rget 4.7.6 → 4.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ulizadl +63 -5
  3. data/rget.gemspec +2 -2
  4. metadata +7 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0fd38e56606b4cab53195c0fdfbc513bb9c111059a8f2d4b8901635f05fd4ef
4
- data.tar.gz: 91557b05c0841059bbacf5293a8ca7adb63bae5a384c27094e5564e5615aceec
3
+ metadata.gz: 67ae7e0feff45509f86be682672f93b2bc85458e686cf3f77b188549daf7447f
4
+ data.tar.gz: 5b63864b67d2c93337f4b48d5a253295b1d72ea3863c03216ee315d9e66916e6
5
5
  SHA512:
6
- metadata.gz: bf5b31cbea8c7f77224820fb345f344e0573c4758db41756908d295b8f627c19b51faacb51bac08fee3ba233fea239758d408d2a879613061c2c0e94aa821ca9
7
- data.tar.gz: 2ae8d69829a71ada3b512ea861ce3ba2156e1dfe038c9474cbe3736c57b44a6937276611f5766118395a39f5820246af0e7e1ed47d37cc90b2255ba472d6667c
6
+ metadata.gz: 1e3009d6cbe8c14cc0d6cd42fdfa62077b4be96ee17825df1a8e65f0a4d3cc08610151ec6b37a0b25bbd0c4b88b4fc9c79b7ffdfb70c5da0be7c3861b3d16fd1
7
+ data.tar.gz: 558ecd9a332a374f03f3092dea3499ef69516da359662b1c1f912af7f3fffd1122772f965000c9af962a1dd244c87d90d2606c8a931935932001c2ff5d4fe72c
data/bin/ulizadl CHANGED
@@ -2,6 +2,7 @@
2
2
  require "uri"
3
3
  require "mechanize"
4
4
  require 'open-uri'
5
+ require 'thread'
5
6
 
6
7
  if ARGV.size != 2
7
8
  $stderr.puts "download TS file decoded by Uliza style video streaming"
@@ -11,6 +12,7 @@ end
11
12
 
12
13
  m3u8 = ARGV.shift
13
14
  ts_file = "#{ARGV.shift}.ts"
15
+ ts_file = nil if File.basename(ts_file) == "-.ts"
14
16
 
15
17
  begin
16
18
  agent = Mechanize.new
@@ -35,11 +37,67 @@ else
35
37
  def decoder.final(); return ''; end
36
38
  end
37
39
 
38
- open(ts_file, 'wb:ASCII-8BIT') do |ts|
39
- tses.each_with_index do |file, count|
40
- print "#{count+1}/#{tses.size}\r"
41
- ts.write(decoder.update(agent.get_file(file)))
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
42
71
  end
43
- ts.write(decoder.final)
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)
44
96
  puts
45
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)
103
+ 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 = "4.7.6"
7
+ spec.version = "4.7.7"
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.}
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency "dropbox_api"
25
25
  spec.add_runtime_dependency "mp3info"
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "bundler"
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency "pry"
30
30
  spec.add_development_dependency "travis"
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.7.6
4
+ version: 4.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - TADA Tadashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '1.3'
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '1.3'
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -203,8 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  - !ruby/object:Gem::Version
204
204
  version: '0'
205
205
  requirements: []
206
- rubyforge_project:
207
- rubygems_version: 2.7.8
206
+ rubygems_version: 3.0.1
208
207
  signing_key:
209
208
  specification_version: 4
210
209
  summary: Downloading newest radio programs on the web.