soundcloud_downloader 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 403aac9fbf02561bb958961072cacb81a53fb4ef
|
4
|
+
data.tar.gz: f3f9f1934aaeda1aa976cab3ded5e426e62cf84f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab4e2b3fbfb811bc309de2cf4e6655d2b4bfbb5e5cba771785474e28eba651192f22b7e88bf9dc0969dd57a006e99d1c2275c6616486e7bbf3c7d2eec67fbd88
|
7
|
+
data.tar.gz: ad0ac25262649e7f12aa23b898595752de0d39bc97b60e1d7722d18734afd6838dc9b0660bf8e76460515ff77841cebe5850e642ef78836764d26cf38884c2fa
|
@@ -1,8 +1,11 @@
|
|
1
|
-
require "
|
1
|
+
require "excon"
|
2
|
+
require "json"
|
3
|
+
require "uri"
|
2
4
|
|
3
5
|
class Song
|
4
6
|
attr_reader :id, :stream_url, :name, :url
|
5
7
|
def initialize(url)
|
8
|
+
raise ArgumentError, "Invalid url" if url !~ URI::regexp
|
6
9
|
@url = url
|
7
10
|
@name = url.split("/").last
|
8
11
|
@id ||= get_id
|
@@ -10,42 +13,35 @@ class Song
|
|
10
13
|
end
|
11
14
|
|
12
15
|
def download (file = "#{@name}.mp3")
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
downloaded = 0
|
19
|
-
total_length = response['Content-Length'].to_f
|
20
|
-
response.read_body do |segment|
|
21
|
-
downloaded += (segment.length).to_f
|
22
|
-
print "\rDownloaded " + (((downloaded/total_length)*100).to_i).to_s + "%"
|
23
|
-
STDOUT.flush
|
24
|
-
file.write(segment)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
ensure
|
28
|
-
file.close
|
29
|
-
end
|
16
|
+
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
17
|
+
file.write(chunk)
|
18
|
+
remaining = ((remaining_bytes.to_f / total_bytes) * 100).to_i
|
19
|
+
STDOUT.flush
|
20
|
+
print "\rRemaining: #{remaining}%"
|
30
21
|
end
|
22
|
+
file = open("#{file}", 'wb')
|
23
|
+
Excon.get(@stream_url, :response_block => streamer)
|
24
|
+
puts "\r\nComplete!"
|
25
|
+
file.close
|
31
26
|
end
|
32
27
|
|
33
28
|
private
|
34
29
|
|
35
30
|
def get_stream_url
|
36
|
-
response =
|
37
|
-
response.body["http_mp3_128_url"]
|
31
|
+
response = Excon.get("https://api.sndcdn.com/i1/tracks/#{@id}/streams", :query => { :client_id => $client_id })
|
32
|
+
JSON.parse(response.body)["http_mp3_128_url"]
|
38
33
|
end
|
39
34
|
|
40
35
|
def get_id
|
41
|
-
response =
|
42
|
-
headers
|
43
|
-
|
36
|
+
response = Excon.get("https://api.sndcdn.com/resolve?_status_code_map%5B302%5D=200",
|
37
|
+
:headers => { "Accept" => "application/json" },
|
38
|
+
:query => {
|
44
39
|
:url => @url,
|
45
40
|
:_status_format => 'json',
|
46
41
|
:client_id => $client_id
|
47
|
-
}
|
48
|
-
|
42
|
+
})
|
43
|
+
location = JSON.parse(response.body)["location"]
|
44
|
+
uri = URI.parse(location).path.to_s
|
49
45
|
uri.split('/').last
|
50
46
|
end
|
51
47
|
end
|
@@ -19,7 +19,8 @@ computer as MP3 files}
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_runtime_dependency "
|
22
|
+
spec.add_runtime_dependency "excon"
|
23
|
+
spec.add_runtime_dependency "json"
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
25
|
spec.add_development_dependency "rake"
|
25
26
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soundcloud_downloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mico Piira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: excon
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,7 +70,7 @@ description: "Downloads songs from SoundCloud to your \ncomputer as MP3 files"
|
|
56
70
|
email:
|
57
71
|
- mico.piira@yahoo.com
|
58
72
|
executables:
|
59
|
-
-
|
73
|
+
- soundcloud-downloader
|
60
74
|
extensions: []
|
61
75
|
extra_rdoc_files: []
|
62
76
|
files:
|
@@ -65,7 +79,7 @@ files:
|
|
65
79
|
- LICENSE.txt
|
66
80
|
- README.md
|
67
81
|
- Rakefile
|
68
|
-
- bin/
|
82
|
+
- bin/soundcloud-downloader
|
69
83
|
- lib/soundcloud_downloader.rb
|
70
84
|
- lib/soundcloud_downloader/song.rb
|
71
85
|
- lib/soundcloud_downloader/version.rb
|