Code: Select all
regsub -all {\x92} $line {'} line
Code: Select all
foreach line [split $data \n] {
regsub -all {\x92} $line {'} line
if {[regexp {^No Show Results Were Found For \".*\"$} $line]} {
putserv "PRIVMSG $chan :\00303$line\00315"
return
}
if {[regexp {^Show Name@(.*)$} $line -> match]} { set show(title) $match }
if {[regexp {^Show URL@(.*)$} $line -> match]} { set show(url) $match }
if {[regexp {^Premiered@(.*)$} $line -> match]} { set show(premiered) $match }
if {[regexp {^Latest Episode@(\d+)x(\d+)\^(.*)\^([\w\/]+)$} $line -> season episode eptitle epDate]} {
set show(latest) [join [list "\00303Latest Episode ::\00315 \00304$season" "x$episode - $eptitle ($epDate)\00315"] ""]
}
if {[regexp {^Next Episode@(\d+)x(\d+)\^(.*)\^([\w\/]+)$} $line -> season episode eptitle epDate]} {
set show(next) [join [list "\00303Next Episode ::\00315 \00304$season" "x$episode - $eptitle ($epDate)\00315"] ""]
}
if {[regexp {^Country@(.*)$} $line -> match]} { set show(country) $match }
if {[regexp {^Status@(.*)$} $line -> match]} { set show(status) $match }
if {[regexp {^Classification@(.*)$} $line -> match]} { set show(class) $match }
}
Code: Select all
####################
# tvrage.tcl #
# v0.6 29Aug06 #
# Coded By: GaveUp #
####################
###################
# DESCRIPTION #
#################################################################################
# This script pulls today's or tomorrow's schedule of new shows from tvrage.com #
# Triggers: #
# !today -- Display today's schedule #
# !tomorrow -- Display tomorrow's schedule #
# !showinfo <show name> -- Display detailed information for <show name> #
# !schedule <day> -- Display schedule for <day> #
# <day> can be one of: mon, tue, wed, thu, fri, sat, sun #
#################################################################################
#############################
# Installation Instructions #
###############################################################################
# Load this script in your eggdrop conf and do a ".chanset <channel> +tv" for #
# every channel you want the script to respond in. #
###############################################################################
####################
# Revision History #
#####################################################################
# 0.6 -- *Patch to deal with non-displayable characters that caused #
# crashes #
# +Added Templating Support to allow for customizing of #
# output #
# +Moved hardcoded variables to global settings. This will #
# make it easier to deal with changes that might occur to #
# the website info is pulled from #
# 0.5 -- *Yet more regex tweaks #
# 0.4 -- *more tweaks to regex #
# *removed ncgi requirement #
# 0.3 -- *fixed last time of 7th day now displayed #
# *tweaked regex to catch some programs it was missing #
# 0.2 -- +!showinfo trigger for detailed show info and next/last ep #
# +!schedule for 7 day schedule #
# *fixed errors in various regex #
# 0.1 -- Initial Release #
# #
# + added - removed * fixed/changed #
#####################################################################
########
# TODO #
########################################################
# *Fix 'too long for line' problem #
# *Add ability to split info display to multiple lines #
########################################################
####################
### Begin Config ###
####################
### Bind Settings ###
# Trigger to show today's schedule
set tvrage(todayTrigger) "!today"
# Trigger to show tomorrow's schedule
set tvrage(tomorrowTrigger) "!tomorrow"
# Trigger to show information about a show
set tvrage(showinfoTrigger) "!showinfo"
# Trigger to get schedule for specified day
set tvrage(scheduleTrigger) "!schedule"
### Formatting Settings ###
# Separator between season number and episode number
set tvrage(seasonEpisodeSeparator) "x"
# The following formatting settings support place holders. These placeholders
# represent pieces of the data to be displayed. The following place holders
# are supported:
# {%%chan%%} -- Channel that trigger request came from
# {%%nick%%} -- Nick that made trigger request
# {%%title%%} -- Show name
# {%%url%%} -- URL to detailed show info (only available in showinfo)
# {%%premiered%%} -- Year show premiered (only available in showinfo)
# {%%latest%%} -- Wrapper for latestEpFormat/latestEpNoExistFormat settings (only available in showinfo)
# {%%next%%} -- Wrapper for nextEpFormat/nextEpNoExistFormat settings (only available in showinfo)
# {%%country%%} -- Country show originated in (only available in showinfo)
# {%%status%%} -- Status of show (cancelled, returning series, etc) (only available in showinfo)
# {%%nextSeason%%} -- Season number of next episode to air (only available in showinfo)
# {%%nextEpisode%%} -- Episode number of next episode to air (only available in showinfo)
# {%%nextTitle%%} -- Title of next episode to air (only available in showinfo)
# {%%nextDate%%} -- Date of next episode to air (only available in showinfo)
# {%%latestSeason%%} -- Season number of last episode to air (only available in showinfo)
# {%%latestEpisode%%} -- Episode number of last episode to air (only available in showinfo)
# {%%latestTitle%%} -- Title of last episode to air (only available in showinfo)
# {%%latestDate%%} -- Date of last episode to air (only available in showinfo)
# {%%date%%} -- Date of schedule being displayed (only available in schedule)
# {%%time%%} -- Time of airing (when displaying a schedule) (only available in schedule)
# {%%network%%} -- Network show airs on (only available in schedule)
# {%%epnum%%} -- "Season"x"Episode" of show airing (only available in schedule)
# {%%scheduleLine%%} -- Line in schedule listing (only available in schedule)
# {%%scheduleShowSeparator%%} -- Separator between shows in a schedule listing (only available in schedule)
# Formatting of info displayed on !showinfo
set tvrage(showInfoLine) "PRIVMSG {%%chan%%} :\00303Title ::\00315 \00304{%%title%%}\00315 \00308<>\00315 \00303URL ::\00315 \00304{%%url%%}\00315 \00308<>\00315 \00303Premiered ::\00315 \00304{%%premiered%%}\00315 \00308<>\00315 {%%latest%%} \00308<>\00315 {%%next%%} \00308<>\00315 \00303Country ::\00315 \00304{%%country%%}\00315 \00308<>\00315 \00303Status ::\00315 \00304{%%status%%}\00315"
# Formatting of next episode to air info displayed on !showinfo
set tvrage(nextEpFormat) "\00303Next Episode ::\00315 \00304{%%nextSeason%%}{%%seasonEpisodeSeparator%%}{%%nextEpisode%%} - {%%nextTitle%%} ({%%nextDate%%})\00315"
# Formatting when there is no episode that has not aired (ie: after a series ends or before new season episodes are announced)
set tvrage(nextEpNoExistFormat) "\00303Next Episode ::\00315 \00304N/A\00315"
# Formatting of last episode to air info displayed on !showinfo
set tvrage(latestEpFormat) "\00303Latest Episode ::\00315 \00304{%%latestSeason%%}{%%seasonEpisodeSeparator%%}{%%latestEpisode%%} - {%%latestTitle%%} ({%%latestDate%%})\00315"
# Formatting when no previous episode has aired (ie: before a show premieres)
set tvrage(latestEpNoExistFormat) "\00303Latest Episode ::\00315 \00304N/A\00315"
# Header to display before showing a schedule.
set tvrage(scheduleHeader) "PRIVMSG {%%chan%%} :\00303New TV Shows for {%%date%%} ***All Times in EST/EDT***\00315"
# Format of the time display for each line in a schedule listing
set tvrage(scheduleTimeFormat) "\002{%%time%%}:\002 "
# Format of a show in a schedule listing
set tvrage(scheduleEpisodeFormat) "\00304{%%network%%}\00315 - \00314{%%title%%} {%%epnum%%}\00315 {%%scheduleShowSeparator%%} "
# Separator between episodes in a schedule listing
set tvrage(scheduleShowSeparator) "<>"
# Format of a schedule Line (should be used primarily to change from a public message, to private message, etc)
set tvrage(scheduleLine) "PRIVMSG {%%chan%%} :{%%scheduleLine%%}"
# Format of info to show when !showinfo does not find the requested show
set tvrage(noShowLine) "PRIVMSG {%%chan%%} :\00303No Show Results Were Found For \"{%%title%%}\"\00315"
### Misc. Settings ###
# Use NCGI package?
# Set to 1 to use NCGI or 0 to use inbuilt function (0 recommended)
set tvrage(useNCGI) 0
# URL to grab schedule from
# Do NOT change this unless you know what you're doing
set tvrage(scheduleurl) "http://www.tvrage.com/quickschedule.php"
# URL to grab show info from
# Do NOT change this unless you know what you're doing
set tvrage(showinfourl) "http://www.tvrage.com/quickinfo.php"
##################
### End Config ###
##################
###################################
### DO NOT EDIT BELOW THIS LINE ###
###################################
bind pub - $tvrage(todayTrigger) pub:tvrage.com.today
bind pub - $tvrage(tomorrowTrigger) pub:tvrage.com.tomorrow
bind pub - $tvrage(showinfoTrigger) pub:tvrage.com.showinfo
bind pub - $tvrage(scheduleTrigger) pub:tvrage.com.schedule
package require http
if {$tvrage(useNCGI)} {
package require ncgi
}
setudef flag tv
proc pub:tvrage.com.templateParser {template info} {
set filled $template
foreach {key value} $info {
regsub -all "\{%%$key%%\}" $filled $value filled
}
return $filled
}
proc pub:tvrage.com.schedule {nick uhost hand chan text} {
set seconds [clock seconds]
set days(sun) 0
set days(mon) 1
set days(tue) 2
set days(wed) 3
set days(thu) 4
set days(fri) 5
set days(sat) 6
if ![info exist days([string tolower $text])] return
set currDay [clock format $seconds -format "%w"]
if {$currDay > $days([string tolower $text])} {
parse:tvrage.com $nick $uhost $hand $chan $text [expr (7 - $currDay) + $days([string tolower $text])]
} else {
parse:tvrage.com $nick $uhost $hand $chan $text [expr $days([string tolower $text]) - $currDay]
}
}
proc pub:tvrage.com.today {nick uhost hand chan text} {
parse:tvrage.com $nick $uhost $hand $chan $text "0"
}
proc pub:tvrage.com.tomorrow {nick uhost hand chan text} {
parse:tvrage.com $nick $uhost $hand $chan $text "1"
}
proc parse:tvrage.com.encodeURL {str} {
set str [string map {" " +} $str]
foreach c [split $str {}] {
if {$c == "+" || [string is alnum $c]} {append x $c} {
binary scan $c H2 c; append x %$c
}
}
return $x
}
proc pub:tvrage.com.showinfo {nick uhost hand chan text} {
global tvrage
if ![channel get $chan tv] return
set show(chan) $chan
set show(nick) $nick
if {$tvrage(useNCGI)} {
set token [http::geturl [join [list $tvrage(showinfourl) "?show=" [ncgi::encode [string trimleft $text]]] ""]]
} else {
set token [http::geturl [join [list $tvrage(showinfourl) "?show=" [parse:tvrage.com.encodeURL [string trimleft $text]]] ""]]
}
set data [http::data $token]
http::cleanup $token
set show(title) ""
foreach line [split $data \n] {
regsub -all {\x92} $line {'} line
if {[regexp {^No Show Results Were Found For (.*)$} $line -> show(title)]} {
putserv [pub:tvrage.com.templateParser $tvrage(noShowLine) [array get show]]
return
}
if {[regexp {^Show Name@(.*)$} $line -> match]} { set show(title) $match }
if {[regexp {^Show URL@(.*)$} $line -> match]} { set show(url) $match }
if {[regexp {^Premiered@(.*)$} $line -> match]} { set show(premiered) $match }
if {[regexp {^Latest Episode@(\d+)x(\d+)\^(.*)\^([\w\/]+)$} $line -> season episode eptitle epDate]} {
set show(latest) 1
set show(latestTitle) $eptitle
set show(latestSeason) $season
set show(latestEpisode) $episode
set show(latestDate) $epDate
set show(latestSeparator) $tvrage(seasonEpisodeSeparator)
}
if {[regexp {^Next Episode@(\d+)x(\d+)\^(.*)\^([\w\/]+)$} $line -> season episode eptitle epDate]} {
set show(next) 1
set show(nextTitle) $eptitle
set show(nextSeason) $season
set show(nextEpisode) $episode
set show(nextDate) $epDate
set show(nextSeparator) $tvrage(seasonEpisodeSeparator)
}
if {[regexp {^Country@(.*)$} $line -> match]} { set show(country) $match }
if {[regexp {^Status@(.*)$} $line -> match]} { set show(status) $match }
if {[regexp {^Classification@(.*)$} $line -> match]} { set show(class) $match }
}
if ![info exist show(latest)] {
set show(latest) 0
set show(latestTitle) ""
set show(latestSeason) ""
set show(latestEpisode) "N/A"
set show(latestDate) ""
set show(latestSeparator) ""
}
if ![info exist show(next)] {
set show(next) 0
set show(nextTitle) ""
set show(nextSeason) ""
set show(nextEpisode) "N/A"
set show(nextDate) ""
set show(nextSeparator) ""
}
set show(seasonEpisodeSeparator) $tvrage(seasonEpisodeSeparator)
if {$show(next)} {
set show(next) [pub:tvrage.com.templateParser $tvrage(nextEpFormat) [array get show]]
} else {
set show(next) [pub:tvrage.com.templateParser $tvrage(nextEpNoExistFormat) [array get show]]
}
if {$show(latest)} {
set show(latest) [pub:tvrage.com.templateParser $tvrage(latestEpFormat) [array get show]]
} else {
set show(latest) [pub:tvrage.com.templateParser $tvrage(LatestEpNoExistFormat) [array get show]]
}
putserv [pub:tvrage.com.templateParser $tvrage(showInfoLine) [array get show]]
}
proc parse:tvrage.com {nick uhost hand chan text when} {
global tvrage
if ![channel get $chan tv] return
set token [http::geturl $tvrage(scheduleurl)]
set data [http::data $token]
http::cleanup $token
set date ""
set systemTime [clock seconds]
#set systemTime [expr $systemTime + 3600]
set currentTime ""
set parsing 0
set currentOutput ""
set gotTime 0
set neededDate ""
set neof 1
set systemTime [expr "$systemTime + ($when * 86400)"]
set neededDate [clock format $systemTime -format "%A, %d %b %Y"]
set show(chan) $chan
set show(nick) $nick
set show(scheduleShowSeparator) $tvrage(scheduleShowSeparator)
foreach line [split $data \n] {
if {[regexp {^\[DAY\]([\w\, ]+)\[\/DAY\]$} $line -> date]} {
if {$parsing == 1} {
break;
}
if {$date == $neededDate} {
set show(date) $date
putserv [pub:tvrage.com.templateParser $tvrage(scheduleHeader) [array get show]]
set parsing 1
}
}
if {$parsing} {
if {[regexp {^\[TIME\]([\w\: ]+)\[\/TIME\]$} $line -> show(time)]} {
if {$gotTime} {
set show(scheduleLine) [string trim $currentOutput $tvrage(scheduleShowSeparator)]
putserv [pub:tvrage.com.templateParser $tvrage(scheduleLine) [array get show]]
#putserv "PRIVMSG $chan :$currentOutput"
set currentOutput ""
}
set currentOutput [pub:tvrage.com.templateParser $tvrage(scheduleTimeFormat) [array get show]]
set gotTime 1
}
regsub -all {\x92} $line {'} line
if {[regexp {^\[SHOW\]([ \w\&\!]+)\^([\,\.\-\(\)\#\w \'\`\:&\!\/]+)\^([\dx]+)\^([\w\\\/\:\.\-]+)\[\/SHOW\]$} $line -> show(network) show(title) show(epnum) show(url)]} {
set currentOutput [concat $currentOutput [pub:tvrage.com.templateParser $tvrage(scheduleEpisodeFormat) [array get show]]]
}
}
}
if {$currentOutput != ""} {
set show(scheduleLine) [string trim $currentOutput $tvrage(scheduleShowSeparator)]
putserv [pub:tvrage.com.templateParser $tvrage(scheduleLine) [array get show]]
}
}
putlog "TVRage.com Primetime Schedule v0.6"
Code: Select all
####################
# tvrage.tcl #
# v0.7 30Aug06 #
# Coded By: GaveUp #
####################
###################
# DESCRIPTION #
#################################################################################
# This script pulls today's or tomorrow's schedule of new shows from tvrage.com #
# Triggers: #
# !today -- Display today's schedule #
# !tomorrow -- Display tomorrow's schedule #
# !showinfo <show name> -- Display detailed information for <show name> #
# !schedule <day> -- Display schedule for <day> #
# <day> can be one of: mon, tue, wed, thu, fri, sat, sun #
# !summary <show> <episode> -- Display a summary for <episode> of <show> #
#################################################################################
#############################
# Installation Instructions #
###############################################################################
# Load this script in your eggdrop conf and do a ".chanset <channel> +tv" for #
# every channel you want the script to respond in. #
###############################################################################
####################
# Revision History #
#####################################################################
# 0.7 -- +Added wordwrap class to support wrapping of long lines. #
# Thanks to user for posting code in the thread #
# http://forum.egghelp.org/viewtopic.php?t=6690 which #
# provided a base for the wordwrap function in this script. #
# +Added !summary trigger to pull a summary for a given #
# episode. Usage: !summary <show title> <episode number> #
# <episode number> must be in the format of WWxYY where WW #
# is the season number and WW is the episode number. #
# *'Long Line' problem fixed with wordwrap code #
# *Fixed minor aesthetic and formatting issues #
# 0.6 -- *Patch to deal with non-displayable characters that caused #
# crashes #
# +Added Templating Support to allow for customizing of #
# output #
# +Moved hardcoded variables to global settings. This will #
# make it easier to deal with changes that might occur to #
# the website info is pulled from #
# 0.5 -- *Yet more regex tweaks #
# 0.4 -- *more tweaks to regex #
# *removed ncgi requirement #
# 0.3 -- *fixed last time of 7th day now displayed #
# *tweaked regex to catch some programs it was missing #
# 0.2 -- +!showinfo trigger for detailed show info and next/last ep #
# +!schedule for 7 day schedule #
# *fixed errors in various regex #
# 0.1 -- Initial Release #
# #
# + added - removed * fixed/changed #
#####################################################################
########
# TODO #
########################################################
# Nothing? #
########################################################
####################
### Begin Config ###
####################
### Bind Settings ###
# Trigger to show today's schedule
set tvrage(todayTrigger) "!today"
# Trigger to show tomorrow's schedule
set tvrage(tomorrowTrigger) "!tomorrow"
# Trigger to show information about a show
set tvrage(showinfoTrigger) "!showinfo"
# Trigger to get schedule for specified day
set tvrage(scheduleTrigger) "!schedule"
# Trigger to get summary of an episode of a show
set tvrage(summaryTrigger) "!summary"
### Formatting Settings ###
# Separator between season number and episode number
set tvrage(seasonEpisodeSeparator) "x"
# The following formatting settings support place holders. These placeholders
# represent pieces of the data to be displayed. The following place holders
# are supported:
# {%%chan%%} -- Channel that trigger request came from
# {%%nick%%} -- Nick that made trigger request
# {%%title%%} -- Show name
# {%%url%%} -- URL to detailed show info (only available in showinfo)
# {%%premiered%%} -- Year show premiered (only available in showinfo)
# {%%latest%%} -- Wrapper for latestEpFormat/latestEpNoExistFormat settings (only available in showinfo)
# {%%next%%} -- Wrapper for nextEpFormat/nextEpNoExistFormat settings (only available in showinfo)
# {%%country%%} -- Country show originated in (only available in showinfo)
# {%%status%%} -- Status of show (cancelled, returning series, etc) (only available in showinfo)
# {%%nextSeason%%} -- Season number of next episode to air (only available in showinfo)
# {%%nextEpisode%%} -- Episode number of next episode to air (only available in showinfo)
# {%%nextTitle%%} -- Title of next episode to air (only available in showinfo)
# {%%nextDate%%} -- Date of next episode to air (only available in showinfo)
# {%%latestSeason%%} -- Season number of last episode to air (only available in showinfo)
# {%%latestEpisode%%} -- Episode number of last episode to air (only available in showinfo)
# {%%latestTitle%%} -- Title of last episode to air (only available in showinfo)
# {%%latestDate%%} -- Date of last episode to air (only available in showinfo)
# {%%date%%} -- Date of schedule being displayed (only available in schedule)
# {%%time%%} -- Time of airing (when displaying a schedule) (only available in schedule)
# {%%network%%} -- Network show airs on (only available in schedule)
# {%%epnum%%} -- "Season"x"Episode" of show airing (only available in schedule)
# {%%scheduleLine%%} -- Line in schedule listing (only available in schedule)
# {%%scheduleShowSeparator%%} -- Separator between shows in a schedule listing (only available in schedule)
# {%%epSeason%%} -- Season of Episode (only available in summary)
# {%%epNumber%%} -- Episode Number of show (only available in summary)
# {%%epTitle%%} -- Title of episode (only available in summary)
# {%%epDate%%} -- Date of first airing of episode (only available in summary)
# {%%summary%%} -- Summary of episode (only available in summary)
# Formatting of info displayed on !showinfo
set tvrage(showInfoLine) "PRIVMSG {%%chan%%} :\00303Title ::\00315 \00304{%%title%%}\00315 \00308<>\00315 \00303URL ::\00315 \00304{%%url%%}\00315 \00308<>\00315 \00303Premiered ::\00315 \00304{%%premiered%%}\00315 \00308<>\00315 {%%latest%%} \00308<>\00315 {%%next%%} \00308<>\00315 \00303Country ::\00315 \00304{%%country%%}\00315 \00308<>\00315 \00303Status ::\00315 \00304{%%status%%}\00315"
# Formatting of next episode to air info displayed on !showinfo
set tvrage(nextEpFormat) "\00303Next Episode ::\00315 \00304{%%nextSeason%%}{%%seasonEpisodeSeparator%%}{%%nextEpisode%%} - {%%nextTitle%%} ({%%nextDate%%})\00315"
# Formatting when there is no episode that has not aired (ie: after a series ends or before new season episodes are announced)
set tvrage(nextEpNoExistFormat) "\00303Next Episode ::\00315 \00304N/A\00315"
# Formatting of last episode to air info displayed on !showinfo
set tvrage(latestEpFormat) "\00303Latest Episode ::\00315 \00304{%%latestSeason%%}{%%seasonEpisodeSeparator%%}{%%latestEpisode%%} - {%%latestTitle%%} ({%%latestDate%%})\00315"
# Formatting when no previous episode has aired (ie: before a show premieres)
set tvrage(latestEpNoExistFormat) "\00303Latest Episode ::\00315 \00304N/A\00315"
# Header to display before showing a schedule.
set tvrage(scheduleHeader) "PRIVMSG {%%chan%%} :\00303New TV Shows for {%%date%%} ***All Times in EST/EDT***\00315"
# Format of the time display for each line in a schedule listing
set tvrage(scheduleTimeFormat) "\002{%%time%%}:\002 "
# Format of a show in a schedule listing
set tvrage(scheduleEpisodeFormat) "\00304{%%network%%}\00315 - \00314{%%title%%} {%%epnum%%}\00315 {%%scheduleShowSeparator%%} "
# Separator between episodes in a schedule listing
set tvrage(scheduleShowSeparator) "<>"
# Format of a schedule Line (should be used primarily to change from a public message, to private message, etc)
set tvrage(scheduleLine) "PRIVMSG {%%chan%%} :{%%scheduleLine%%}"
# Format of info to show when !showinfo does not find the requested show
set tvrage(noShowLine) "PRIVMSG {%%chan%%} :\00303No Show Results Were Found For \"{%%title%%}\"\00315"
# Format of info to show when !summary finds a summary
set tvrage(summaryLine) "PRIVMSG {%%chan%%} :\00303Show ::\00315 \00304{%%title%%}\00315 \00308<>\00315 \00303Episode ::\00315 \00304{%%epSeason%%}{%%seasonEpisodeSeparator%%}{%%epNumber%%} - {%%epTitle%%} ({%%epDate%%})\00315 \00308<>\00315 \00303Summary:\00315 \00304{%%summary%%}\00315 \00308<>\00315 \00303Episode URL ::\00315 \00304{%%url%%}\00315"
### Misc. Settings ###
# Enable(1)/Disable(0) !summary trigger.
set tvrage(enableSummary) 1
# Split Lines at nChars length
set tvrage(nChars) 450
# Use NCGI package?
# Set to 1 to use NCGI or 0 to use inbuilt function (0 recommended)
set tvrage(useNCGI) 0
# URL to grab schedule from
# Do NOT change this unless you know what you're doing
set tvrage(scheduleurl) "http://www.tvrage.com/quickschedule.php"
# URL to grab show info from
# Do NOT change this unless you know what you're doing
set tvrage(showinfourl) "http://www.tvrage.com/quickinfo.php"
##################
### End Config ###
##################
###################################
### DO NOT EDIT BELOW THIS LINE ###
###################################
bind pub - $tvrage(todayTrigger) pub:tvrage.com.today
bind pub - $tvrage(tomorrowTrigger) pub:tvrage.com.tomorrow
bind pub - $tvrage(showinfoTrigger) pub:tvrage.com.showinfo
bind pub - $tvrage(scheduleTrigger) pub:tvrage.com.schedule
if {$tvrage(enableSummary)} {
bind pub - $tvrage(summaryTrigger) pub:tvrage.com.getSummary
}
package require http
if {$tvrage(useNCGI)} {
package require ncgi
}
setudef flag tv
proc wordwrap {str {len 200} {prefix {}} {splitChr { }}} {
set out {}
set cur $prefix
set i 0
foreach word [split [set str][unset str] $splitChr] {
if {[incr i [string len $word]]>$len} {
lappend out [join $cur $splitChr]
if {[regexp {^.*(\003\d\d)} $cur -> lastColor]} {
set cur [join [list $prefix $lastColor $word] ""]
} else {
set cur [join [list $prefix $word] ""]
}
set i [string len $word]
} {
lappend cur $word
}
incr i
}
lappend out [join $cur $splitChr]
}
proc pub:tvrage.com.displayInfo {text {prefix {}} {tosplit {}}} {
global tvrage
if {([string len $prefix] == 0) && ([string len $tosplit] == 0)} {
regexp {^(.*?:)(.*)$} $text -> prefix tosplit
} elseif {[string len $prefix] == 0} {
regexp {^(.*?:)(.*)$} $text -> prefix ->
} elseif {[string len $tosplit] == 0} {
regexp {^(.*?:)(.*)$} $text -> -> tosplit
}
foreach line [wordwrap $tosplit $tvrage(nChars) $prefix] {
putserv $line
}
}
proc pub:tvrage.com.getSummary {nick uhost hand chan text} {
global tvrage
if ![channel get $chan tv] return
set show(chan) $chan
set show(nick) $nick
if {![regexp {(.*) (\d+x\d+)} $text -> showname ep]} {
putlog "Invalid Request."
return
}
if {$tvrage(useNCGI)} {
set token [http::geturl [join [list $tvrage(showinfourl) "?show=" [ncgi::encode [string trimleft $showname]] "&ep=" [ncgi::encode [string trimleft $ep]]] ""]]
} else {
set token [http::geturl [join [list $tvrage(showinfourl) "?show=" [parse:tvrage.com.encodeURL [string trimleft $showname]] "&ep=" [parse:tvrage.com.encodeURL [string trimleft $ep]]] ""]]
}
set data [http::data $token]
http::cleanup $token
foreach line [split $data \n] {
if {[regexp {^Episode URL@(.*)$} $line -> match]} {
set show(url) $match
}
if {[regexp {^Show Name@(.*)$} $line -> match]} { set show(title) $match }
if {[regexp {^Episode Info@(\d+)x(\d+)\^(.*)\^([\w\/]+)$} $line -> season episode eptitle epDate]} {
set show(latest) 1
set show(epTitle) $eptitle
set show(epSeason) $season
set show(epNumber) $episode
set show(epDate) $epDate
set show(seasonEpisodeSeparator) $tvrage(seasonEpisodeSeparator)
}
}
set token [http::geturl $show(url)]
set data [http::data $token]
http::cleanup $token
foreach line [split $data \n] {
if {[regexp "<table width=\'98%\' align='center'><tr><td>(.*)</td></tr></table>" $line -> match]} { set show(summary) $match }
}
pub:tvrage.com.displayInfo [pub:tvrage.com.templateParser $tvrage(summaryLine) [array get show]]
}
proc pub:tvrage.com.templateParser {template info} {
set filled $template
foreach {key value} $info {
regsub -all {\&} $value {\\&} value
regsub -all "\{\%\%$key\%\%\}" $filled $value filled
}
return $filled
}
proc pub:tvrage.com.schedule {nick uhost hand chan text} {
set seconds [clock seconds]
set days(sun) 0
set days(mon) 1
set days(tue) 2
set days(wed) 3
set days(thu) 4
set days(fri) 5
set days(sat) 6
if ![info exist days([string tolower $text])] return
set currDay [clock format $seconds -format "%w"]
if {$currDay > $days([string tolower $text])} {
parse:tvrage.com $nick $uhost $hand $chan $text [expr (7 - $currDay) + $days([string tolower $text])]
} else {
parse:tvrage.com $nick $uhost $hand $chan $text [expr $days([string tolower $text]) - $currDay]
}
}
proc pub:tvrage.com.today {nick uhost hand chan text} {
parse:tvrage.com $nick $uhost $hand $chan $text "0"
}
proc pub:tvrage.com.tomorrow {nick uhost hand chan text} {
parse:tvrage.com $nick $uhost $hand $chan $text "1"
}
proc parse:tvrage.com.encodeURL {str} {
set str [string map {" " +} $str]
foreach c [split $str {}] {
if {$c == "+" || [string is alnum $c]} {append x $c} {
binary scan $c H2 c; append x %$c
}
}
return $x
}
proc pub:tvrage.com.showinfo {nick uhost hand chan text} {
global tvrage
if ![channel get $chan tv] return
set show(chan) $chan
set show(nick) $nick
if {$tvrage(useNCGI)} {
set token [http::geturl [join [list $tvrage(showinfourl) "?show=" [ncgi::encode [string trimleft $text]]] ""]]
} else {
set token [http::geturl [join [list $tvrage(showinfourl) "?show=" [parse:tvrage.com.encodeURL [string trimleft $text]]] ""]]
}
set data [http::data $token]
http::cleanup $token
set show(title) ""
foreach line [split $data \n] {
regsub -all {\x92} $line {'} line
if {[regexp {^No Show Results Were Found For \"(.*)\"$} $line -> show(title)]} {
pub:tvrage.com.displayInfo [pub:tvrage.com.templateParser $tvrage(noShowLine) [array get show]]
return
}
if {[regexp {^Show Name@(.*)$} $line -> match]} { set show(title) $match }
if {[regexp {^Show URL@(.*)$} $line -> match]} { set show(url) $match }
if {[regexp {^Premiered@(.*)$} $line -> match]} { set show(premiered) $match }
if {[regexp {^Latest Episode@(\d+)x(\d+)\^(.*)\^([\w\/]+)$} $line -> season episode eptitle epDate]} {
set show(latest) 1
set show(latestTitle) $eptitle
set show(latestSeason) $season
set show(latestEpisode) $episode
set show(latestDate) $epDate
set show(latestSeparator) $tvrage(seasonEpisodeSeparator)
}
if {[regexp {^Next Episode@(\d+)x(\d+)\^(.*)\^([\w\/]+)$} $line -> season episode eptitle epDate]} {
set show(next) 1
set show(nextTitle) $eptitle
set show(nextSeason) $season
set show(nextEpisode) $episode
set show(nextDate) $epDate
set show(nextSeparator) $tvrage(seasonEpisodeSeparator)
}
if {[regexp {^Country@(.*)$} $line -> match]} { set show(country) $match }
if {[regexp {^Status@(.*)$} $line -> match]} { set show(status) $match }
if {[regexp {^Classification@(.*)$} $line -> match]} { set show(class) $match }
}
if ![info exist show(latest)] {
set show(latest) 0
set show(latestTitle) ""
set show(latestSeason) ""
set show(latestEpisode) "N/A"
set show(latestDate) ""
set show(latestSeparator) ""
}
if ![info exist show(next)] {
set show(next) 0
set show(nextTitle) ""
set show(nextSeason) ""
set show(nextEpisode) "N/A"
set show(nextDate) ""
set show(nextSeparator) ""
}
set show(seasonEpisodeSeparator) $tvrage(seasonEpisodeSeparator)
if {$show(next)} {
set show(next) [pub:tvrage.com.templateParser $tvrage(nextEpFormat) [array get show]]
} else {
set show(next) [pub:tvrage.com.templateParser $tvrage(nextEpNoExistFormat) [array get show]]
}
if {$show(latest)} {
set show(latest) [pub:tvrage.com.templateParser $tvrage(latestEpFormat) [array get show]]
} else {
set show(latest) [pub:tvrage.com.templateParser $tvrage(LatestEpNoExistFormat) [array get show]]
}
pub:tvrage.com.displayInfo [pub:tvrage.com.templateParser $tvrage(showInfoLine) [array get show]]
}
proc parse:tvrage.com {nick uhost hand chan text when} {
global tvrage
if ![channel get $chan tv] return
set token [http::geturl $tvrage(scheduleurl)]
set data [http::data $token]
http::cleanup $token
set date ""
set systemTime [clock seconds]
#set systemTime [expr $systemTime + 3600]
set currentTime ""
set parsing 0
set currentOutput ""
set gotTime 0
set neededDate ""
set neof 1
set systemTime [expr "$systemTime + ($when * 86400)"]
set neededDate [clock format $systemTime -format "%A, %d %b %Y"]
set show(chan) $chan
set show(nick) $nick
set show(scheduleShowSeparator) $tvrage(scheduleShowSeparator)
foreach line [split $data \n] {
if {[regexp {^\[DAY\]([\w\, ]+)\[\/DAY\]$} $line -> date]} {
if {$parsing == 1} {
break;
}
if {$date == $neededDate} {
set show(date) $date
pub:tvrage.com.displayInfo [pub:tvrage.com.templateParser $tvrage(scheduleHeader) [array get show]]
set parsing 1
}
}
if {$parsing} {
if {[regexp {^\[TIME\]([\w\: ]+)\[\/TIME\]$} $line -> show(time)]} {
if {$gotTime} {
set show(scheduleLine) [string trim $currentOutput $tvrage(scheduleShowSeparator)]
set outputLine [pub:tvrage.com.templateParser $tvrage(scheduleLine) [array get show]]
regexp {^(.*?:.*\d\d:\d\d [ap]m:.*? )(.*)$} $outputLine -> prefix tosplit
pub:tvrage.com.displayInfo $outputLine $prefix $tosplit
unset prefix
unset tosplit
set currentOutput ""
}
set currentOutput [pub:tvrage.com.templateParser $tvrage(scheduleTimeFormat) [array get show]]
set gotTime 1
}
regsub -all {\x92} $line {'} line
if {[regexp {^\[SHOW\]([ \w\&\!]+)\^([\,\.\-\(\)\#\w \'\`\:&\!\/]+)\^([\dx]+)\^([\w\\\/\:\.\-]+)\[\/SHOW\]$} $line -> show(network) show(title) show(epnum) show(url)]} {
set currentOutput [concat $currentOutput [pub:tvrage.com.templateParser $tvrage(scheduleEpisodeFormat) [array get show]]]
}
}
}
if {$currentOutput != ""} {
set show(scheduleLine) [string trim $currentOutput $tvrage(scheduleShowSeparator)]
set outputLine [pub:tvrage.com.templateParser $tvrage(scheduleLine) [array get show]]
regexp {^(.*?:.*\d\d:\d\d [ap]m:.*? )(.*)$} $outputLine -> prefix tosplit
pub:tvrage.com.displayInfo $outputLine $prefix $tosplit
unset prefix
unset tosplit
}
}
putlog "TVRage.com Primetime Schedule v0.7"