rget 4.9.2 → 4.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +14 -0
- data/.devcontainer/devcontainer.json +30 -0
- data/bin/hls-dl +11 -96
- data/lib/hibiki.rb +1 -3
- data/lib/hls.rb +10 -28
- data/lib/onsen.rb +9 -25
- data/lib/webradio.rb +1 -1
- data/rget.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 222b83cd5f8c3cff4f1b3372ec7488cc2bc4643c66469be1259d123c54e53643
|
4
|
+
data.tar.gz: d2eda18075858e1e78fe0a862140161edfab2ad886075ba80e8b1a450f0ec617
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54d7bcead0ea3ddbb7a88afad7e7b95bde817c7272d0c2c4c567925bc41cc5ce35dff780624be93b92a49ec0e74ce9ac6cacf22f4c61c109543d73dc6d320728
|
7
|
+
data.tar.gz: f722aabcdaa8767d0fecaebedc400c26312ad44c5b8894f1cd3567c0eabbadee13aaeefbcc8a7211779b8427a386725e1a1406b788ae2c791183b2b07727e15a
|
@@ -0,0 +1,14 @@
|
|
1
|
+
FROM ruby:2
|
2
|
+
ENV USER vscode
|
3
|
+
LABEL maintainer "@tdtds <t@tdtds.jp>"
|
4
|
+
RUN apt-get -y update && apt-get -y install ffmpeg && \
|
5
|
+
curl -sLo /usr/local/bin/youtube-dl http://www.yt-dl.org/downloads/latest/youtube-dl && \
|
6
|
+
chmod +x /usr/local/bin/youtube-dl && \
|
7
|
+
useradd -u 1000 -m $USER && chsh -s /bin/bash $USER
|
8
|
+
USER $USER
|
9
|
+
RUN bundle config set path vendor/bundle && \
|
10
|
+
bundle config set with development:test && \
|
11
|
+
echo 'git config --global --unset core.editor' >> /home/$USER/.bashrc && \
|
12
|
+
echo 'git config --global --unset core.sshCommand' >> /home/$USER/.bashrc && \
|
13
|
+
echo 'git ls-remote -q > /dev/null' >> /home/$USER/.bashrc
|
14
|
+
CMD [ "sleep", "infinity" ]
|
@@ -0,0 +1,30 @@
|
|
1
|
+
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
|
2
|
+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.122.1/containers/docker-from-docker-compose
|
3
|
+
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
|
4
|
+
{
|
5
|
+
"name": "rget",
|
6
|
+
"context": "..",
|
7
|
+
"dockerFile": "Dockerfile",
|
8
|
+
|
9
|
+
// Set *default* container specific settings.json values on container create.
|
10
|
+
"settings": {
|
11
|
+
"terminal.integrated.shell.linux": "/bin/bash"
|
12
|
+
},
|
13
|
+
|
14
|
+
// Add the IDs of extensions you want installed when the container is created.
|
15
|
+
"extensions": [
|
16
|
+
"rebornix.ruby"
|
17
|
+
],
|
18
|
+
|
19
|
+
// Uncomment the next line if you want start specific services in your Docker Compose config.
|
20
|
+
// "runServices": [],
|
21
|
+
|
22
|
+
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
|
23
|
+
// "shutdownAction": "none",
|
24
|
+
|
25
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
26
|
+
// "postCreateCommand": "docker --version",
|
27
|
+
|
28
|
+
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
|
29
|
+
// "remoteUser": "vscode"
|
30
|
+
}
|
data/bin/hls-dl
CHANGED
@@ -1,103 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require "
|
3
|
-
require "mechanize"
|
4
|
-
require 'open-uri'
|
5
|
-
require 'thread'
|
2
|
+
require "open3"
|
6
3
|
|
7
4
|
if ARGV.size != 2
|
8
|
-
$stderr.puts "
|
9
|
-
$stderr.puts "hls-dl <playlist.m3u8> <output(.
|
5
|
+
$stderr.puts "HLS downloader wrapping ffmpeg"
|
6
|
+
$stderr.puts "hls-dl <playlist.m3u8> <output(.mp4,mp3,...)>"
|
10
7
|
exit 1
|
11
8
|
end
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
21
|
-
agent.get(m3u8)
|
22
|
-
body = agent.page.body
|
23
|
-
rescue ArgumentError
|
24
|
-
body = URI.open(m3u8, &:read)
|
25
|
-
end
|
26
|
-
tses = body.scan(/.*\.ts.*/)
|
27
|
-
key_url = body.scan(/URI="(.*)"/).flatten.first
|
28
|
-
|
29
|
-
if key_url
|
30
|
-
key = agent.get_file(key_url)
|
31
|
-
decoder = OpenSSL::Cipher.new('aes-128-cbc')
|
32
|
-
decoder.key = key
|
33
|
-
decoder.decrypt
|
34
|
-
else
|
35
|
-
decoder = ''
|
36
|
-
def decoder.update(s); return s; end
|
37
|
-
def decoder.final(); return ''; end
|
38
|
-
end
|
39
|
-
|
40
|
-
q = Queue.new
|
41
|
-
tses.each_with_index{|ts_url, block_no| q.push([ts_url, block_no])}
|
42
|
-
q.close
|
43
|
-
results = [nil] * q.size
|
44
|
-
|
45
|
-
msgs = Queue.new
|
46
|
-
stats = [0] * 3
|
47
|
-
stats.size.times do |thread_no|
|
48
|
-
Thread.start(thread_no) do |thread_no|
|
49
|
-
while (ts_url, block_no = q.pop)
|
50
|
-
begin
|
51
|
-
sleep(rand(0.1) * 3)
|
52
|
-
results[block_no] = agent.get_file(ts_url)
|
53
|
-
stats[thread_no] = block_no
|
54
|
-
rescue Mechanize::ResponseCodeError => e
|
55
|
-
case e.response_code
|
56
|
-
when "403" # Forbidden
|
57
|
-
msgs.push "T#{thread_no}: 403 Forbidden"
|
58
|
-
retry
|
59
|
-
when "429" # TooManyRequests
|
60
|
-
msgs.push "T#{thread_no}: 429 TooManyRequests"
|
61
|
-
retry
|
62
|
-
else
|
63
|
-
msgs.push "T#{thread_no}: #{e}"
|
64
|
-
retry # TODO: catch other status code
|
65
|
-
end
|
66
|
-
rescue
|
67
|
-
msgs.push "T#{thread_no}: #{e.class} #{e}"
|
68
|
-
break
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def print_status(block, tses, stats, msgs)
|
75
|
-
$stderr.puts msgs.pop while !msgs.empty?
|
76
|
-
$stderr.print "#{block+1}/#{tses.size} saved --"
|
77
|
-
stats.each_with_index{|block_no, thread_no| $stderr.print " T#{thread_no+1}:#{block_no+1}"}
|
78
|
-
$stderr.print "\r"
|
79
|
-
end
|
80
|
-
|
81
|
-
def save(fd, results, tses, stats, msgs, decoder)
|
82
|
-
results.each_with_index do |data, i|
|
83
|
-
print_status(i, tses, stats, msgs)
|
84
|
-
loop do
|
85
|
-
if data
|
86
|
-
fd.write(decoder.update(data))
|
87
|
-
results[i] = nil # be saved data want to GC
|
88
|
-
break
|
89
|
-
else
|
90
|
-
sleep(1.0) # wait for complete of chunk download finished
|
91
|
-
data = results[i]
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
fd.write(decoder.final)
|
96
|
-
puts
|
97
|
-
end
|
98
|
-
|
99
|
-
if ts_file
|
100
|
-
open(ts_file, 'wb:ASCII-8BIT'){|f|save(f, results, tses, stats, msgs, decoder)}
|
101
|
-
else
|
102
|
-
save($stdout, results, tses, stats, msgs, decoder)
|
10
|
+
ffmpeg = %Q[ffmpeg -loglevel error -protocol_whitelist file,http,https,tcp,tls,crypto -n -i "#{ARGV[0]}" #{ARGV[1]}]
|
11
|
+
result = Open3.capture3(ffmpeg)
|
12
|
+
unless result[2].to_i == 0
|
13
|
+
p result
|
14
|
+
File.delete(ARGV[1]) if File.exist?(ARGV[1])
|
15
|
+
$stderr.puts result[1]
|
16
|
+
exit(1)
|
103
17
|
end
|
18
|
+
exit(0)
|
data/lib/hibiki.rb
CHANGED
@@ -58,9 +58,7 @@ private
|
|
58
58
|
m3u8_url = URI(agent.get(playlist_url).body.scan(/http.*/).flatten.first)
|
59
59
|
|
60
60
|
# choice the max size element from multi-part m3u8 file
|
61
|
-
|
62
|
-
m3u8_sizes = m3u8s.map(&:size)
|
63
|
-
m3u8 = m3u8s[m3u8_sizes.index(m3u8_sizes.max)]
|
61
|
+
m3u8 = agent.get(m3u8_url).body.split("EXT-X-KEY").sort{|m,n|m.size <=> n.size}.last
|
64
62
|
|
65
63
|
key_url = m3u8.scan(/URI="(.*)"/).flatten.first
|
66
64
|
|
data/lib/hls.rb
CHANGED
@@ -1,35 +1,17 @@
|
|
1
1
|
require 'webradio'
|
2
|
+
require 'open3'
|
2
3
|
|
3
4
|
class HLS < WebRadio
|
4
5
|
private
|
5
|
-
def hls_download(name,
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
m3u_meta1 = URI.open(m3u_meta2, &:read)
|
15
|
-
m3u = m3u_meta1.scan(/^[^#].*/).first
|
16
|
-
save_m4a(URI(m3u), @m4a_file)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def get_m4a(uri_playlist)
|
21
|
-
URI.open(uri_playlist).each_line do |l|
|
22
|
-
next if /^#/ =~ l
|
23
|
-
l.chomp!
|
24
|
-
print "."
|
25
|
-
yield URI.open(uri_playlist + l, 'r:ASCII-8BIT', &:read)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def save_m4a(uri_playlist, m4a_file)
|
30
|
-
open(m4a_file, 'wb:ASCII-8BIT') do |m4a|
|
31
|
-
get_m4a(uri_playlist) do |part|
|
32
|
-
m4a.write part
|
6
|
+
def hls_download(name, serial, m3u_meta)
|
7
|
+
mp4_file = "#{name}##{serial}.mp4"
|
8
|
+
mp3_file = "#{name}##{serial}.mp3"
|
9
|
+
m3u = URI.open(m3u_meta, &:read).scan(/^[^#].*/).first
|
10
|
+
m3u = Pathname(m3u_meta).dirname.join(m3u) if Pathname(m3u).relative?
|
11
|
+
mp3nize(mp4_file, mp3_file) do
|
12
|
+
result = Open3.capture3(%Q[ffmpeg -loglevel error -protocol_whitelist file,http,https,tcp,tls,crypto -i "#{m3u}" "#{mp4_file}"])
|
13
|
+
unless result[2].to_i == 0
|
14
|
+
raise WebRadio::DownloadError.new("failed download the radio program (#{@label}).")
|
33
15
|
end
|
34
16
|
end
|
35
17
|
end
|
data/lib/onsen.rb
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'hls'
|
4
4
|
require 'nokogiri'
|
5
|
+
require 'json'
|
5
6
|
|
6
|
-
class Onsen <
|
7
|
+
class Onsen < HLS
|
7
8
|
def initialize(params, options)
|
8
9
|
super
|
9
|
-
@cover = "//*[@
|
10
|
+
@cover = "//*[@class='newest-content--left']//img[1]/@src" unless @cover
|
10
11
|
end
|
11
12
|
|
12
13
|
def download
|
13
|
-
|
14
|
+
html = URI.open(@url, &:read)
|
15
|
+
serial = Nokogiri(html).css('.play-video-info td')[0].text.scan(/\d+/)[0].to_i
|
16
|
+
m3u8 = JSON.parse(html.scan(%r|streaming_url:("https:.*?.m3u8")|).flatten.sort.last)
|
17
|
+
hls_download(@label, serial, m3u8)
|
14
18
|
end
|
15
19
|
|
16
20
|
def dump
|
17
21
|
tag = Pathname(@url).basename.to_s.gsub(%r|[-/]|, '_')
|
18
22
|
html = Nokogiri(URI.open(@url, &:read))
|
19
|
-
title = html.css('
|
23
|
+
title = html.css('h3')[0].text
|
20
24
|
return {
|
21
25
|
tag => {
|
22
26
|
'desc' => title,
|
@@ -25,24 +29,4 @@ class Onsen < WebRadio
|
|
25
29
|
}
|
26
30
|
}
|
27
31
|
end
|
28
|
-
|
29
|
-
private
|
30
|
-
def onsen_download(name, program_id)
|
31
|
-
html = Nokogiri(URI.open('http://onsen.ag/', 'User-Agent' => 'iPhone', &:read))
|
32
|
-
begin
|
33
|
-
serial = html.css("##{program_id}").text.scan(/#(\d+)/).flatten.first
|
34
|
-
mp3_url = html.css('form[target=_self]').select {|form|
|
35
|
-
form.attr('action') =~ %r|/#{program_id}\w+\.mp[34]|
|
36
|
-
}.first.attr('action')
|
37
|
-
rescue NoMethodError
|
38
|
-
raise NotFoundError.new("no radio program in #{program_id}.")
|
39
|
-
end
|
40
|
-
src_file = "#{name}##{serial}#{mp3_url.scan(/\.mp[34]$/).first}"
|
41
|
-
mp3_file = "#{name}##{serial}.mp3"
|
42
|
-
mp3nize(src_file, mp3_file, false) do
|
43
|
-
open(src_file, 'wb:ASCII-8BIT') do |mp3|
|
44
|
-
mp3.write URI.open(mp3_url, 'rb:ASCII-8BIT', &:read)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
32
|
end
|
data/lib/webradio.rb
CHANGED
@@ -14,7 +14,7 @@ class WebRadio
|
|
14
14
|
when %r[^https?://hibiki-radio\.jp/]
|
15
15
|
require 'hibiki'
|
16
16
|
Hibiki.new(params, options)
|
17
|
-
when %r[^
|
17
|
+
when %r[^https?://(www\.)?onsen\.ag/program/]
|
18
18
|
require 'onsen'
|
19
19
|
Onsen.new(params, options)
|
20
20
|
when %r[nicovideo\.jp]
|
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 = "4.9.
|
7
|
+
spec.version = "4.9.3"
|
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, onsen, niconico, freshlive, himalaya and asobi store.}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.9.
|
4
|
+
version: 4.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TADA Tadashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -161,6 +161,8 @@ executables:
|
|
161
161
|
extensions: []
|
162
162
|
extra_rdoc_files: []
|
163
163
|
files:
|
164
|
+
- ".devcontainer/Dockerfile"
|
165
|
+
- ".devcontainer/devcontainer.json"
|
164
166
|
- ".gitignore"
|
165
167
|
- ".travis.yml"
|
166
168
|
- Gemfile
|
@@ -201,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
203
|
- !ruby/object:Gem::Version
|
202
204
|
version: '0'
|
203
205
|
requirements: []
|
204
|
-
rubygems_version: 3.
|
206
|
+
rubygems_version: 3.0.8
|
205
207
|
signing_key:
|
206
208
|
specification_version: 4
|
207
209
|
summary: Downloading newest radio programs on the web.
|