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.

TVMaze Script That lists tonights shows

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
User avatar
CrazyCat
Revered One
Posts: 1303
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: TVMaze Script That lists tonights shows

Post by CrazyCat »

I made some corrections to your code:
Now, you have 3 procedures, tvmazetoday and tvmazetomorrow just format the good date and send it to tvmazeget which is the main proc.

All variables are out of the proc, it's simplest to change the configuration.
# -----------------------------------
# TVMaze TV !today API Announce
# -----------------------------------

set tvmaze_chan "#test"
set tvmaze_api_key "YOUR_KEY_HERE"

# Define the networks we're interested in
set tvmaze_networks {"AMC" "FOX" "FX" "SyFy" "Travel" "HBOMAX" "CW" "Starz" "TLC" "Showtime" "KTLA" "NBC" "CBS" "ABC"}
set tvmaze_tz +2

# Define the !today/!tonight command
bind pub - "!today" tvmazetoday
bind pub - "!tonight" tvmazetoday
bind time - "* 00 * * *" tvmazetoday
bind pub - "!tomorrow" tvmazetomorrow

package require http
package require tls
package require json

# Today proc
proc tvmazetoday {nick uhost hand chan text} {
   if {$chan ne $::tvmaze_chan} { return }
   tvmazeget "Today" [clock format [clock add [clock seconds] $::tvmaze_tz hours] -format "%Y-%m-%d"]
}

# Tomorrow proc: add 1 day
proc tvmazetomorrow {nick uhost hand chan text} {
   if {$chan ne $::tvmaze_chan} { return }
   tvmazeget "Tomorrow" [clock format [clock add [clock seconds] +1 day $::tvmaze_tz hours] -format "%Y-%m-%d"]
}

# Global proc
proc tvmazeget {fday day} {
   http::register https 443 [list ::tls::socket -autoservername true]
   set url "https://api.tvmaze.com/schedule"
   set response [http::geturl $url?date=${day}&country=US -headers [list "X-TVMaze-API-Key" $::tvmaze_api_key] -timeout 10000]
   putserv "PRIVMSG $::tvmaze_chan :$url?date=${day}&country=US"
   upvar 0 $response state
   if {$state(status) ne "ok"} {
      putlog "HTTP Error : $state(url) made $state(status) error"
      return
   }
   set json_data [::json::json2dict [http::data $response]]
   ::http::cleanup $response
   ::http::unregister https

   # Filter the TV shows by time and network
   set shows {}
   foreach item $json_data {
      set airtime [dict get $item airtime]
      set season [dict get $item season]
      set number [dict get $item number]
      set network [dict get [dict get $item show] network name]
      set name [dict get [dict get $item show] name]
      if {[lsearch -exact $::tvmaze_networks $network] != -1} {
         lappend shows [format "%s %s (S%sE%s) - %s" $airtime $name $season $number $network]
      }
   }

   # If no shows were found, display a message
   if {[llength $shows] == 0} {
      putquick "PRIVMSG $::tvmaze_chan :TVMAZE: ${fday}'s TV Shows:"
      putquick "PRIVMSG $::tvmaze_chan :00:00 No TV shows found for tonight"
      return
   }

   # List the TV shows in the channel
   putquick "PRIVMSG $::tvmaze_chan :TVMAZE: ${fday}'s TV Shows:"
   foreach show $shows {
      putquick "PRIVMSG $::tvmaze_chan :$show"
   }
}
H
Henkie2
Voice
Posts: 35
Joined: Fri Sep 25, 2015 2:55 pm

Re: TVMaze Script That lists tonights shows

Post by Henkie2 »

CrazyCat wrote: Wed Dec 13, 2023 5:24 am I made some corrections to your code:
Now, you have 3 procedures, tvmazetoday and tvmazetomorrow just format the good date and send it to tvmazeget which is the main proc.

All variables are out of the proc, it's simplest to change the configuration.
# -----------------------------------
# TVMaze TV !today API Announce
# -----------------------------------

set tvmaze_chan "#test"
set tvmaze_api_key "YOUR_KEY_HERE"

# Define the networks we're interested in
set tvmaze_networks {"AMC" "FOX" "FX" "SyFy" "Travel" "HBOMAX" "CW" "Starz" "TLC" "Showtime" "KTLA" "NBC" "CBS" "ABC"}
set tvmaze_tz +2

