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.

tv search (Danish, or can be edited to it)

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

tv search (Danish, or can be edited to it)

Post by Fire-Fox »

Hey all

Is there a tv program Somethin like tvrage, where it shows air time and such?


I have tryed : tvrip2.tcl from the archive.
but there is and error in script or the site has been changed.
Update of TV3 failed, retrying in 60secs

Code: Select all

proc gettitles {tvkanal url} {
 global tv tvdb
 set token [http::geturl $url]
 upvar #0 $token state
 set lines 0
 foreach line [split $state(body) "\n"] {
  incr lines
  if {[string match "*<span class='udsendelse-symboler'>*" $line]} {
   set line [string range $line 0 [string first "<span class='udsendelse-symboler'>" $line]]
  }
  if {[regexp $tv(regex) $line garbage time title]} {
   if {[string match -nocase "*</span>*" $title]} {
    set title [string range $title 0 [expr [string first "</span>" $title] - 1]]
   }
    #$time should be converted to the min of day
    set time [hhmm2minofday $time]
    tv:add $tvkanal $time $title
  }
 }
if {$lines < 15} {
timer 1 "gettitles $tvkanal $url"
putserv "PRIVMSG #dktv :Update of $tvkanal failed, retrying in 60secs"
putlog "Update of $tvkanal failed, retrying in 60secs"
} else {
 putlog "Updated $tvkanal"
 putserv "PRIVMSG #dktv :Updated $tvkanal"
}
}
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

no one :D?
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: tv search (Danish, or can be edited to it)

Post by speechles »

