Class: Nicovideo

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

Instance Method Summary collapse

Methods inherited from WebRadio

instance

Constructor Details

#initialize(params, options) ⇒ Nicovideo

Returns a new instance of Nicovideo.



9
10
11
12
13
14
15
16
17
# File 'lib/nicovideo.rb', line 9

def initialize(params, options)
   = Pit::get('nicovideo', :require => {
    :id => 'your nicovideo id',
    :pass => 'your nicovideo password'
  })
  @nico = Niconico.new([:id], [:pass])
  @nico.
  super
end

Instance Method Details

#downloadObject



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/nicovideo.rb', line 19

def download
  begin
    video = get_video(@url)
  rescue NoMethodError
    raise DownloadError.new('video not found')
  end
  @cover = thumbinfo(video, 'thumbnail_url') unless @cover
  title = video.title || thumbinfo(video, 'title') || video.id
  title.tr!('0-9', '0-9')
  serial = title.scan(/(?:[#第]|[  ]EP|track-)(\d+)|/).flatten.compact[0].to_i
  appendix = title =~ /おまけ|アフタートーク/ ? 'a' : ''
  @file = "#{@label}##{'%02d' % serial}#{appendix}.#{video.type}"
  @mp3_file = @file.sub(/\....$/, '.mp3')
  mp3nize(@file, @mp3_file) do
    open(@file, 'wb:ASCII-8BIT') do |o|
      begin
        video.get_video do |body|
          print '.'
          o.write(body)
        end
      rescue Niconico::Video::VideoUnavailableError => e
        raise DownloadError.new(e.message)
      end
    end
  end
end

#dumpObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/nicovideo.rb', line 46

def dump
  begin
    tag = Pathname(@url).basename.to_s.gsub(%r|[-/]|, '_')
    rss_url = "#{@url}/video?rss=2.0"
    desc = RSS::Parser.parse(rss_url).channel.dc_creator
    return {
      tag => {
        'desc' => desc,
        'url' => rss_url,
        'label' => tag
      }
    }
  rescue RSS::NotWellFormedError
    raise
  end
end