egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
Fire-Fox
Master


Joined: 23 Sep 2006
Posts: 270
Location: /dev/null

PostPosted: Tue Feb 10, 2009 4:38 pm    Post subject: tv search (Danish, or can be edited to it) Reply with quote

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.

Quote:
Update of TV3 failed, retrying in 60secs


Code:
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
Back to top
View user's profile Send private message MSN Messenger
Fire-Fox
Master


Joined: 23 Sep 2006
Posts: 270
Location: /dev/null

PostPosted: Thu Feb 12, 2009 2:07 pm    Post subject: Reply with quote

no one Very Happy?
_________________
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
Back to top
View user's profile Send private message MSN Messenger
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Thu Feb 12, 2009 7:16 pm    Post subject: Re: tv search (Danish, or can be edited to it) Reply with quote

Code:
  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.. Laughing
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
Fire-Fox
Master


Joined: 23 Sep 2006
Posts: 270
Location: /dev/null

PostPosted: Fri Feb 13, 2009 12:26 pm    Post subject: Re: tv search (Danish, or can be edited to it) Reply with quote

speechles wrote:
Code:
  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.. Laughing


Have no clue.

but here is the whole code

Code:
package require http

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

set tv(lastid) 0

set tv(regex) "<div><span class='.*'>(.*)</span>&nbsp;&nbsp;<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
Back to top
View user's profile Send private message MSN Messenger
Fire-Fox
Master


Joined: 23 Sep 2006
Posts: 270
Location: /dev/null

PostPosted: Sat Feb 21, 2009 8:04 am    Post subject: Reply with quote

Please close the topic Smile
_________________
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber