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.

dlx's tvrage LOOKUP SCRIPT (v2.3fix)

Support & discussion of released scripts, and announcements of new releases.
Post Reply
Z
Znuff
Voice
Posts: 9
Joined: Mon May 17, 2010 1:00 am

dlx's tvrage LOOKUP SCRIPT (v2.3fix)

Post by Znuff »

Hi,

Code is not mine, but dlx's. Just changed the api url and added a timeout value so the bot doesn't crash anymore if the service is unresponsive.

Wished I could write better error handling, but this will do, I guess :-)

Code: Select all

###########################################################
# tvrage LOOKUP SCRIPT (dlx @ linknet)                    #
###########################################################
# v2.3fix - changed API url                               #
#         - added timeout after 5 seconds (stops crashing #
#           if tvrage.com is slow                         #
#         - modified by znuff on 17/05/2010               #
###########################################################
# v2.3 - changed the way !today and                       #
#        !tomorrow reply for less spam                    #
###########################################################
# v2.2 - added tvrage(inline) support                     #
#        for iPoRn                                        #
###########################################################
# v2.1 - added time output to !tonight                    #
#         and !tomorrow for nogruk                        #
###########################################################
# v2.0 - new commands !next/!last/                        #
#                !tonight/!tomorrow                       #
###########################################################

bind pub - .tv dlx:tvrage:tv
bind pub - .tvnext dlx:tvrage:next
bind pub - .tvlast dlx:tvrage:last
#bind pub - .tvtonight dlx:tvrage:tonight
#bind pub - .tvtomorrow dlx:tvrage:tomorrow

# Channels not to be displayed on !tonight/!tomorrow
set tvrage(excluded_Channels) [list "Nickelodeon" "Disney Channel" "Style" "VH1" "HGTV" "PBS" "Cooking Channel" "Food Network" "TLC" "Discovery Channel" "Spike TV" "E!" "A&E" "Cartoon Network" "Animal Planet"]

# timeout value - in miliseconds
set tvrage(timeout) "5000"

# Show the Time of the show?
set tvrage(show_time) "TRUE"

# Show the Episode number of the show?
set tvrage(show_episode) "TRUE"

# Display !tonight and !tomorrow in one line?
# TRUE will squeeze all shows into one line
# FALSE will split them up by channel (DEFAULT)
set tvrage(inline) "FALSE"

proc dlx:tvrage:tv { nick host hand chan arg } {
    global tvrage
    package require http
    set prefix "\002\0037TV ->\003\002 "
 
    set arg [string map { " " "%20" } $arg]
 
    set url "http://services.tvrage.com/tools/quickinfo.php?show=$arg"
    set page [http::data [http::geturl $url -timeout $tvrage(timeout)]]

    regexp {Show Name@([A-Za-z 0-9\&\':]+)} $page gotname show_name
    regexp {Show URL@http://www.tvrage.com/([A-Za-z_0-9/-]+)} $page goturl show_url
    regexp {Premiered@([0-9]+)} $page gotpremiere show_premiered
    regexp {Latest Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:\.,]+)\^([A-Za-z0-9/]+)} $page gotlatest latest_ep latest_ep_title latest_ep_date
    set gotnext [regexp {Next Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:.,]+)\^([A-Za-z0-9/]+)} $page gotnext next_ep next_ep_title next_ep_date]
    regexp {Country@([A-Za-z]+)} $page gotcountry show_country
    regexp {Status@([A-Za-z/ ]+)} $page gotstatus show_status
    regexp {Classification@([A-Za-z ]+)} $page gotclassification show_classification
    set gotgenres [regexp {Genres@([A-Za-z |]+)} $page gotgenres show_genres]
    regexp {Network@([A-Za-z 0-9]+)} $page gotnetwork show_network
    regexp {Airtime@([A-Za-z, 0-9:]+)} $page gotairtime show_airtime

    if { ![info exists show_name] } {
       putquick "PRIVMSG $chan :$prefix Error! (timeout or something similar)"
       return -1
    }

    set show_url "http://www.tvrage.com/$show_url"
    if { $gotgenres == 0 } { set show_genres "N/A" }
    if { $gotnext == 0 } {
            set next_ep "00x00"
            set next_ep_title "-N/A-"
            set next_ep_date "not available"
    }
   putquick "PRIVMSG $chan :$prefix Show: $show_name ($show_classification \| $show_genres)"
   putquick "PRIVMSG $chan :$prefix Premiered: $show_premiered"
   putquick "PRIVMSG $chan :$prefix Status: $show_status"
   putquick "PRIVMSG $chan :$prefix Network: $show_network"
   putquick "PRIVMSG $chan :$prefix URL: $show_url"
}

