Class: XMLTV::TvtodayGrabber
- Defined in:
- lib/xmltv/sites/tvtoday.rb
Constant Summary
Constants inherited from Grabber
Grabber::Dag, Grabber::MythTV, Grabber::Vandaag
Instance Attribute Summary
Attributes inherited from Grabber
#all_channels, #base_url, #channel_list, #chnbasedir, #config, #config_file_name, #generator, #myname, #reject_file_name, #spooldir
Instance Method Summary collapse
- #clean_cache(cache) ⇒ Object
- #day_url(chan_id, day) ⇒ Object
- #fetch_all_channels ⇒ Object
-
#grab_channel(chan_id) ⇒ Object
grab_channel return chan_idber of programs found.
- #grab_detail(href) ⇒ Object
-
#lang ⇒ Object
Must implement fetch_all_channels or define channel_list as nil Must returns something that respond_to? [].
-
#transform(chan_id) ⇒ Object
transform returns an array of special hashes (obtained with proghash).
Methods inherited from Grabber
#add_channels_to_config, #cachefile, #channel_display, #channel_name, #check_argv, #check_channel, #clean_cache_dir, #clean_spool_dir, #config_channels, #date_stats, #delete_channels_from_config, #do_list, #do_options, #dump, #fetch, #fix_times, #get_channels, #initialize, #list_all, #list_config, #load_cachefile, #load_channel_file, #load_config_file, #outputfile, #printline, #proghash, #reject, #report, #run, #save, #save_config, #save_object, #version
Constructor Details
This class inherits a constructor from XMLTV::Grabber
Instance Method Details
#clean_cache(cache) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/xmltv/sites/tvtoday.rb', line 62 def clean_cache(cache) count = 0 cache.delete_if do |dt, en| rsl = (Date.parse(en['datum']) < Vandaag) count += 1 if rsl rsl end count end |
#day_url(chan_id, day) ⇒ Object
72 73 74 |
# File 'lib/xmltv/sites/tvtoday.rb', line 72 def day_url(chan_id, day) "#{base_url}/program2007?format=genre&offset=0&date=#{day.german}&slotIndex=all&channel=#{chan_id}&order=time" end |
#fetch_all_channels ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/xmltv/sites/tvtoday.rb', line 19 def fetch_all_channels puts base_url url = @base_url page = fetch(url) channels = Hash.new page.at('//select[@name=channel]').search('//option').each do |op| val = op['value'] next if val.index('gruppeId') || val.empty? channels[val] = op.inner_text.strip.to_utf end save_object(channels, channel_list) channels end |
#grab_channel(chan_id) ⇒ Object
grab_channel return chan_idber of programs found
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/xmltv/sites/tvtoday.rb', line 76 def grab_channel(chan_id) fetched = found = 0 @channelhash = load_cachefile(chan_id) now = Date.today (now .. now + 14).each do |date| url = day_url(chan_id, date) # puts url # url = '/home/han/program2007' page = fetch(url) avond = false page.search('div#program_complete//tr').each do |prog| # puts prog times = prog.at('span.tv-sendung-uhrzeit') next unless times # puts times.inner_text titel = prog.at("td/a.tv-sendung-titel") id = titel['href'][/detailPopup\('(\d+)'/, 1] href = "/program2007?format=detail&sid=#{id}" # puts "#{id}: #{@channelhash[id]}" found += 1 next if @channelhash[id] begin @channelhash[id] = program = grab_detail(href) fetched += 1 rescue STDERR.puts href, page, '=====' raise end times = times.inner_text start = times.to_i avond = true if start > 17 program['times'] = times program['title'] = titel.inner_text.to_utf program['datum'] = date.to_s program['evening'] = avond # exit end end save_object(@channelhash, cachefile(chan_id)) if fetched > 0 found end |
#grab_detail(href) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/xmltv/sites/tvtoday.rb', line 32 def grab_detail(href) program = Hash.new if href[0] == ?/ href="#{base_url}#{href}" end # puts href page = fetch(href) info = page.at('span.tv-titel-popup').parent # puts info.at('span.tv-titel-popup').inner_text.to_utf program['desc-s'] = info.at('span.tv-vorspann-popup').inner_text.to_utf page.at('td.tv-sendung-info').each_child do |el| if el.is_a? Hpricot::Text program['desc'] = el.inner_text.to_utf break end end credits = page.at('span.tv-credits') if credits program['info'] = credits.parent.inner_text.to_utf end categ = info.at('span.tv-auszeichnung') if categ program['kind'] = categ.inner_text.to_utf end info.search('img').each do |img| program[img['title']] = true end program end |
#lang ⇒ Object
Must implement fetch_all_channels or define channel_list as nil Must returns something that respond_to? []
16 17 18 |
# File 'lib/xmltv/sites/tvtoday.rb', line 16 def lang 'de' end |
#transform(chan_id) ⇒ Object
transform returns an array of special hashes (obtained with proghash)
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/xmltv/sites/tvtoday.rb', line 121 def transform(chan_id) progdata_array = Array.new @channelhash.each_pair do |id, entry| begin progdata = proghash(entry, chan_id) # pp progdata # pp entry start, stop = entry['times'].split('-') date = Date.parse(entry['datum']) startuur, startmin, stopuur, stopmin = entry['times'].split(/[-.]/).map{|x| x.to_i} if startuur < 7 && entry['evening'] date += 1 end progdata['start'] = Time.local(date.year, date.month, date.day, startuur, startmin) progdata['stop'] = Time.local(date.year, date.month, date.day, stopuur, stopmin) if progdata['stop'] < progdata['start'] progdata['stop'] += Dag end date_stats(chan_id, progdata['start']) # puts progdata['stop'], progdata['start'] if entry['desc'].index("\t\t\t\t>") || entry['desc'].empty? && ! entry['desc-s'].empty? progdata['desc'] = entry['desc-s'] end if entry['info'] # puts entry['info'] details = entry['info'].split(';').map{|x| x.strip} role = nil details.each do |det| year = nil case det[0,2] when 'R:' role = 'director' det = det[2..-1].strip when 'D:' role = 'actor' det = det[2..-1] when 'O:' year = det[-5..-1].to_i else year = det[-5..-1].to_i end if year && year > 1900 progdata['date'] = year.to_s elsif role content = det.gsub(/\(.*\)/,'').strip unless content.empty? (progdata['credits'][role] ||= Array.new) << content end end end progdata['audio']['stereo'] = 'stereo' if entry['Stereo'] progdata['subtitles']['type'] = 'teletext' if entry['Untertitel'] progdata['video']['aspect'] = '16:9' if entry['Breitbild'] end progdata_array << progdata rescue StandardError => exc STDERR.puts exc, exc., exc.backtrace PP.pp(entry, STDERR) raise end end progdata_array end |