Class: XMLTV::VproGrabber
Constant Summary
Constants inherited
from Grabber
Grabber::Dag, Grabber::MythTV, Grabber::Vandaag
Instance Attribute Summary
Attributes inherited from Grabber
#all_channels, #channel_list, #chnbasedir, #config, #config_file_name, #generator, #lang, #myname, #reject_file_name, #spooldir
Class Method Summary
collapse
Instance Method Summary
collapse
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, #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
Returns a new instance of VproGrabber.
10
11
12
13
14
|
# File 'lib/xmltv/sites/vpro.rb', line 10
def initialize
super
@cookie = nil
@zenders = config['channels'].map{|x| "zendersTV[]=#{x}"}.join('&')
end
|
Class Method Details
.cookie_parse(cookie) ⇒ Object
Ruby standard lib cookie parsing is seriously broken This is kind of a kludge, which works for vpro.nl
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/xmltv/sites/vpro.rb', line 34
def self.cookie_parse(cookie)
ourcookie = Array.new
cookie.split(/, (?=[A-Z])/).map{|x| x.split('=', 2)}.each do |pair|
cook, val = pair
val.gsub!(/;.*/, '')
unless val == 'deleted'
ourcookie << "#{cook}=#{val}"
end
end
ourcookie.join('; ')
end
|
Instance Method Details
#base_url ⇒ Object
15
16
17
|
# File 'lib/xmltv/sites/vpro.rb', line 15
def base_url
'http://gids.vpro.nl'
end
|
#clean_cache(cache) ⇒ Object
69
70
71
|
# File 'lib/xmltv/sites/vpro.rb', line 69
def clean_cache(cache)
0
end
|
#fetch_all_channels ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/xmltv/sites/vpro.rb', line 18
def fetch_all_channels
page = fetch(base_url)
channels = Hash.new
page.search('ul#selZendersTV//a').each do |a|
begin
channels[a['id'].to_utf] = a.inner_text.to_utf
rescue NoMethodError
STDERR.puts a, '===='
end
end
save_object(channels, channel_list)
channels
end
|
#grab_channel(chan_id) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/xmltv/sites/vpro.rb', line 73
def grab_channel(chan_id)
if @cookie.nil?
a = open('http://gids.vpro.nl')
@cookie = VproGrabber.cookie_parse(a.meta['set-cookie'])
end
url = "/index.php/gids"
datasrc = [ 'medium=TV', @zenders, 'layout=zender', "lZenCode=#{chan_id}"]
data = URI.escape(datasrc.join('&'))
http = Net::HTTP.new( 'gids.vpro.nl')
cook = @cookie
response = http.request_post(url, data,
{ 'Cookie' => cook, 'Content-Type' => 'application/x-www-form-urlencoded' } )
@channel_info = Array.new
%w{ vandaag morgen overmorgen }.each do |dag|
response = http.request_get("#{url}?medium=TV&dag=#{dag}", { 'Cookie' => cook } )
page = Hpricot(response.body)
vandaag = page.at('div#vandaag').inner_text
@avond = false
page.search('div.infoRow').each do |info|
@channel_info << grab_detail(info)
@channel_info[-1]['datum'] = vandaag
end
end
save_object(@channel_info, cachefile(chan_id))
@channel_info.size
end
|
#grab_detail(info) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/xmltv/sites/vpro.rb', line 45
def grab_detail(info)
program = Hash.new
begin
t = info.at('div.tijd').inner_text.strip
program['times'] = t
unless @avond
@avond = true if t.to_i > 17
end
program['avond'] = @avond
program['title'] = info.at('div.uitzending').inner_text.to_utf.strip.split("\n")[0]
detail = info.parent.at('div.detail')
program['category'] = detail.at('//p').inner_text.strip.split("\n")[-1]
program['desc'] = detail.at('//p.summary').inner_text.to_utf.strip rescue ''
rescue NoMethodError => exc
errfile = '/tmp/vpro.errors'
STDERR.puts "Some detail problem, see #{errfile}"
File.open(errfile, 'a') do |h|
h.puts Time.now
h.puts info,'===', detail, '++++++++++++'
end
end
program
end
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/xmltv/sites/vpro.rb', line 101
def transform(chan_id)
progdata_array = Array.new
@channel_info.each do | entry|
begin
progdata_array << ( progdata = proghash(entry, chan_id))
date = Date.dutch(entry['datum'])
startuur, startmin, stopuur, stopmin = entry['times'].split(/[^0-9]+/).map {|x| x.to_i }
shift = entry['avond'] && startuur < 9 ? Dag : 0
progdata['start'] = start = Time.local(date.year, date.month, date.day, startuur, startmin) + shift
progdata['stop'] = stop = Time.local(date.year, date.month, date.day, stopuur, stopmin) + shift
date_stats(chan_id, progdata['start'])
if stop < start
progdata['stop'] += Dag
end
rescue Exception => exc
STDERR.puts exc, exc.message, exc.backtrace
raise
end
end
progdata_array
end
|