# Define the !today/!tonight command
bind pub - "!today" tvmazetoday
bind pub - "!tonight" tvmazetoday
bind time - "* 00 * * *" tvmazetoday
bind pub - "!tomorrow" tvmazetomorrow

package require http
package require tls
package require json

# Today proc
proc tvmazetoday {nick uhost hand chan text} {
   if {$chan ne $::tvmaze_chan} { return }
   tvmazeget "Today" [clock format [clock add [clock seconds] $::tvmaze_tz hours] -format "%Y-%m-%d"]
}

# Tomorrow proc: add 1 day
proc tvmazetomorrow {nick uhost hand chan text} {
   if {$chan ne $::tvmaze_chan} { return }
   tvmazeget "Tomorrow" [clock format [clock add [clock seconds] +1 day $::tvmaze_tz hours] -format "%Y-%m-%d"]
}

# Global proc
proc tvmazeget {fday day} {
   http::register https 443 [list ::tls::socket -autoservername true]
   set url "https://api.tvmaze.com/schedule"
   set response [http::geturl $url?date=${day}&country=US -headers [list "X-TVMaze-API-Key" $::tvmaze_api_key] -timeout 10000]
   putserv "PRIVMSG $::tvmaze_chan :$url?date=${day}&country=US"
   upvar 0 $response state
   if {$state(status) ne "ok"} {
      putlog "HTTP Error : $state(url) made $state(status) error"
      return
   }
   set json_data [::json::json2dict [http::data $response]]
   ::http::cleanup $response
   ::http::unregister https

   # Filter the TV shows by time and network
   set shows {}
   foreach item $json_data {
      set airtime [dict get $item airtime]
      set season [dict get $item season]
      set number [dict get $item number]
      set network [dict get [dict get $item show] network name]
      set name [dict get [dict get $item show] name]
      if {[lsearch -exact $::tvmaze_networks $network] != -1} {
         lappend shows [format "%s %s (S%sE%s) - %s" $airtime $name $season $number $network]
      }
   }

   # If no shows were found, display a message
   if {[llength $shows] == 0} {
      putquick "PRIVMSG $::tvmaze_chan :TVMAZE: ${fday}'s TV Shows:"
      putquick "PRIVMSG $::tvmaze_chan :00:00 No TV shows found for tonight"
      return
   }

   # List the TV shows in the channel
   putquick "PRIVMSG $::tvmaze_chan :TVMAZE: ${fday}'s TV Shows:"
   foreach show $shows {
      putquick "PRIVMSG $::tvmaze_chan :$show"
   }
}
Ohw wow that's awesome :D going to test now. (edit: tested only still no luck on https on http url it works) Thx for this much appreciated also comparing about https thx going to use it for getting experienced with it.

Also can you help on getting extra proc to collect data of that web/stream page so we can show that streams to
Like: Hulu/netflix etc. It's needs to be a new proc because of json regex is diff on this page.
User avatar
CrazyCat
Revered One
Posts: 1303
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: TVMaze Script That lists tonights shows

Post by CrazyCat »

With my tests, it works with https, peharps your tls package version is too old.

And I'm sorry but I haven't enough time to help you more with other parts, but I think you have all elements to improve the script.

Good luck !
H
Henkie2
Voice
Posts: 35
Joined: Fri Sep 25, 2015 2:55 pm

Re: TVMaze Script That lists tonights shows

Post by Henkie2 »

CrazyCat wrote: Wed Dec 13, 2023 9:05 am With my tests, it works with https, peharps your tls package version is too old.

And I'm sorry but I haven't enough time to help you more with other parts, but I think you have all elements to improve the script.

Good luck !
Maybe it's outdated, will have a check on that. Thanks once again and i'm going to try to get that stream as extra and will share my results :D

Edit: got 1.67 package (on windrop) anyone has the 1.7 compiled?
Also added !yesterday trigger as well, thx that was easy hahaha
Only that stream page, for some reason no results

changed to webchannel and airdate
https://api.tvmaze.com/schedule/web?dat ... country=US

Code: Select all

 # Filter the TV shows by time and network
   set shows {}
   foreach item $json_data {
      set airdate [dict get $item airdate]
      set season [dict get $item season]
      set number [dict get $item number]
      set webChannel [dict get [dict get $item show] webChannel name]
      set name [dict get [dict get $item show] name]
      if {[lsearch -exact $::tvmaze_streamnetworks $network] != -1} {
         lappend shows [format "%s %s (S%sE%s) - %s" $airdate $name $season $number $webChannel]
      }
   }
Post Reply