daily pastebin goal
42%
SHARE
TWEET

TVmaze.com Eggdrop Script (Version 1.25 / 2015-10-03)

johndigweed Oct 3rd, 2015 759 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##############################[ TVmaze.com Eggdrop Script ]######################
  2. #                                                                               #
  3. variable tvmazeversion 1.25
  4. #                                                                               #
  5. # Author   : x0x a.k.a. ericNL (freenode + EFnet)                               #
  6. # Source   : http://forum.egghelp.org/viewtopic.php?t=20045                     #
  7. #            Latest version of this script always in the 1st post of the topic! #
  8. #                                                                               #
  9. # Activate : Party line command: .chanset #channel +tvmaze                      #
  10. # Commands : !tv or !t <show>    !last or !l <show>    !next or !n <show>       #
  11. #                                                                               #
  12. # Credits  : GaveUp, dlx, Znuff, speechles, nrt, Chokladkakan                   #
  13. #            Viper (Jan Milants), thommey, GPenguin                             #
  14. #                                                                               #
  15. # Greets   : Everyone over at http://forum.egghelp.org                          #
  16. #            The freenode #eggdrop crowd                                        #
  17. #            My friends in #<translate-shark-to-dutch> on EFnet ;)              #
  18. #                                                                               #
  19. #################################################################################
  20.  
  21. # We'll be needing these to run the script.
  22. package require http
  23. package require json
  24.  
  25. # Don't forget to activate the script by setting .chanset #channel +tvmaze
  26. setudef flag tvmaze
  27.  
  28. # The channel triggers.
  29. bind pub - !tv tv
  30. bind pub - !t tv
  31.  
  32. bind pub - !last tvlast
  33. bind pub - !l tvlast
  34.  
  35. bind pub - !next tvnext
  36. bind pub - !n tvnext
  37.  
  38. # Handle the !tv and !t triggers.
  39. proc tv { nick host hand chan arg } {
  40.  
  41.         # Basic warez scene formatting support.
  42.         # Translate 'The.Big.Bang.Theory.S09E01.720p.HDTV.X264-DIMENSION' to 'The Big Bang Theory' so that TVmaze understands your query.
  43.         regsub -nocase -all {(\.| )([[:digit:]]{4}(\.| )|)(S[[:digit:]]{2}E[[:digit:]]{2}(\.| )|)(INTERNAL|INT|1080p|720p|HDTV|x264|WEBRip|REPACK|REAL|PROPER)(\.| ).*} $arg "" arg
  44.         regsub -all "\\." $arg " " arg
  45.  
  46.         # This is where we contact TVmaze.
  47.         set url "http://api.tvmaze.com/singlesearch/shows?[::http::formatQuery q $arg embed\[\] nextepisode embed\[\] previousepisode]"
  48.         set timeout "5000"
  49.  
  50.         if {[catch { ::http::geturl $url -timeout $timeout } token]} {
  51.         putquick "privmsg $chan :$nick, there was a fatal error :$token."
  52.         return 0
  53.         }
  54.  
  55.         if {![string equal -nocase [::http::status $token] "ok"] || ![string equal [::http::ncode $token] 200]} {
  56.         putquick "privmsg $chan :$nick, there was an http error: ( [http::ncode $token] ) [::http::status $token]"
  57.         http::cleanup $token
  58.         return 0
  59.         }
  60.  
  61.         # Translate the TVmaze JSON data to Tcl dict which makes it possible for us to display the requested info in the IRC channel(s).
  62.         set tvmaze [::json::json2dict [::http::data $token]]
  63.         ::http::cleanup $token
  64.  
  65.         dict with tvmaze {
  66.  
  67.         # Set the network name.
  68.         # Is the show you're looking for available on Amazon/Netflix etc. or a network like ABC/HBO/Showtime etc.?
  69.         if {[string equal "null" $webChannel]} { set network [dict get $tvmaze network name] } else { set network [dict get $tvmaze webChannel name] }
  70.  
  71.         # If there is any info on a next episode, make sure we can use that info later on.
  72.         if { [dict exists $tvmaze _embedded nextepisode url] } { set nextepurl [dict get $tvmaze _embedded nextepisode url] }
  73.         if { [dict exists $tvmaze _embedded nextepisode name] } { set nextepname [dict get $tvmaze _embedded nextepisode name] }
  74.         if { [dict exists $tvmaze _embedded nextepisode season] } { set nextepseason [dict get $tvmaze _embedded nextepisode season] }
  75.         if { [dict exists $tvmaze _embedded nextepisode number] } { set nextepnumber [dict get $tvmaze _embedded nextepisode number] }
  76.         if { [dict exists $tvmaze _embedded nextepisode airdate] } { set nextepairdate [dict get $tvmaze _embedded nextepisode airdate] }
  77.         if { [dict exists $tvmaze _embedded nextepisode airtime] } { set nextepairtime [dict get $tvmaze _embedded nextepisode airtime] }
  78.         if { [dict exists $tvmaze _embedded nextepisode runtime] } { set nextepruntime [dict get $tvmaze _embedded nextepisode runtime] }
  79.         if { [dict exists $tvmaze _embedded nextepisode summary] } { set nextepsummary [dict get $tvmaze _embedded nextepisode summary] }
  80.  
  81.         # Same as above but now for the last/previous episode.
  82.         if { [dict exists $tvmaze _embedded previousepisode url] } { set prevepurl [dict get $tvmaze _embedded previousepisode url] }
  83.         if { [dict exists $tvmaze _embedded previousepisode name] } { set prevepname [dict get $tvmaze _embedded previousepisode name] }
  84.         if { [dict exists $tvmaze _embedded previousepisode season] } { set prevepseason [dict get $tvmaze _embedded previousepisode season] }
  85.         if { [dict exists $tvmaze _embedded previousepisode number] } { set prevepnumber [dict get $tvmaze _embedded previousepisode number] }
  86.         if { [dict exists $tvmaze _embedded previousepisode airdate] } { set prevepairdate [dict get $tvmaze _embedded previousepisode airdate] }
  87.         if { [dict exists $tvmaze _embedded previousepisode airtime] } { set prevepairtime [dict get $tvmaze _embedded previousepisode airtime] }
  88.         if { [dict exists $tvmaze _embedded previousepisode runtime] } { set prevepruntime [dict get $tvmaze _embedded previousepisode runtime] }
  89.         if { [dict exists $tvmaze _embedded previousepisode summary] } { set prevepsummary [dict get $tvmaze _embedded previousepisode summary] }
  90.  
  91.         # Set the airtime (if exists) and reformat the 24-hour clock data supplied by TVmaze to a 12-hour clock format.
  92.         if { [dict exists $tvmaze _embedded nextepisode airstamp] } {
  93.         set airstamp [clock scan [dict get $tvmaze _embedded nextepisode airstamp] -format {%Y-%m-%dT%H:%M:%S%z}]
  94.         set airstampnyc [clock format $airstamp -format {%I:%M %p %Z} -timezone :America/New_York]
  95.         }
  96.  
  97.         if { ![info exists name] } {
  98.                 putquick "privmsg $chan :$nick, nothing happened, try something different? :)"
  99.                 return 0
  100.         }
  101.  
  102.         # Add a leading 0 if the season number is 1-9. Do the same for episode numbers 1-9. This formats S1E1 to S01E01 to match warez scene formatting.
  103.         if { [info exists prevepseason] } { set prevepseason [format S%02d $prevepseason] }
  104.         if { [info exists prevepnumber] } { set prevepnumber [format E%02d $prevepnumber] }
  105.         if { [info exists nextepseason] } { set nextepseason [format S%02d $nextepseason] }
  106.         if { [info exists nextepnumber] } { set nextepnumber [format E%02d $nextepnumber] }
  107.  
  108.         if { [info exists nextepname] && [info exists prevepname] && ![llength $genres] == 1 } {
  109.                 putquick "privmsg $chan :Show: \002$name\002 \u2022 Network: $network"
  110.                 putquick "privmsg $chan :Premiered: $premiered \u2022 Status: $status \u2022 URL: $url"
  111.                 putquick "privmsg $chan :Previous: $prevepseason$prevepnumber aired $prevepairdate \u2022 Next: $nextepseason$nextepnumber airs $nextepairdate at $airstampnyc"
  112.         return 0
  113.                 }
  114.  
  115.         if { [info exists nextepname] && [info exists prevepname] } {
  116.                 putquick "privmsg $chan :Show: \002$name\002 \u2022 Network: $network \u2022 Genre: $genres"
  117.                 putquick "privmsg $chan :Premiered: $premiered \u2022 Status: $status \u2022 URL: $url"
  118.                 putquick "privmsg $chan :Previous: $prevepseason$prevepnumber aired $prevepairdate \u2022 Next: $nextepseason$nextepnumber airs $nextepairdate at $airstampnyc"
  119.                 return 0
  120.                 }
  121.  
  122.         if { ![info exists nextepname] && [info exists prevepname] && ![llength $genres] == 1 } {
  123.                 putquick "privmsg $chan :Show: \002$name\002 \u2022 Network: $network"
  124.                 putquick "privmsg $chan :Premiered: $premiered \u2022 Status: $status \u2022 URL: $url"
  125.                 putquick "privmsg $chan :Last: $prevepseason$prevepnumber aired $prevepairdate"
  126.                 return 0
  127.         }
  128.  
  129.         if { ![info exists nextepname] && [info exists prevepname] } {
  130.                 putquick "privmsg $chan :Show: \002$name\002 \u2022 Network: $network \u2022 Genre: $genres"
  131.                 putquick "privmsg $chan :Premiered: $premiered \u2022 Status: $status \u2022 URL: $url"
  132.                 putquick "privmsg $chan :Last: $prevepseason$prevepnumber aired $prevepairdate"
  133.                 return 0
  134.                 }
  135.  
  136.         if { [info exists nextepname] && ![info exists prevepname] && ![llength $genres] == 1 } {
  137.                 putquick "privmsg $chan :Show: \002$name\002 \u2022 Network: $network"
  138.                 putquick "privmsg $chan :Premiered: $premiered \u2022 Status: $status \u2022 URL: $url"
  139.                 putquick "privmsg $chan :Next episode: $nextepseason$nextepnumber airs $nextepairdate at $airstampnyc"
  140.                 return 0
  141.                 }
  142.  
  143.         if { [info exists nextepname] && ![info exists prevepname] } {
  144.                 putquick "privmsg $chan :Show: \002$name\002 \u2022 Network: $network \u2022 Genre: $genres"
  145.                 putquick "privmsg $chan :Premiered: $premiered \u2022 Status: $status \u2022 URL: $url"
  146.                 putquick "privmsg $chan :Next episode: $nextepseason$nextepnumber airs $nextepairdate at $airstampnyc"
  147.                 return 0
  148.                 }
  149.  
  150.         if { ![info exists nextepname] && ![info exists previousepname] && ![llength $genres] == 1 } {
  151.                 putquick "privmsg $chan :Show: \002$name\002 \u2022 Network: $network"
  152.                 putquick "privmsg $chan :Status: $status \u2022 URL: $url"
  153.                 return 0
  154.                 }
  155.  
  156.         if { ![info exists nextepname] && ![info exists previousepname] } {
  157.                 putquick "privmsg $chan :Show: \002$name\002 \u2022 Network: $network \u2022 Genre: $genres"
  158.                 putquick "privmsg $chan :Status: $status \u2022 URL: $url"
  159.                 return 0
  160.                 }
  161.  
  162.         }
  163.  
  164. }
  165.  
  166. # Handle the !next and !n triggers.
  167. proc tvnext { nick host hand chan arg } {
  168.  
  169.         set url "http://api.tvmaze.com/singlesearch/shows?[::http::formatQuery q $arg embed\[\] nextepisode embed\[\] previousepisode]"
  170.         set timeout "5000"
  171.  
  172.         if {[catch { ::http::geturl $url -timeout $timeout } token]} {
  173.         putquick "privmsg $chan :$nick, there was a fatal error :$token."
  174.         return 0
  175.         }
  176.  
  177.         if {![string equal -nocase [::http::status $token] "ok"] || ![string equal [::http::ncode $token] 200]} {
  178.         putquick "privmsg $chan :$nick, there was an http error: ( [http::ncode $token] ) [::http::status $token]"
  179.         http::cleanup $token
  180.         return 0
  181.         }
  182.  
  183.         set tvmaze [::json::json2dict [::http::data $token]]
  184.         ::http::cleanup $token
  185.  
  186.         dict with tvmaze {
  187.  
  188.         if {[string equal "null" $webChannel]} { set network [dict get $tvmaze network name] } else { set network [dict get $tvmaze webChannel name] }
  189.  
  190.         if { [dict exists $tvmaze _embedded nextepisode url] } { set nextepurl [dict get $tvmaze _embedded nextepisode url] }
  191.         if { [dict exists $tvmaze _embedded nextepisode name] } { set nextepname [dict get $tvmaze _embedded nextepisode name] }
  192.         if { [dict exists $tvmaze _embedded nextepisode season] } { set nextepseason [dict get $tvmaze _embedded nextepisode season] }
  193.         if { [dict exists $tvmaze _embedded nextepisode number] } { set nextepnumber [dict get $tvmaze _embedded nextepisode number] }
  194.         if { [dict exists $tvmaze _embedded nextepisode airdate] } { set nextepairdate [dict get $tvmaze _embedded nextepisode airdate] }
  195.         if { [dict exists $tvmaze _embedded nextepisode airtime] } { set nextepairtime [dict get $tvmaze _embedded nextepisode airtime] }
  196.         if { [dict exists $tvmaze _embedded nextepisode runtime] } { set nextepruntime [dict get $tvmaze _embedded nextepisode runtime] }
  197.         if { [dict exists $tvmaze _embedded nextepisode summary] } { set nextepsummary [dict get $tvmaze _embedded nextepisode summary] }
  198.  
  199.         if { [dict exists $tvmaze _embedded nextepisode airstamp] } {
  200.         set airstamp [clock scan [dict get $tvmaze _embedded nextepisode airstamp] -format {%Y-%m-%dT%H:%M:%S%z}]
  201.         set airstampnyc [clock format $airstamp -format {%I:%M %p %Z} -timezone :America/New_York]
  202.         }
  203.  
  204.         if { ![info exists nextepname] } {
  205.                 putquick "privmsg $chan :$nick, no next episode information."
  206.                         return 0
  207.                 }
  208.  
  209.                 set nextepseason [format S%02d $nextepseason]
  210.                 set nextepnumber [format E%02d $nextepnumber]
  211.  
  212.         putquick "privmsg $chan :Show: \002$name\002 \u2022 Next episode: $nextepseason$nextepnumber \"$nextepname\" airs $nextepairdate at $airstampnyc"
  213.  
  214.         }
  215.  
  216. }
  217.  
  218. # Handle the !last and !l triggers.
  219. proc tvlast { nick host hand chan arg } {
  220.  
  221.         set url "http://api.tvmaze.com/singlesearch/shows?[::http::formatQuery q $arg embed\[\] nextepisode embed\[\] previousepisode]"
  222.         set timeout "5000"
  223.  
  224.         if {[catch { ::http::geturl $url -timeout $timeout } token]} {
  225.         putquick "privmsg $chan :$nick, there was a fatal error :$token."
  226.         return 0
  227.         }
  228.  
  229.         if {![string equal -nocase [::http::status $token] "ok"] || ![string equal [::http::ncode $token] 200]} {
  230.         putquick "privmsg $chan :$nick, there was an http error: ( [http::ncode $token] ) [::http::status $token]"
  231.         http::cleanup $token
  232.         return 0
  233.         }
  234.  
  235.         set tvmaze [::json::json2dict [::http::data $token]]
  236.         ::http::cleanup $token
  237.  
  238.         dict with tvmaze {
  239.  
  240.         if {[string equal "null" $webChannel]} { set network [dict get $tvmaze network name] } else { set network [dict get $tvmaze webChannel name] }
  241.  
  242.         if { [dict exists $tvmaze _embedded previousepisode url] } { set prevepurl [dict get $tvmaze _embedded previousepisode url] }
  243.         if { [dict exists $tvmaze _embedded previousepisode name] } { set prevepname [dict get $tvmaze _embedded previousepisode name] }
  244.         if { [dict exists $tvmaze _embedded previousepisode season] } { set prevepseason [dict get $tvmaze _embedded previousepisode season] }
  245.         if { [dict exists $tvmaze _embedded previousepisode number] } { set prevepnumber [dict get $tvmaze _embedded previousepisode number] }
  246.         if { [dict exists $tvmaze _embedded previousepisode airdate] } { set prevepairdate [dict get $tvmaze _embedded previousepisode airdate] }
  247.         if { [dict exists $tvmaze _embedded previousepisode airtime] } { set prevepairtime [dict get $tvmaze _embedded previousepisode airtime] }
  248.         if { [dict exists $tvmaze _embedded previousepisode runtime] } { set prevepruntime [dict get $tvmaze _embedded previousepisode runtime] }
  249.         if { [dict exists $tvmaze _embedded previousepisode summary] } { set prevepsummary [dict get $tvmaze _embedded previousepisode summary] }
  250.  
  251.         if { ![info exists prevepname] } {
  252.                 putquick "privmsg $chan :$nick, no last episode information."
  253.                         return 0
  254.                 }
  255.  
  256.                 set prevepseason [format S%02d $prevepseason]
  257.                 set prevepnumber [format E%02d $prevepnumber]
  258.  
  259.                 putquick "privmsg $chan :Show: \002$name\002 \u2022 Last episode: $prevepseason$prevepnumber \"$prevepname\" aired $prevepairdate"
  260.  
  261.         }
  262.  
  263. }
  264.  
  265. putlog "TVmaze.com Eggdrop Script by x0x/ericNL version $tvmazeversion loaded!"
  266.  
  267. #eof
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top