soundcloud_downloader 0.1.0 → 0.1.1

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: 583a92d287b6ab514855671337e83b7bf5b1961b
4
- data.tar.gz: acca92e3fdf28abeb911e30519d5a4cb4eb3d438
3
+ metadata.gz: e463e0ae3702a0b02f3917b106c64354e42920f2
4
+ data.tar.gz: d65c7c79d922960c05a42b74a40f78ea5934f5f9
5
5
  SHA512:
6
- metadata.gz: 04f243309166576e7af0057eecb4e9bda372e2707ed9ac93cf9a4e207b196f4fcaac5521719a7737e8bc63e8f720909b00de18203ffe7f6ecf8dafe32c701f93
7
- data.tar.gz: 2bc3b860d01555ac5f2f34a45a5d43db6cc44426f8e639e68dbe723c5b7d8310c13337c5ba00b819d830a94c9569a03eb1c2b2a396578c4cc9e86d9f45a418d9
6
+ metadata.gz: 5e11d7757806c0018243f916b7f54e95429d1649c6f85ef53dd780bd08ac6d11a313234bd99046cb679297026e83554ad6b3bcbb7e923a89c7790fd5042cf9f8
7
+ data.tar.gz: b4f00c07ec43794ec3f03b3f7b5f1d206e68d4dc2034750af0d10b5d5e10a41e69f74ac5f79c0d5921afe3a23309cdfc1d61395be64412542ed5d6aeb2753a31
data/.gitignore CHANGED
@@ -1,23 +1,23 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
23
- *.mp3
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ *.mp3
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in scdownloader.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scdownloader.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2014 TODO: Write your name
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,24 +1,26 @@
1
- # SoundcloudDownloader
2
-
3
- SoundcloudDownloader is a tool used to download songs from SoundCloud to your computer as MP3.
4
-
5
- ## Installation
6
-
7
- $ gem install soundcloud_downloader
8
-
9
- ## Usage
10
-
11
- CLI:
12
-
13
- $ soundcloud-downloader URL
14
-
15
- In your own Ruby applications:
16
-
17
- require 'soundcloud_downloader'
18
-
19
- song = Song.new("https://soundcloud.com/example/example-song-name")
20
- song.id # => 123456
21
- song.stream_url # => https://soundcloud.hs.llnwd.net/Example.128.mp3?AWSAccessKeyId=Example&Expires=Example&Signature=Example%3D&e=Example&h=Example
22
- song.name # => example-song-name
23
- song.url # => https://soundcloud.com/example/example-song-name
24
- song.download # This will download the song as mp3
1
+ # SoundcloudDownloader
2
+
3
+ SoundcloudDownloader is a tool used to download songs from SoundCloud to your computer as MP3.
4
+
5
+ ## Installation
6
+
7
+ $ gem install soundcloud_downloader
8
+
9
+ ## Usage
10
+
11
+ CLI:
12
+
13
+ $ soundcloud-downloader <URL> [OPTIONS]
14
+ -O, --output-file [filename] Filename for the MP3, optional (Default: parse from URL)
15
+ -v, --version Show version
16
+
17
+ In your own Ruby applications:
18
+
19
+ require 'soundcloud_downloader'
20
+
21
+ song = Song.new("https://soundcloud.com/example/example-song-name")
22
+ song.id # => 123456
23
+ song.stream_url # => https://soundcloud.hs.llnwd.net/Example.128.mp3?AWSAccessKeyId=Example&Expires=Example&Signature=Example%3D&e=Example&h=Example
24
+ song.name # => example-song-name
25
+ song.url # => https://soundcloud.com/example/example-song-name
26
+ song.download(file, folder) # This will download the song as mp3 (File and folder arguments are optional)
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require "bundler/gem_tasks"
2
+
@@ -1,28 +1,27 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'soundcloud_downloader'
4
- require 'optparse'
5
-
6
- options = {}
7
- OptionParser.new do |opts|
8
- opts.banner = "Usage: soundcloud-downloader <URL> [OPTIONS]"
9
-
10
- opts.on("-o", "--out [filename]",
11
- "Filename for the MP3, optional") do |t|
12
- options[:filename] = t
13
- end
14
- opts.on("-f", "--folder [folder]",
15
- "Folder to save the MP3 to, optional") do |t|
16
- options[:folder] = t
17
- end
18
- opts.on_tail("-v", "--version", "Show version") do
19
- puts "Version: #{SoundcloudDownloader::VERSION}"
20
- exit
21
- end
22
-
23
- end.parse!
24
-
25
- url = ARGV[0]
26
-
27
- song = Song.new(url)
28
- song.download(options[:filename], options[:folder])
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'soundcloud_downloader'
4
+ require 'optparse'
5
+
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: soundcloud-downloader <URL> [OPTIONS]"
9
+
10
+ opts.on("-O", "--output-file [filename]",
11
+ "Filename for the MP3, optional (Default: parse from URL)") do |t|
12
+ options[:filename] = t
13
+ end
14
+ opts.on_tail("-v", "--version", "Show version") do
15
+ puts "Version: #{SoundcloudDownloader::VERSION}"
16
+ exit
17
+ end
18
+
19
+ end.parse!
20
+
21
+ url = ARGV[0]
22
+
23
+ song = Song.new(url)
24
+ dl_options = []
25
+ dl_options << options[:filename] unless options[:filename].nil?
26
+ dl_options << options[:folder] unless options[:folder].nil?
27
+ song.send('download', *dl_options)
@@ -1,51 +1,61 @@
1
1
  require "excon"
2
2
  require "json"
3
3
  require "uri"
4
+ require "mp3info"
4
5
 
5
6
  class Song
