This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

TVRage.com Schedule Script (Latest: 2.0)

Support & discussion of released scripts, and announcements of new releases.
Post Reply
t
twr
Voice
Posts: 6
Joined: Sat Jun 17, 2006 9:19 pm

tvrage.tcl

Post by twr »

I found the problem I was having with the script. The channel I had a problem with displaying the script is encrypted, and the bot didn't have the correct key sedt for the channel. Works great now.
N
NoahMPLS
Voice
Posts: 3
Joined: Sun Apr 02, 2006 11:26 pm

New Suggestion

Post by NoahMPLS »

First of all, awesome awesome script. Worked flawlessly from the get go, unlike the Episode World Scripts I had tried. Two suggestions if you could/would be so kind:

(1) Make the public bind of "!" a variable so it can easily be changed to suit various channels. In one of my channels all commands are prefaced with a "-" instead of a "!" For example, -today rather than !today

(2) Allow an option to be set to display the information as a NOTICE rather than in the channel, because (A) When too many people do it the info flood gets annoying and (B) In my test channel I have the default flood protection so the bot announcing the parsed information gets KICKED.

Again let me say, awesome darn script dude!!!!!
s
screwface
Voice
Posts: 2
Joined: Wed Jul 19, 2006 11:43 am

!showinfo any 2 words will not work, only 1 word shows

Post by screwface »

im using your latest script and did all the changes ive seen posted to fix certain bugs.

but now when i try !showinfo certain shows they wont show up.

like that 70s show, the sopranos, arrested development

but shows like battlestar galactica,the ultimate fighter do show up

if i reverse some of the changes, those shows do come up but then 1 word shows like 24 stop showing up. the error is "Tcl error [pub:tvrage.com.showinfo]: can't read "show(latest)": no such
lement in array"

i know this has been addressed in the past posts, but my point is this if use 1 way , some shows stop shwoing up...if i change it back then other shows stop showing up that showed before. so thier must be some sort of balance to get them all showing up :p keep in mind i love your script and it woks flawless for me excpet for this 1 small annoying problem...pls fix :)

and if you could paste an updated version of the script again with all errors fixed, maybe its something stupid im doin from pasting these line fixes.

thx
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

All 3 of the shows you mentioned work on my set up, and while it doesn't appear to be the issue in this instance this is the only change I've made between tvrage.tcl .5 and what I'm using.

Code: Select all

      regsub -all {\x92} $line {'} line
This line belongs around line 141 as the first line of the foreach statement that begins around that line so in the end you should have:

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 }
   }
Let me know if this works.
s
screwface
Voice
Posts: 2
Joined: Wed Jul 19, 2006 11:43 am

thank you

Post by screwface »

not only was your repsonse quick but it was dead on too :)

thank you totaly fixed the problem.

seems to b working 100%.
d
dhp1080
Voice
Posts: 8
Joined: Mon Aug 14, 2006 4:13 pm

Post by dhp1080 »

This thread has been dormant for awhile, but I just tried using the .4 release of this script, and it doesn't run any command, yet it produces no visible errors. I'm running eggdrop v1.6.17.

The complete working version of this script in it's latest form would be helpful.
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

Make sure the channel(s) is set +tv.
f
fanatic
Voice
Posts: 7
Joined: Mon Aug 21, 2006 5:25 pm

help

Post by fanatic »

Hi,

Im brazilian and i dont understand English very well.

I caught and used.
It appeared this here:

[21:42] invalid command name "\rtf1\ansi\ansicpg1252\d
\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pa
#####\par
# tvrage.tcl #\par
# v0.2 23Jan06 #\par
# Coded By: GaveUp #\par
####################\par
\par
###################\par
# DESCRIPTION #\par
######################################################
#\par
# This script pulls today's or tomorrow's schedule of
#\par
######################################################
#\par
\par
####################\par
# Revision History #\par
######################################################
# 0.3 -- *fixed last time
[21:42] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)




I have to configure some thing in tcl?

Or copy and use?

Thnks :D
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

@fanatic: It appears you copy, pasted, and saved the script as an RTF file and it's the RTF formatting crap that is causing the error. Instead copy, paste, and save as a normal txt file and things should work.

In other news ... a progress update. In the past few days I've started updating this script again. Right now, I am finishing up modifying the code to support templating, so the output will be customizable. Additionally, inspired by another tv script, I am looking at the posibility of adding a !synopsis trigger that will pull up the synopsis for a given episode, or possible an abbreviated synopsis with a link to the full thing. I hope to have a new version done in a few days that will have at least template support.
C
Cletus
Voice
Posts: 19
Joined: Sun Aug 06, 2006 6:01 pm

Post by Cletus »

I already enjoy the script as is, but that would just be awesome. Good stuff GaveUp!
f
fanatic
Voice
Posts: 7
Joined: Mon Aug 21, 2006 5:25 pm

ncgi

Post by fanatic »

i have problem in package ncgi...

where i find this package? :D

thnks ;D
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

Here is the latest version of the script. See below for a list of changes. Test this version out and report any problems you have.

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"
f
fanatic
Voice
Posts: 7
Joined: Mon Aug 21, 2006 5:25 pm

suport

Post by fanatic »

Hi,

I`m Brazilian and dont have suport for other country?

The tcl no she shows according to the timetables from here.

!showinfo shows of tomorrow

thnks for v0.6 :D
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

All listings are showen in Eastern (and Pacific) time and it is only capable of showing US schedules. The sources the information is pulled from do not keep the same information for other countries and frankly, having no use for it myself, don't really care to look at other places that might and add support as it'd almost assuredly require a complete rewrite of the parsing code.

Just to answer a question some might have about the timezone issue. I have not added a variable to adjust the timezone because it causes problems around midnight. There will be some time (the adjustment made) where the script may not return the correct results if the adjustment made is negative. To really solve this I'd need to cache, in essence, a copy of the previous days schedule and while a !yesterday trigger might be somewhat useful, I really don't have the ambition to implement caching like that.
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

Here it is ... v0.7. This script fixes a few bugs in the last version, and ads a couple new features. My ideas for features to add to this script have pretty much run out so if anyone has any suggestions for new features I'm open to them and, as always, bug reports are always welcome.

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"
Post Reply