proc dlx:tvrage:next { nick host hand chan arg } {
    global tvrage
    package require http
    set prefix "\002\0037TV ->\003\002 "
    set arg [string map { " " "_" } $arg]
 
    set url "http://services.tvrage.com/tools/quickinfo.php?show=$arg"
    set page [http::data [http::geturl $url -timeout $tvrage(timeout)]]
 
    regexp {Show Name@([A-Za-z 0-9\&\':]+)} $page gotname show_name
    set gotnext [regexp {Next Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:.,]+)\^([A-Za-z0-9/]+)} $page gotnext next_ep next_ep_title next_ep_date]
    regexp {Airtime@([A-Za-z, 0-9:]+)} $page gotairtime show_airtime
    
    if { ![info exists show_name] } {
       putquick "PRIVMSG $chan :$prefix Error! (timeout or something similar)"
       return -1
    }

    if { $gotnext == 0 } {
      putquick "PRIVMSG $chan :$prefix The next episode of \002$show_name\002 is not yet scheduled. That makes me a sad panda :("
    } else {
   putquick "PRIVMSG $chan :$prefix The next episode of \002$show_name\002 is \002$next_ep_title \[$next_ep\]\002, it will air on \002$show_airtime\002 \002$next_ep_date\002"
   }
}
 
proc dlx:tvrage:last { nick host hand chan arg } {
    global tvrage
    package require http
    set prefix "\002\0037TV ->\003\002 "
    set arg [string map { " " "_" } $arg]
 
    set url "http://services.tvrage.com/tools/quickinfo.php?show=$arg"
    set page [http::data [http::geturl $url -timeout $tvrage(timeout)]]
 
    regexp {Show Name@([A-Za-z 0-9\&\':]+)} $page gotname show_name
    regexp {Latest Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:\.,]+)\^([A-Za-z0-9/]+)} $page gotlatest latest_ep latest_ep_title latest_ep_date
    set gotnext [regexp {Next Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:.,]+)\^([A-Za-z0-9/]+)} $page gotnext next_ep next_ep_title next_ep_date]

    if { ![info exists show_name] } {
       putquick "PRIVMSG $chan :$prefix Error! (timeout or something similar)"
       return -1
    }
    
   putquick "PRIVMSG $chan :$prefix The last episode of \002$show_name\002 is \002$latest_ep_title $latest_ep\ \002 it aired on \002$latest_ep_date\002"
}

proc dlx:tvrage:tonight { nick host hand chan arg } {
   global tvrage
   if { [info exists chans] } { unset chans }
   package require http
   set prefix "\002\0037TV ->\003\002 "
   set schedule [http::data [http::geturl "http://www.tvrage.com/quickschedule.php" -timeout $tvrage(timeout)]]

   set end [string first "\n\n" $schedule]
   set today [string range $schedule 0 $end]

   putquick "PRIVMSG $chan :$prefix TV Schedule for Today:"

   set showList "$prefix "

   foreach line [split $today "\n"] {
      set found_time [regexp {\[TIME\](.*)\[\/TIME\]} $line found_time time]
      set found_show [regexp {\[SHOW\](.*)\^(.*)\^(.*)\^(.*)\[\/SHOW\]} $line found_show show_channel show_name show_ep show_url]
      if { $found_show && [lsearch -exact $tvrage(excluded_Channels) $show_channel] == -1 } {
         if { $tvrage(inline) } {
            append showList "$show_name ($show_ep) - "
         } else {
            if {$tvrage(show_time)} { append chans($show_channel) "\037$time\037 " }
            append chans($show_channel) "\002$show_name\002 "
            if {$tvrage(show_episode)} { append chans($show_channel) "($show_ep) " }
         }
      }
   }
   if { $tvrage(inline) } {
      set showList [string range $showList 0 [expr [string length $showList] - 3]]
      putquick "PRIVMSG $chan :$showList"
   } else {
      set chanlist [array names chans]
      foreach x $chanlist {
         putquick "PRIVMSG $chan :$x\: $chans($x)"
      }
   }
}

