Class: FreshLive

Inherits:
WebRadio show all
Defined in:
lib/freshlive.rb

Instance Method Summary collapse

Methods inherited from WebRadio

#initialize, instance

Constructor Details

This class inherits a constructor from WebRadio

Instance Method Details

#downloadObject



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
# 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$/, '.mp4')
      if exist?(dst)
        puts "#{dst} is existent, skipped."
        return
      end
      open(src, 'wb') do |w|
        print "getting #{src}..."
        ts_list(meta['data']['archiveStreamUrl']).each do |u|
          print '.'
          w.write(open(u, 'rb').read)
        end
      end
      dst = mp4nize(src)
      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

#dumpObject



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/freshlive.rb', line 46

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