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
51
|
# 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
if serial == 0
tmp = title.scan(/\d+/).last.to_i
serial = tmp if tmp > 0
end
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
count = 1
video.get_video do |body|
raise DownloadError.new(body) if body == '403 Forbidden'
print '.' if count % 400 == 0
o.write(body)
count += 1
end
rescue Niconico::Video::VideoUnavailableError => e
raise DownloadError.new(e.message)
end
end
end
end
|