Code: Select all

  if {[regexp $tv(regex) $line garbage time title]} { 
what does $tv(regex) contain? As GI Joe once said, knowing is half the battle. Without knowing this battle is surely lost.. :lol:
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Re: tv search (Danish, or can be edited to it)

Post by Fire-Fox »

speechles wrote:

Code: Select all

  if {[regexp $tv(regex) $line garbage time title]} { 
what does $tv(regex) contain? As GI Joe once said, knowing is half the battle. Without knowing this battle is surely lost.. :lol:
Have no clue.

but here is the whole code

Code: Select all

package require http

#tvrip2.tcl version 2.10 Released 15-08-2003

set tv(lastid) 0

set tv(regex) "<div><span class='.*'>(.*)</span>  <span class='.*' onclick='.*'>(.*)</span>.*"

setudef flag tvrip

proc tv:add {station time title} {
	global tv tvdb
	set id [incr tv(lastid)]
	set tvdb($id,station) $station
	set tvdb($id,time) $time
	set tvdb($id,title) $title
	return $id
}
bind pub -|- !rehash pub:update:list
proc pub:update:list {nick uhost handle chan text} {
putserv "PRIVMSG $chan :Updateing lists"
tv:update:list
}

proc tv:update:list {} {
 global tvrip tvdb
 catch { unset tvdb }
 set tvrip(db) ""
 set kanalnavne ""TV2" "TV2ZULU" "DR1" "DR2" "TV3+" "TV3" "TVDK1" "TVDK2""
 set i 0
 foreach kanal $kanalnavne {
  incr i
  set url "http://tv.tv2.dk/tv/listning.php?sektion&Soegeord=&Kategori=0&Periode=-1&KanalID=$i&Region=0&dato=3"
  utimer [expr $i * 5] "gettitles [join [lindex $kanalnavne [expr $i - 1]]] $url"
 }
}

proc getnow {} {
  #Return min of day
  set usecs [clock seconds]
  set h [clock format $usecs -format "%H"]
  set m [clock format $usecs -format "%M"]
  if {[string index $h 0]==0} { set h [string index $h 1] }
# set h [expr $h + 6] ; #To compensate for timezone diff.
  if {$h > 23} { set h [expr $h - 24] }
  if {[string index $m 0]==0} { set m [string index $m 1] }
  set res [expr $h * 60]
  set res [expr $res + $m]

  if {$res > 1400} { set res [expr $res - 1400] }

  return $res
}

proc hhmm2minofday {time} {
  set hh [join [lindex [split $time ":"] 0]]
  set min [join [lindex [split $time ":"] 1]]
  if {[string index $hh 0]==0} { set hh [string index $hh 1] }
  if {[string index $min 0]==0} { set min [string index $min 1] }
  set res [expr $hh * 60]
  set res [expr $res + $min]
  return $res
}

proc gettitles {tvkanal url} {
 global tv tvdb
 set token [http::geturl $url]
 upvar #0 $token state
 set lines 0
 foreach line [split $state(body) "\n"] {
  incr lines
  if {[string match "*<span class='udsendelse-symboler'>*" $line]} {
   set line [string range $line 0 [string first "<span class='udsendelse-symboler'>" $line]]
  }
  if {[regexp $tv(regex) $line garbage time title]} {
   if {[string match -nocase "*</span>*" $title]} {
    set title [string range $title 0 [expr [string first "</span>" $title] - 1]]
   }
    #$time should be converted to the min of day
    set time [hhmm2minofday $time]
    tv:add $tvkanal $time $title
  }
 }
if {$lines < 15} {
timer 1 "gettitles $tvkanal $url"
putserv "RIVMSG #dktv :Update of $tvkanal failed, retrying in 60secs"
putlog "Update of $tvkanal failed, retrying in 60secs"
} else {
 putlog "Updated $tvkanal"
 putserv "PRIVMSG #dktv :Updated $tvkanal"
}
}

proc nowplus {min} {
 set next [expr $min + [getnow]]
 if {$next > 1440} { set next [expr $next - 1440] }
 return $next
}

proc notifychan {s t} {
foreach chan [channels] {
 if {[lsearch [channel info $chan] +tvrip]>-1 && [lsearch [channel info $chan] -inactive]>-1} {
  putserv "PRIVMSG $chan :\[$s\] $t"
 }
}
}

bind time - "* * * * *" tv:db:warn
proc tv:db:warn {min hour day month year} {
global tvdb
if {[getnow]==304} { tv:update:list }  ;  #tv2.dk resets at 300
#  set warn [nowplus 5]
  set warn [getnow]
  putloglev 5 * "Looking for programs with time $warn"
  set size [array size tvdb]
  for {set i 0} {$i<$size} {incr i} {
   set col [array get tvdb $i,*]
   if {$col != ""} {
    set time [tvdb:getfield $i time]
    putloglev 4 * "$time == $warn"
    if {$time == $warn} {
     set title [tvdb:getfield $i title]
     set station [tvdb:getfield $i station]
     notifychan $station $title
    }
   }
  }
}

proc tvdb:getfield {id field} {
 global tvdb
	return [join [lindex [array get tvdb $id,$field] 1]]
 }

proc humantime {time} {
	set hour 0
	set min 0
	while {$time>59} {
	set time [expr $time - 60]
		incr hour
	}
	set min $time
	if {$hour<9} { set hour "0$hour" }
	if {$min<9} { set min "0$min" }
	return $hour:$min
}

proc islater {now time} {
 #return 1 if time is later then now
 if {$now < 300} {
  #After midnight and before update
  if {$time > $now && $time < 300} { return 1 }
  return 0
 }
 if {$now == 300} { return 0 }
 if {$now > 300} {
  #After update time
  if {$time > $now} { return 1 }
  if {$time < 300} { return 1 }
  return 0
 }
}

#!tv <kanal>
#!tvall
#!search
bind pub -|- !tv pub:tv
proc pub:tv {nick uhost handle chan text} {
	global tvdb
	set kanal [join [lindex $text 0]]
	#Find next 5 programs on kanal
	set size [array size tvdb]
	set now [getnow]
	set found 0
	for {set i 0} {$i<$size} {incr i} {
		set col [array get tvdb $i,*]
		if {$col != ""} {
			set time [tvdb:getfield $i time]
			set station [tvdb:getfield $i station]
			if {[string match -nocase $station $kanal]} {
				if {[islater $now $time]} {
					incr found
					set title [tvdb:getfield $i title]
					set htime [humantime $time]
					putserv "PRIVMSG $nick :$htime $title"
					if {$found==5} { break }
				}
			}
		}
	}
}

bind pub -|- !tvall pub:tvall
proc pub:tvall {nick uhost handle chan text} {
	global tvdb
	#Find next program for all channels.
	set size [array size tvdb]
	set now [getnow]
	set found ""
	for {set i 0} {$i<$size} {incr i} {
		set col [array get tvdb $i,*]
		if {$col != ""} {
			set time [tvdb:getfield $i time]
			set station [tvdb:getfield $i station]
			if {[lsearch $found $station]!=-1} {
				if {[islater $now $time]} {
					lappend found $station
					set title [tvdb:getfield $i title]
					set htime [humantime $time]
					putserv "PRIVMSG $nick :$htime \[$station\] $title"
					putloglev 8 * "Found=[llength $found]"
					if {[llength $found]==8} { break }
				}
			}
		}
	}
}

bind pub -|- !search pub:search
proc pub:search {nick uhost handle chan text} {
	global tvdb
	set program [join [lindex $text 0]]
	#Find all future programs containing program (max 10)
	set size [array size tvdb]
	set now [getnow]
	set found 0
	for {set i 0} {$i<$size} {incr i} {
		set col [array get tvdb $i,*]
		if {$col != ""} {
			set time [tvdb:getfield $i time]
			set title [tvdb:getfield $i title]
			if {[string match -nocase "*$program*" $title]} {
				if {[islater $now $time]} {
					incr found
					set station [tvdb:getfield $i station]
					set htime [humantime $time]
					putserv "PRIVMSG $nick :$htime \[$station\] $title"
					if {[llength $found]==10} { break }
				}
			}
		}
	}
	if {$found==0} { putserv "PRIVMSG $nick :Sorry, no matches" }
}

#TODO : pub triggers /msg triggers
if {![info exists tv(started)]} {
 utimer 20 tv:update:list
 set tv(started) 1
}
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

Please close the topic :)
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
Post Reply