proc dlx:tvrage:tomorrow { nick host hand chan arg } {
   global tvrage
   if { [info exists chans] } { unset chans }
   package require http
   set prefix "\002\0037TV ->\003\002 "
   set schedule [http::data [http::geturl "http://www.tvrage.com/quickschedule.php" -timeout $tvrage(timeout)]]

   set start [string first "\n\n" $schedule]
   set schedule [string range $schedule [expr $start+3] end]

   set end [string first "\n\n" $schedule]
   set tomorrow [string range $schedule 0 $end]

   putquick "PRIVMSG $chan :$prefix TV Schedule for Tomorrow:"

   set showList "$prefix "

   foreach line [split $tomorrow "\n"] {
      set found_time [regexp {\[TIME\](.*)\[\/TIME\]} $line found_time time]
      set found_show [regexp {\[SHOW\](.*)\^(.*)\^(.*)\^(.*)\[\/SHOW\]} $line found_show show_channel show_name show_ep show_url]
      if { $found_show && [lsearch -exact $tvrage(excluded_Channels) $show_channel] == -1 } {
         if { $tvrage(inline) == "TRUE" } {
            append showList "$show_name ($show_ep) - "
         } else {
            if {$tvrage(show_time)} { append chans($show_channel) "\037$time\037 " }
            append chans($show_channel) "\002$show_name\002 "
            if {$tvrage(show_episode)} { append chans($show_channel) "($show_ep) " }
         }
      }
   }
   if { $tvrage(inline) == "TRUE" } {
      set showList [string range $showList 0 [expr [string length $showList] - 3]]
      putquick "PRIVMSG $chan :$showList"
   } else {
      set chanlist [array names chans]
      foreach x $chanlist {
         putquick "PRiVmsg $chan :$x\: $chans($x)"
      }
   }
}

putlog "dlx-tvrage_v2.3f.tcl loaded. enjoy!"

Z
Znuff
Voice
Posts: 9
Joined: Mon May 17, 2010 1:00 am

Post by Znuff »

if the above code doesn't really work for you (it worked for me, but not for a friend...), try this one:

Code: Select all

###########################################################
# tvrage LOOKUP SCRIPT (dlx @ linknet)                    #
###########################################################
# v2.3fix - changed API url                               #
#         - added timeout after 5 seconds (stops crashing #
#           if tvrage.com is slow                         #
#         - modified by znuff on 17/05/2010               #
###########################################################
# v2.3 - changed the way !today and                       #
#        !tomorrow reply for less spam                    #
###########################################################
# v2.2 - added tvrage(inline) support                     #
#        for iPoRn                                        #
###########################################################
# v2.1 - added time output to !tonight                    #
#         and !tomorrow for nogruk                        #
###########################################################
# v2.0 - new commands !next/!last/                        #
#                !tonight/!tomorrow                       #
###########################################################

bind pub - .tv dlx:tvrage:tv
bind pub - .tvnext dlx:tvrage:next
bind pub - .tvlast dlx:tvrage:last
#bind pub - .tvtonight dlx:tvrage:tonight
#bind pub - .tvtomorrow dlx:tvrage:tomorrow

# Channels not to be displayed on !tonight/!tomorrow
set tvrage(excluded_Channels) [list "Nickelodeon" "Disney Channel" "Style" "VH1" "HGTV" "PBS" "Cooking Channel" "Food Network" "TLC" "Discovery Channel" "Spike TV" "E!" "A&E" "Cartoon Network" "Animal Planet"]

# timeout value - in miliseconds
set tvrage(timeout) "5000"

# Show the Time of the show?
set tvrage(show_time) "TRUE"

# Show the Episode number of the show?
set tvrage(show_episode) "TRUE"

# Display !tonight and !tomorrow in one line?
# TRUE will squeeze all shows into one line
# FALSE will split them up by channel (DEFAULT)
set tvrage(inline) "FALSE"

