Class: FreshLive
Instance Method Summary
collapse
Methods inherited from WebRadio
#initialize, instance
Constructor Details
This class inherits a constructor from WebRadio
Instance Method Details
#download ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/freshlive.rb', line 6
def download
if URI(@url).path =~ %r|/search/|
archive = @url
else
archive = URI(File.join(@url + '/programs/archive'))
end
each_programs(Nokogiri(open(archive).read)) do |meta|
begin
serial = meta['data']['title'].scan(/\d+$/).first.to_i
src = "#{@label}##{'%02d' % serial}.ts"
dst = src.sub(/\.ts$/, @options.mp3 ? '.mp3' : '.mp4')
if exist?(dst)
puts "#{dst} is existent, skipped."
return
end
unless exist?(src)
open(src, 'wb') do |w|
print "getting #{src}..."
ts_list(meta['data']['archiveStreamUrl']).each_with_index do |u, i|
print '.' if i % 50 == 0
w.write(open(u, 'rb').read)
end
end
end
if @options.mp3
dst = to_mp3(src)
else
dst = to_mp4(src)
end
puts 'done.'
move(dst)
return
rescue OpenURI::HTTPError
puts 'try next.'
next
rescue
puts 'fail.'
$stderr.puts 'faild to convert .ts => .mp4'
return
end
end
puts 'fail.'
$stderr.puts 'free program not found.'
end
|
#dump ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/freshlive.rb', line 52
def dump
u = URI(@url)
if u.path =~ %r|/search/|
desc = URI.decode_www_form_component(Pathname(u.path).basename.to_s)
return {
'freshlive_search' => {
'desc' => desc,
'url' => @url,
'label' => desc
}
}
else
tag = Pathname(u.path).basename.to_s
meta = JSON.parse(Nokogiri(open(@url, &:read)).css('script').first)
return {
tag => {
'desc' => meta['name'],
'url' => @url,
'label' => tag
}
}
end
end
|