soundcloud_streamer 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d8df81a25b54abb3fdaefef7ff3fdbb1bd1d3d97
4
+ data.tar.gz: cc6c03a8f59fd55986e72c568a0dcfd47a7c18ff
5
+ SHA512:
6
+ metadata.gz: 16e3b86dd43ee665a2752793924cf4bf61218007f5a4d272669eb03c23c7572283b492a9066be6cefa67d1abc62cc5299f840a85d331f3dc3c89c4749f909873
7
+ data.tar.gz: 6f335df7c52911361be0cf90f84e621fb2d0a6f4880076069e8f0239d912b6610db4db35391b9c0bfd7f1d1fd0b83373e9f895a4d2d919ccb95b017419d11a90
@@ -0,0 +1,24 @@
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
24
+ .ruby-*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soundcloud_streamer.gemspec
4
+ gemspec
@@ -0,0 +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.
@@ -0,0 +1,35 @@
1
+ # SoundcloudStreamer
2
+
3
+ streams and saves whole playlist and single tracks as mp3 from soundcloud via api.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'soundcloud_streamer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install soundcloud_streamer
18
+
19
+ ## Usage
20
+
21
+ $ soundcloud_stream help
22
+
23
+ $ soundcloud_stream help playlist
24
+
25
+ ### Example
26
+
27
+ $ soundcloud_stream playlist https://soundcloud.com/mathew-steven-klein/sets/her-soundtrack --client-id=07b516960d652769d2a00c9a6a26f27d --target-dir="Her Soundtrack by Arcade Fire"
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/soundcloud_streamer/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ begin
7
+ require 'soundcloud_streamer'
8
+ rescue LoadError
9
+ require 'rubygems'
10
+ require 'soundcloud_streamer'
11
+ end
12
+
13
+ SoundcloudStreamer::CLI.start(ARGV)
@@ -0,0 +1,13 @@
1
+ require "fileutils"
2
+ require "uri"
3
+
4
+ require "mp3info"
5
+ require "soundcloud"
6
+ require "thor"
7
+ require "typhoeus"
8
+
9
+ require "soundcloud_streamer/version"
10
+ require "soundcloud_streamer/cli"
11
+
12
+ module SoundcloudStreamer
13
+ end
@@ -0,0 +1,134 @@
1
+ module SoundcloudStreamer
2
+ class CLI < ::Thor
3
+ package_name "Soundcloud Streamer v#{SoundcloudStreamer::VERSION}"
4
+
5
+ desc "playlist <URL>", "streams and saves all tracks from the playlist"
6
+ method_options client_id: :string, target_dir: :string
7
+ def playlist(url)
8
+ response = playlist = client.get('/resolve', url: url)
9
+
10
+ if response.kind == 'playlist'
11
+ instant_print "Going to Stream all #{playlist.tracks.count} Tracks from Playlist ...\r\n"
12
+ else
13
+ puts "Isn't a playlist. It's a #{response.kind.inspect}"
14
+ exit(-8)
15
+ end
16
+
17
+ track_num_justr = (playlist.tracks.count / 10.0).ceil
18
+ playlist.tracks.each_with_index do |track, track_idx|
19
+ track_num = track_idx + 1
20
+ track_num_str = track_num.to_s.rjust(track_num_justr, '0')
21
+
22
+ uri = URI.parse(track.stream_url)
23
+ uri.query = URI.encode_www_form(SoundCloud::Client::CLIENT_ID_PARAM_NAME => client_id)
24
+
25
+ download_name = File.join(target_dir, [ track_num_str, ' ', track.title, '.mp3' ].join.gsub('/',' - ') )
26
+ download_file = nil
27
+
28
+ request = Typhoeus::Request.new(uri, followlocation: true)
29
+ request.on_headers do |response|
30
+ if response.code == 200
31
+ instant_print "Streaming-#{track_num}."
32
+ download_file = File.open(download_name, 'w+b')
33
+ else
34
+ raise "Request '#{uri.to_s}' failed"
35
+ end
36
+ end
37
+
38
+ request.on_body do |chunk|
39
+ download_file.write(chunk)
40
+ instant_print "."
41
+ end
42
+
43
+ request.on_complete do |response|
44
+ download_file.close
45
+
46
+ artwork_data = nil
47
+ artwork_url = track.artwork_url || playlist.artwork_url
48
+ if artwork_url
49
+ instant_print "Artwork."
50
+ response = Typhoeus.get(artwork_url, followlocation: true)
51
+ if response.code == 200
52
+ artwork_data = response.body
53
+ end
54
+ instant_print "."
55
+ end
56
+
57
+ instant_print "Tagging."
58
+ Mp3Info.open(download_file.path) do |mp3|
59
+ mp3.tag.title = track.title.to_s.strip
60
+ mp3.tag.artist = 'SoundCloud'
61
+ mp3.tag.album = playlist.title.to_s.strip
62
+ mp3.tag.year = $1 if track.created_at.to_s =~ /^(\d{4})/
63
+ mp3.tag.tracknum = track_num
64
+ mp3.tag.comments = [ "Streamed from SoundCloud", track.permalink_url ].join("\r\n")
65
+ instant_print "."
66
+
67
+ mp3.tag2.TCOP = track.license.to_s.strip
68
+ mp3.tag2.TPUB = track.user.username.to_s.strip
69
+ instant_print "."
70
+
71
+ if artwork_data
72
+ mime = File.extname(artwork_url) ? File.extname(artwork_url)[1..-1] : nil
73
+ mp3.tag2.add_picture(artwork_data, pic_type: 0, mime: mime, description: "Artwork")
74
+ instant_print "."
75
+ end
76
+ end
77
+
78
+ instant_print "ok\r\n"
79
+ end
80
+
81
+ request.run
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ def config_paths
88
+ [ Dir.home, Dir.getwd ].map { |directory| File.join(directory, '.soundcloud_streamer') }
89
+ end
90
+
91
+ def config
92
+ @config ||= begin
93
+ config = {}
94
+ config_paths.each do |config_path|
95
+ if File.file?(config_path) && File.readable?(config_path)
96
+ config_part = YAML.load( File.read(config_path) )
97
+ if config_part.is_a?(Hash)
98
+ config.merge!(config_part)
99
+ else
100
+ raise "invalid configuration in '#{config_path}'"
101
+ end
102
+ end
103
+ end
104
+ config
105
+ end
106
+ end
107
+
108
+ def client_id
109
+ @client_id ||= begin
110
+ options[:client_id] || config["client_id"]
111
+ end
112
+ end
113
+
114
+ def client
115
+ @client ||= begin
116
+ raise "no client_id given" if client_id.nil? || client_id.empty?
117
+ Soundcloud.new(client_id: client_id)
118
+ end
119
+ end
120
+
121
+ def target_dir
122
+ target_dir = options[:target_dir] || Dir.getwd
123
+ unless File.exist?(target_dir)
124
+ FileUtils.mkdir_p(target_dir)
125
+ end
126
+ target_dir
127
+ end
128
+
129
+ def instant_print(*params)
130
+ print(*params) { STDOUT.flush }
131
+ end
132
+
133
+ end
134
+ end
@@ -0,0 +1,3 @@
1
+ module SoundcloudStreamer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soundcloud_streamer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soundcloud_streamer"
8
+ spec.version = SoundcloudStreamer::VERSION
9
+ spec.authors = ["Michael Nowak"]
10
+ spec.email = ["thexsystem@gmail.com"]
11
+ spec.summary = %q{streams and saves whole playlist and single tracks as mp3 from soundcloud via api.}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/mmichaa/#{spec.name}"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+
26
+ spec.add_development_dependency "pry", "~> 0.10"
27
+
28
+ spec.add_runtime_dependency "ruby-mp3info", "~> 0.8"
29
+ spec.add_runtime_dependency "soundcloud", "~> 0.3"
30
+ spec.add_runtime_dependency "typhoeus", "~> 0.6"
31
+ spec.add_runtime_dependency "thor", "~> 0.19"
32
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soundcloud_streamer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Nowak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-mp3info
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: soundcloud
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: typhoeus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.6'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.19'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.19'
111
+ description: streams and saves whole playlist and single tracks as mp3 from soundcloud
112
+ via api.
113
+ email:
114
+ - thexsystem@gmail.com
115
+ executables:
116
+ - soundcloud_streamer
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/soundcloud_streamer
126
+ - lib/soundcloud_streamer.rb
127
+ - lib/soundcloud_streamer/cli.rb
128
+ - lib/soundcloud_streamer/version.rb
129
+ - soundcloud_streamer.gemspec
130
+ homepage: https://github.com/mmichaa/soundcloud_streamer
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 1.9.3
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.4.1
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: streams and saves whole playlist and single tracks as mp3 from soundcloud
154
+ via api.
155
+ test_files: []