proc dlx:tvrage:tv { nick host hand chan arg } {
    global tvrage
    package require http
    set prefix "\002\0037TV ->\003\002 "
 
    set arg [string map { " " "%20" } $arg]
 
    set url "http://services.tvrage.com/tools/quickinfo.php?show=$arg"
    set page [http::data [http::geturl $url -timeout $tvrage(timeout)]]

    regexp {Show Name@([A-Za-z 0-9\&\':]+)} $page gotname show_name
    regexp {Show URL@http://www.tvrage.com/([A-Za-z_0-9/-]+)} $page goturl show_url
    regexp {Premiered@([0-9]+)} $page gotpremiere show_premiered
    regexp {Latest Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:\.,]+)\^([A-Za-z0-9/]+)} $page gotlatest latest_ep latest_ep_title latest_ep_date
    set gotnext [regexp {Next Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:.,]+)\^([A-Za-z0-9/]+)} $page gotnext next_ep next_ep_title next_ep_date]
    regexp {Country@([A-Za-z]+)} $page gotcountry show_country
    regexp {Status@([A-Za-z/ ]+)} $page gotstatus show_status
    regexp {Classification@([A-Za-z ]+)} $page gotclassification show_classification
    set gotgenres [regexp {Genres@([A-Za-z |]+)} $page gotgenres show_genres]
    regexp {Network@([A-Za-z 0-9]+)} $page gotnetwork show_network
    regexp {Airtime@([A-Za-z, 0-9:]+)} $page gotairtime show_airtime

    if { ![info exists show_name] } {
       putquick "PRIVMSG $chan :$prefix Error! (timeout or something similar)"
    #   return -1
    }

    set show_url "http://www.tvrage.com/$show_url"
    if { $gotgenres == 0 } { set show_genres "N/A" }
    if { $gotnext == 0 } {
            set next_ep "00x00"
            set next_ep_title "-N/A-"
            set next_ep_date "not available"
    }
   putquick "PRIVMSG $chan :$prefix Show: $show_name ($show_classification \| $show_genres)"
   putquick "PRIVMSG $chan :$prefix Premiered: $show_premiered"
   putquick "PRIVMSG $chan :$prefix Status: $show_status"
   putquick "PRIVMSG $chan :$prefix Network: $show_network"
   putquick "PRIVMSG $chan :$prefix URL: $show_url"
}

proc dlx:tvrage:next { nick host hand chan arg } {
    global tvrage
    package require http
    set prefix "\002\0037TV ->\003\002 "
    set arg [string map { " " "_" } $arg]
 
    set url "http://services.tvrage.com/tools/quickinfo.php?show=$arg"
    set page [http::data [http::geturl $url -timeout $tvrage(timeout)]]
 
    regexp {Show Name@([A-Za-z 0-9\&\':]+)} $page gotname show_name
    set gotnext [regexp {Next Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:.,]+)\^([A-Za-z0-9/]+)} $page gotnext next_ep next_ep_title next_ep_date]
    regexp {Airtime@([A-Za-z, 0-9:]+)} $page gotairtime show_airtime
    
    if { ![info exists show_name] } {
       putquick "PRIVMSG $chan :$prefix Error! (timeout or something similar)"
    #   return -1
    }

    if { $gotnext == 0 } {
      putquick "PRIVMSG $chan :$prefix The next episode of \002$show_name\002 is not yet scheduled. That makes me a sad panda :("
    } else {
   putquick "PRIVMSG $chan :$prefix The next episode of \002$show_name\002 is \002$next_ep_title \[$next_ep\]\002, it will air on \002$show_airtime\002 \002$next_ep_date\002"
   }
}
 
proc dlx:tvrage:last { nick host hand chan arg } {
    global tvrage
    package require http
    set prefix "\002\0037TV ->\003\002 "
    set arg [string map { " " "_" } $arg]
 
    set url "http://services.tvrage.com/tools/quickinfo.php?show=$arg"
    set page [http::data [http::geturl $url -timeout $tvrage(timeout)]]
 
    regexp {Show Name@([A-Za-z 0-9\&\':]+)} $page gotname show_name
    regexp {Latest Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:\.,]+)\^([A-Za-z0-9/]+)} $page gotlatest latest_ep latest_ep_title latest_ep_date
    set gotnext [regexp {Next Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:.,]+)\^([A-Za-z0-9/]+)} $page gotnext next_ep next_ep_title next_ep_date]

    if { ![info exists show_name] } {
       putquick "PRIVMSG $chan :$prefix Error! (timeout or something similar)"
    #   return -1
    }
    
   putquick "PRIVMSG $chan :$prefix The last episode of \002$show_name\002 is \002$latest_ep_title $latest_ep\ \002 it aired on \002$latest_ep_date\002"
}

