rget 1.1.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rget +3 -4
- data/lib/nicovideo.rb +9 -17
- data/lib/onsen.rb +4 -8
- data/lib/podcast.rb +2 -1
- data/lib/seaside-c.rb +6 -16
- data/lib/uliza.rb +9 -20
- data/lib/webradio.rb +39 -18
- data/rget.gemspec +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3948e94aa1e3af6de50e3932f601b9cca3d7f9bd
|
4
|
+
data.tar.gz: e81647ae6ecd6a38f29a8da45672108d0d4f2a29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 831e83211408af8a52f7731a3bdaf3cfe33f3116d3ca525774d924df9d761a09f5f1181d9e79208d9a489b6b394088c916b805bcb1b156ffe4bba013a33e364b
|
7
|
+
data.tar.gz: be3ebe369368e0e73473b78a8791ae8bba96b1799b2224196687a013b388a1c0d7f32dff35e4c9ef8bd16b89a198bbe4960aef4f11b8fe2012d6c1819357e071
|
data/bin/rget
CHANGED
@@ -7,7 +7,7 @@ require 'webradio'
|
|
7
7
|
require 'podcast'
|
8
8
|
|
9
9
|
class GetWebRadio < Thor
|
10
|
-
class_option :mp3, type: :boolean, default:
|
10
|
+
class_option :mp3, type: :boolean, default:true, desc:'convert to mp3 with ffmpeg'
|
11
11
|
|
12
12
|
config = nil
|
13
13
|
[
|
@@ -39,14 +39,13 @@ class GetWebRadio < Thor
|
|
39
39
|
|
40
40
|
private
|
41
41
|
def process(uri, label)
|
42
|
-
WebRadio(uri) do |radio|
|
42
|
+
WebRadio(uri, options) do |radio|
|
43
43
|
radio.download(label)
|
44
|
-
radio.mp3ize if options.mp3?
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
47
|
def podcast(uri, label = nil)
|
49
|
-
Podcast.new(uri) do |pod|
|
48
|
+
Podcast.new(uri, options) do |pod|
|
50
49
|
pod.download(label)
|
51
50
|
end
|
52
51
|
end
|
data/lib/nicovideo.rb
CHANGED
@@ -6,7 +6,7 @@ require 'open-uri'
|
|
6
6
|
require 'rss'
|
7
7
|
|
8
8
|
class Nicovideo < WebRadio
|
9
|
-
def initialize(url)
|
9
|
+
def initialize(url, options)
|
10
10
|
account = Pit::get('nicovideo', :require => {
|
11
11
|
:id => 'your nicovideo id',
|
12
12
|
:pass => 'your nicovideo password'
|
@@ -21,23 +21,15 @@ class Nicovideo < WebRadio
|
|
21
21
|
video = @nico.video(Pathname(URI(player_url).path).basename.to_s)
|
22
22
|
serial = video.title.scan(/(?:[#第]| EP)(\d+)|/).flatten.compact[0].to_i
|
23
23
|
@file = "#{name}##{'%02d' % serial}.#{video.type}"
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
video.get_video do |body|
|
32
|
-
print '.'
|
33
|
-
o.write(body)
|
24
|
+
@mp3_file = @file.sub(/\....$/, '.mp3')
|
25
|
+
mp3ize(@file, @mp3_file) do
|
26
|
+
open(@file, 'wb:ASCII-8BIT') do |o|
|
27
|
+
video.get_video do |body|
|
28
|
+
print '.'
|
29
|
+
o.write(body)
|
30
|
+
end
|
34
31
|
end
|
35
32
|
end
|
36
|
-
puts "done."
|
37
|
-
end
|
38
|
-
|
39
|
-
def mp3ize
|
40
|
-
mp3_convert(@file, @file.sub(/\....$/, '.mp3'))
|
41
33
|
end
|
42
34
|
|
43
35
|
private
|
@@ -49,7 +41,7 @@ private
|
|
49
41
|
rescue RSS::NotWellFormedError
|
50
42
|
html = open(list_url, &:read)
|
51
43
|
url = html.scan(%r|http://www.nicovideo.jp/watch/[\w]+|).first
|
52
|
-
raise
|
44
|
+
raise WebRadio::DownloadError.new('video not found in this pege') unless url
|
53
45
|
return url
|
54
46
|
end
|
55
47
|
end
|
data/lib/onsen.rb
CHANGED
@@ -16,14 +16,10 @@ private
|
|
16
16
|
form.attr('action') =~ %r[/#{program_id}\w+\.mp3]
|
17
17
|
}.first.attr('action')
|
18
18
|
mp3_file = "#{name}##{serial}.mp3"
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
mp3ize(mp3_file, mp3_file, false) do
|
20
|
+
open(mp3_file, 'wb:ASCII-8BIT') do |mp3|
|
21
|
+
mp3.write open(mp3_url, 'rb:ASCII-8BIT', &:read)
|
22
|
+
end
|
22
23
|
end
|
23
|
-
print "getting #{serial}..."
|
24
|
-
open(mp3_file, 'wb:ASCII-8BIT') do |mp3|
|
25
|
-
mp3.write open(mp3_url, 'rb:ASCII-8BIT', &:read)
|
26
|
-
end
|
27
|
-
puts "done."
|
28
24
|
end
|
29
25
|
end
|
data/lib/podcast.rb
CHANGED
data/lib/seaside-c.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
1
|
require 'webradio'
|
2
2
|
|
3
3
|
class SeasideCommnunications < WebRadio
|
4
|
-
def mp3ize
|
5
|
-
mp3_convert(@wma_file, @wma_file.sub(/\.wma$/, '.mp3'))
|
6
|
-
end
|
7
|
-
|
8
4
|
def download(name)
|
9
5
|
html = open(@url, &:read)
|
10
6
|
playlist_url, serial = html.scan(%r[(http:.*?\_(\d+).wax)]).flatten
|
11
7
|
unless playlist_url
|
12
|
-
|
13
|
-
exit -1
|
8
|
+
raise WebRadio::DownloadError.new("recent radio program not found.")
|
14
9
|
end
|
15
10
|
serial = serial.to_i
|
16
11
|
|
@@ -18,17 +13,12 @@ class SeasideCommnunications < WebRadio
|
|
18
13
|
wma_url, = playlist.scan(%r[http://.*?\.wma])
|
19
14
|
|
20
15
|
@wma_file = "#{name}##{serial}.wma"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
print "getting #{serial}..."
|
27
|
-
open(@wma_file, 'wb:ASCII-8BIT') do |wma|
|
28
|
-
wma.write(open(wma_url, &:read))
|
16
|
+
@mp3_file = @wma_file.sub(/\.wma$/, '.mp3')
|
17
|
+
mp3ize(@wma_file, @mp3_file) do
|
18
|
+
open(@wma_file, 'wb:ASCII-8BIT') do |wma|
|
19
|
+
wma.write(open(wma_url, &:read))
|
20
|
+
end
|
29
21
|
end
|
30
|
-
puts "done."
|
31
|
-
self
|
32
22
|
end
|
33
23
|
end
|
34
24
|
|
data/lib/uliza.rb
CHANGED
@@ -1,31 +1,20 @@
|
|
1
1
|
require 'webradio'
|
2
2
|
|
3
3
|
class Uliza < WebRadio
|
4
|
-
def mp3ize
|
5
|
-
mp3_convert(@m4a_file, @m4a_file.sub(/\.m4a$/, '.mp3'))
|
6
|
-
end
|
7
|
-
|
8
4
|
private
|
9
5
|
def uliza_download(name, html, serial_pattern, m3u_pattern)
|
10
6
|
serial = html.scan(serial_pattern).flatten.sort{|a,b| a.to_i <=> b.to_i}.last
|
11
7
|
@m4a_file = "#{name}##{serial}.m4a"
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
@mp3_file = @m4a_file.sub(/\.m4a$/, '.mp3')
|
9
|
+
mp3ize(@m4a_file, @mp3_file) do
|
10
|
+
m3u_meta2 = html.scan(m3u_pattern).flatten.sort.last
|
11
|
+
unless m3u_meta2
|
12
|
+
raise WebRadio::DownloadError.new("recent radio program not found.")
|
13
|
+
end
|
14
|
+
m3u_meta1 = open(m3u_meta2, &:read)
|
15
|
+
m3u = m3u_meta1.scan(/^[^#].*/).first
|
16
|
+
save_m4a(URI(m3u), @m4a_file)
|
21
17
|
end
|
22
|
-
print "getting #{serial}"
|
23
|
-
|
24
|
-
m3u_meta1 = open(m3u_meta2, &:read)
|
25
|
-
m3u = m3u_meta1.scan(/^[^#].*/).first
|
26
|
-
save_m4a(URI(m3u), @m4a_file)
|
27
|
-
puts "done."
|
28
|
-
self
|
29
18
|
end
|
30
19
|
|
31
20
|
def get_m4a(uri_playlist)
|
data/lib/webradio.rb
CHANGED
@@ -4,55 +4,76 @@ require 'open-uri'
|
|
4
4
|
require 'open3'
|
5
5
|
|
6
6
|
class WebRadio
|
7
|
-
|
7
|
+
class DownloadError < StandardError; end
|
8
|
+
|
9
|
+
def self.instance(url, options)
|
8
10
|
case url
|
9
11
|
when %r[^http://hibiki-radio\.jp/]
|
10
12
|
require 'hibiki'
|
11
|
-
Hibiki.new(url)
|
13
|
+
Hibiki.new(url, options)
|
12
14
|
when %r[^http://sp\.animate\.tv/]
|
13
15
|
require 'animate'
|
14
16
|
Animate.new(url)
|
15
17
|
when %r[^http://onsen\.ag/program/]
|
16
18
|
require 'onsen'
|
17
|
-
Onsen.new(url)
|
19
|
+
Onsen.new(url, options)
|
18
20
|
when %r[^http://seaside-c\.jp/program/], %r[http://nakamuland\.net/]
|
19
21
|
require 'seaside-c'
|
20
|
-
SeasideCommnunications.new(url)
|
22
|
+
SeasideCommnunications.new(url, options)
|
21
23
|
when %r[nicovideo\.jp]
|
22
24
|
require 'nicovideo'
|
23
|
-
Nicovideo.new(url)
|
25
|
+
Nicovideo.new(url, options)
|
24
26
|
else
|
25
27
|
raise 'unsupported url.'
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
def initialize(url)
|
31
|
+
def initialize(url, options)
|
30
32
|
raise 'do not instanciate directly, use WebRadio method.' if self.class == WebRadio
|
31
33
|
@url = url
|
34
|
+
@options = options
|
32
35
|
end
|
33
36
|
|
34
37
|
def download(name)
|
35
38
|
raise 'not implemented.'
|
36
39
|
end
|
37
40
|
|
38
|
-
def mp3ize
|
39
|
-
return
|
40
|
-
end
|
41
|
-
|
42
41
|
private
|
43
|
-
def
|
42
|
+
def mp3ize(src, dst, delete_src = true)
|
43
|
+
# download src file
|
44
|
+
if !File.exist?(src) && !File.exist?(dst)
|
45
|
+
print "getting #{src}..."
|
46
|
+
begin
|
47
|
+
yield
|
48
|
+
puts "done."
|
49
|
+
rescue DownloadError => e
|
50
|
+
puts "failed."
|
51
|
+
File.delete(src) if File.exist?(src)
|
52
|
+
$stderr.puts e.message
|
53
|
+
return
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# convert to mp3
|
58
|
+
return self unless @options.mp3
|
59
|
+
|
60
|
+
print "converting to mp3..."
|
44
61
|
if File.exist? dst
|
45
|
-
puts "
|
46
|
-
|
62
|
+
puts "skipped."
|
63
|
+
else
|
64
|
+
result = Open3.capture3("ffmpeg -i #{src} -ab 64k #{dst}")
|
65
|
+
if result[2].to_i == 0
|
66
|
+
File.delete(src) if delete_src
|
67
|
+
else
|
68
|
+
puts "failed."
|
69
|
+
$stderr.puts MediaConvertError.new(result[1])
|
70
|
+
end
|
47
71
|
end
|
48
|
-
result = Open3.capture3("ffmpeg -i #{src} -ab #{bitrate}k #{dst}")
|
49
|
-
$stderr.print result[1] unless result[2].to_i == 0
|
50
|
-
self
|
51
72
|
end
|
52
73
|
end
|
53
74
|
|
54
|
-
def WebRadio(url)
|
55
|
-
radio = WebRadio.instance(url)
|
75
|
+
def WebRadio(url, options)
|
76
|
+
radio = WebRadio.instance(url, options)
|
56
77
|
yield radio if block_given?
|
57
78
|
radio
|
58
79
|
end
|
data/rget.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "rget"
|
7
|
-
spec.version = "
|
7
|
+
spec.version = "2.0.0"
|
8
8
|
spec.authors = ["TADA Tadashi"]
|
9
9
|
spec.email = ["t@tdtds.jp"]
|
10
10
|
spec.description = %q{Downloading newest radio programs on the web. Supported radio stations are hibiki, animate, onsen, seaside communications and niconico.}
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_runtime_dependency "thor"
|
21
21
|
spec.add_runtime_dependency "nokogiri"
|
22
|
-
spec.add_runtime_dependency "niconico"
|
22
|
+
spec.add_runtime_dependency "niconico", ">= 1.7.0"
|
23
23
|
spec.add_runtime_dependency "pit"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TADA Tadashi
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.7.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.7.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pit
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|