6
- attr_reader :id, :stream_url, :name, :url
7
+ attr_reader :metadata, :name, :url, :resolved_url
8
+
7
9
  def initialize(url)
8
10
  raise ArgumentError, "Invalid url" if url !~ URI::regexp
9
11
  @url = url
10
12
  @name = url.split("/").last
11
- @id ||= get_id
13
+ @resolved_url ||= resolve_url
14
+ @metadata ||= get_metadata
12
15
  @stream_url ||= get_stream_url
13
16
  end
14
17
 
15
- def download (file = "#{@name}.mp3", folder = "./")
16
- raise ArgumentError, "Invalid folder" if not File.directory?(folder)
17
- raise ArgumentError, "Cannot write to this folder" if not File.writable?(folder)
18
- raise ArgumentError, "File must have .mp3 extension" if File.extname(file) != ".mp3"
18
+ def download (filename = "#{@metadata['title']}.mp3")
19
+ file = File.open(filename, 'wb')
20
+
19
21
  streamer = lambda do |chunk, remaining_bytes, total_bytes|
20
22
  file.write(chunk)
21
23
  remaining = ((remaining_bytes.to_f / total_bytes) * 100).to_i
22
24
  STDOUT.flush
23
25
  print "\rRemaining: #{remaining}%"
24
26
  end
25
- path = File.join(folder,File.basename(file))
26
- file = open(path, 'wb')
27
+
27
28
  Excon.get(@stream_url, :response_block => streamer)
28
- puts "\r\nSaved to #{File.realpath(path)}!"
29
29
  file.close
30
+ puts "\r\nSaved to #{File.realpath(filename)}!"
31
+ Mp3Info.open(File.realpath(filename)) do |mp3|
32
+ mp3.tag.title = @metadata["title"]
33
+ end
34
+
30
35
  end
31
36
 
32
37
  private
33
38
 
34
39
  def get_stream_url
35
- response = Excon.get("https://api.sndcdn.com/i1/tracks/#{@id}/streams", :query => { :client_id => $client_id })
40
+ response = Excon.get("https://api.sndcdn.com/i1/tracks/#{@metadata['id']}/streams", :query => { :client_id => $client_id })
36
41
  JSON.parse(response.body)["http_mp3_128_url"]
37
42
  end
38
43
 
39
- def get_id
40
- response = Excon.get("https://api.sndcdn.com/resolve?_status_code_map%5B302%5D=200",
41
- :headers => { "Accept" => "application/json" },
44
+ def resolve_url
45
+ response = Excon.get("http://api.soundcloud.com/resolve.json",
42
46
  :query => {
43
47
  :url => @url,
44
- :_status_format => 'json',
45
48
  :client_id => $client_id
46
49
  })
47
- location = JSON.parse(response.body)["location"]
48
- uri = URI.parse(location).path.to_s
49
- uri.split('/').last
50
+ JSON.parse(response.body)["location"]
51
+ end
52
+
53
+ def get_metadata
54
+ response = Excon.get(@resolved_url,
55
+ :query => {
56
+ :client_id => $client_id
57
+ })
58
+ JSON.parse(response.body)
50
59
  end
60
+
51
61
  end
@@ -1,3 +1,3 @@
1
- module SoundcloudDownloader
2
- VERSION = "0.1.0"
3
- end
1
+ module SoundcloudDownloader
2
+ VERSION = "0.1.1"
3
+ end
@@ -1,9 +1,9 @@
1
- require "soundcloud_downloader/version"
2
- require "soundcloud_downloader/song"
3
-
4
- $client_id = "2de556d4242efcdb9efb51480a1e59e9"
5
-
6
- module SoundcloudDownloader
7
-
8
- end
9
-
1
+ require "soundcloud_downloader/version"
2
+ require "soundcloud_downloader/song"
3
+
4
+ $client_id = "2de556d4242efcdb9efb51480a1e59e9"
5
+
6
+ module SoundcloudDownloader
7
+
8
+ end
9
+
@@ -1,26 +1,27 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'soundcloud_downloader/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "soundcloud_downloader"
8
- spec.version = SoundcloudDownloader::VERSION
9
- spec.authors = ["Mico Piira"]
10
- spec.email = ["mico.piira@yahoo.com"]
11
- spec.summary = %q{SoundCloud downloader}
12
- spec.description = %q{Downloads songs from SoundCloud to your
13
- computer as MP3 files}
14
- spec.homepage = "https://gitlab.com/mixu/soundcloud-downloader"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_runtime_dependency 'excon', '~> 0.38.0'
23
- spec.add_runtime_dependency 'json', '~> 1.8.1'
24
- spec.add_development_dependency "bundler", "~> 1.6"
25
- spec.add_development_dependency "rake"
26
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soundcloud_downloader/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soundcloud_downloader"
8
+ spec.version = SoundcloudDownloader::VERSION
9
+ spec.authors = ["Mico Piira"]
10
+ spec.email = ["mico.piira@yahoo.com"]
11
+ spec.summary = %q{SoundCloud downloader}
12
+ spec.description = %q{Downloads songs from SoundCloud to your
13
+ computer as MP3 files}
14
+ spec.homepage = "https://gitlab.com/mixu/soundcloud-downloader"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency 'excon', '~> 0.38.0'
23
+ spec.add_runtime_dependency 'json', '~> 1.8.1'
24
+ spec.add_runtime_dependency 'ruby-mp3info', '~> 0.8.4'
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soundcloud_downloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-10 00:00:00.000000000 Z
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-mp3info
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.4
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
118
  version: '0'
105
119
  requirements: []
106
120
  rubyforge_project:
107
- rubygems_version: 2.2.2
121
+ rubygems_version: 2.4.1
108
122
  signing_key:
109
123
  specification_version: 4
110
124
  summary: SoundCloud downloader