proc dlx:tvrage:tonight { nick host hand chan arg } {
   global tvrage
   if { [info exists chans] } { unset chans }
   package require http
   set prefix "\002\0037TV ->\003\002 "
   set schedule [http::data [http::geturl "http://www.tvrage.com/quickschedule.php" -timeout $tvrage(timeout)]]

   set end [string first "\n\n" $schedule]
   set today [string range $schedule 0 $end]

   putquick "PRIVMSG $chan :$prefix TV Schedule for Today:"

   set showList "$prefix "

   foreach line [split $today "\n"] {
      set found_time [regexp {\[TIME\](.*)\[\/TIME\]} $line found_time time]
      set found_show [regexp {\[SHOW\](.*)\^(.*)\^(.*)\^(.*)\[\/SHOW\]} $line found_show show_channel show_name show_ep show_url]
      if { $found_show && [lsearch -exact $tvrage(excluded_Channels) $show_channel] == -1 } {
         if { $tvrage(inline) } {
            append showList "$show_name ($show_ep) - "
         } else {
            if {$tvrage(show_time)} { append chans($show_channel) "\037$time\037 " }
            append chans($show_channel) "\002$show_name\002 "
            if {$tvrage(show_episode)} { append chans($show_channel) "($show_ep) " }
         }
      }
   }
   if { $tvrage(inline) } {
      set showList [string range $showList 0 [expr [string length $showList] - 3]]
      putquick "PRIVMSG $chan :$showList"
   } else {
      set chanlist [array names chans]
      foreach x $chanlist {
         putquick "PRIVMSG $chan :$x\: $chans($x)"
      }
   }
}

proc dlx:tvrage:tomorrow { nick host hand chan arg } {
   global tvrage
   if { [info exists chans] } { unset chans }
   package require http
   set prefix "\002\0037TV ->\003\002 "
   set schedule [http::data [http::geturl "http://www.tvrage.com/quickschedule.php" -timeout $tvrage(timeout)]]

   set start [string first "\n\n" $schedule]
   set schedule [string range $schedule [expr $start+3] end]

   set end [string first "\n\n" $schedule]
   set tomorrow [string range $schedule 0 $end]

   putquick "PRIVMSG $chan :$prefix TV Schedule for Tomorrow:"

   set showList "$prefix "

   foreach line [split $tomorrow "\n"] {
      set found_time [regexp {\[TIME\](.*)\[\/TIME\]} $line found_time time]
      set found_show [regexp {\[SHOW\](.*)\^(.*)\^(.*)\^(.*)\[\/SHOW\]} $line found_show show_channel show_name show_ep show_url]
      if { $found_show && [lsearch -exact $tvrage(excluded_Channels) $show_channel] == -1 } {
         if { $tvrage(inline) == "TRUE" } {
            append showList "$show_name ($show_ep) - "
         } else {
            if {$tvrage(show_time)} { append chans($show_channel) "\037$time\037 " }
            append chans($show_channel) "\002$show_name\002 "
            if {$tvrage(show_episode)} { append chans($show_channel) "($show_ep) " }
         }
      }
   }
   if { $tvrage(inline) == "TRUE" } {
      set showList [string range $showList 0 [expr [string length $showList] - 3]]
      putquick "PRIVMSG $chan :$showList"
   } else {
      set chanlist [array names chans]
      foreach x $chanlist {
         putquick "PRiVmsg $chan :$x\: $chans($x)"
      }
   }
}

putlog "dlx-tvrage_v2.3f.tcl loaded. enjoy!"
l
luminoso
Voice
Posts: 7
Joined: Mon Jul 02, 2007 7:59 am

Post by luminoso »

thank you!
Post Reply