kgmusic 0.1.0pre20160509 → 0.1.0pre20160513
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kgmusic/basemod.rb +54 -1
- data/lib/kgmusic/version.rb +1 -1
- data/lib/kgmusic.rb +12 -69
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dff9fbe5070d1a37e25827f4bfa52fd5c28c183f
|
4
|
+
data.tar.gz: 5568456eed54334f98b9dab45ee5da8ee93067a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4b2084a705b3f4c65d9c76cb4f7c471e2c312a1a74e2486b91707c3845b2c6ba1d8418ab5a253f67f4f685fb1f5ee3fe591074b8beb12472b0840d184027608
|
7
|
+
data.tar.gz: 4bf0d0b2131b16d11e41fbd91e03f62f190f593cabfeb8632c082a08fe2cfa7a4f38ad48026f711e806e76acdc1131fbc629c85559e3d7544734d90ec04025d7
|
data/lib/kgmusic/basemod.rb
CHANGED
@@ -61,7 +61,60 @@ module KgMusic
|
|
61
61
|
|
62
62
|
def get_content_length __uri
|
63
63
|
response = __head_request __uri
|
64
|
-
|
64
|
+
response['content-length'].to_i
|
65
|
+
end
|
66
|
+
|
67
|
+
def obtain_final_url __uri
|
68
|
+
uri = uri_parse __uri
|
69
|
+
response = Net::HTTP.start(uri.host) do |http|
|
70
|
+
http.request_get(uri.path)
|
71
|
+
end
|
72
|
+
response['location'] || __uri
|
73
|
+
end
|
74
|
+
|
75
|
+
def download_proc(url, outfile)
|
76
|
+
|
77
|
+
uri = uri_parse url
|
78
|
+
content_length = get_content_length url
|
79
|
+
counter = 0
|
80
|
+
|
81
|
+
unless File.exist? outfile
|
82
|
+
Net::HTTP.start(uri.host) do |http|
|
83
|
+
@progress_bar = ProgressBar.new("Progress", content_length)
|
84
|
+
File.open(outfile, 'w') do |f|
|
85
|
+
http.read_timeout = 5
|
86
|
+
http.request_get(uri.path) do |response|
|
87
|
+
response.read_body do |body|
|
88
|
+
f.write body
|
89
|
+
counter += body.length
|
90
|
+
@progress_bar.set counter
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
@progress_bar.finish
|
96
|
+
else
|
97
|
+
Net::HTTP.start(uri.host) do |http|
|
98
|
+
partial_size = File.size(outfile)
|
99
|
+
__range = [partial_size, content_length]
|
100
|
+
__headers = {"Range" => "bytes=#{__range.first}-#{__range.last}"}
|
101
|
+
@progress_bar = ProgressBar.new("Progress", content_length)
|
102
|
+
counter += partial_size
|
103
|
+
while content_length > File.size(outfile) do
|
104
|
+
File.open(outfile, 'a') do |f|
|
105
|
+
http.read_timeout = 5
|
106
|
+
http.request_get(uri.path, __headers) do |response|
|
107
|
+
response.read_body do |body|
|
108
|
+
f.write body
|
109
|
+
counter += body.length
|
110
|
+
@progress_bar.set counter
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
@progress_bar.finish
|
65
118
|
end
|
66
119
|
end
|
67
120
|
end
|
data/lib/kgmusic/version.rb
CHANGED
data/lib/kgmusic.rb
CHANGED
@@ -10,13 +10,14 @@ module KgMusic
|
|
10
10
|
attr_reader :artist, :album
|
11
11
|
attr_reader :doc, :info, :result, :download_page, :direct_link
|
12
12
|
|
13
|
-
def initialize
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
def initialize args
|
14
|
+
keys = [:artist, :album]
|
15
|
+
keys.each do |k|
|
16
|
+
if args[k].is_a? String
|
17
|
+
self.instance_variable_set "@#{k}", validate(args[k])
|
18
|
+
else
|
19
|
+
raise ArgumentError
|
18
20
|
end
|
19
|
-
rescue
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
@@ -56,69 +57,15 @@ module KgMusic
|
|
56
57
|
@direct_link = link.to_s
|
57
58
|
end
|
58
59
|
|
59
|
-
def
|
60
|
+
def get_album
|
61
|
+
url = obtain_final_url @direct_link
|
62
|
+
outfile = File.join(ENV['HOME'], "#{@artist} - #{@album}.zip")
|
60
63
|
begin
|
61
|
-
|
62
|
-
response = Net::HTTP.start(uri.host) { |http| http.request_get(uri.path) }
|
63
|
-
@final_uri = response['location']
|
64
|
+
download_proc url, outfile
|
64
65
|
rescue
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
def get_album
|
69
|
-
|
70
|
-
result = obtain_final_url
|
71
|
-
uri = uri_parse result
|
72
|
-
host, path = uri.host, uri.path
|
73
|
-
@outfile = File.join(ENV['HOME'], "#{@artist} - #{@album}.zip")
|
74
|
-
|
75
|
-
counter = 0
|
76
|
-
|
77
|
-
unless File.exist? @outfile
|
78
|
-
Net::HTTP.start(host) do |http|
|
79
|
-
get_content_length @final_uri
|
80
|
-
@progress_bar = ProgressBar.new("Progress", @content_length)
|
81
|
-
File.open(@outfile, 'w') do |f|
|
82
|
-
http.read_timeout = 3
|
83
|
-
http.request_get(path) do |response|
|
84
|
-
response.read_body do |body|
|
85
|
-
f.write body
|
86
|
-
counter += body.length
|
87
|
-
@progress_bar.set counter
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
@progress_bar.finish
|
93
|
-
puts "Ok, Done."
|
94
|
-
else
|
95
|
-
Net::HTTP.start(host) do |http|
|
96
|
-
get_content_length @final_uri
|
97
|
-
@progress_bar = ProgressBar.new("Progress", @content_length)
|
98
|
-
fsize = File.size @outfile
|
99
|
-
counter += fsize
|
100
|
-
@progress_bar.set counter
|
101
|
-
while @content_length > File.size(@outfile) do
|
102
|
-
File.open(@outfile, 'a+') do |f|
|
103
|
-
partial_size = File.size(@outfile)
|
104
|
-
__range = Range.new(partial_size, @content_length)
|
105
|
-
__headers = {"Range" => "bytes=#{__range.first}-#{__range.last}"}
|
106
|
-
http.read_timeout = 3
|
107
|
-
http.request_get(path, __headers) do |response|
|
108
|
-
response.read_body do |body|
|
109
|
-
f.write body
|
110
|
-
counter += body.length
|
111
|
-
@progress_bar.set counter
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
@progress_bar.finish
|
118
|
-
puts "Ok, Done."
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
69
|
public
|
123
70
|
|
124
71
|
def search
|
@@ -126,11 +73,7 @@ module KgMusic
|
|
126
73
|
end
|
127
74
|
|
128
75
|
def download_album
|
129
|
-
|
130
|
-
get_album
|
131
|
-
rescue => e
|
132
|
-
puts e.message
|
133
|
-
end
|
76
|
+
get_album
|
134
77
|
end
|
135
78
|
end
|
136
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kgmusic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.0pre20160513
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vitvegl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|