soundcloud_streamer 0.0.1 → 0.0.2

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: d8df81a25b54abb3fdaefef7ff3fdbb1bd1d3d97
4
- data.tar.gz: cc6c03a8f59fd55986e72c568a0dcfd47a7c18ff
3
+ metadata.gz: 8d9f17867544bc5f60639e9e4adc21a431d09855
4
+ data.tar.gz: a14b1342c5fadc88c88adb2565e8ad438e26936e
5
5
  SHA512:
6
- metadata.gz: 16e3b86dd43ee665a2752793924cf4bf61218007f5a4d272669eb03c23c7572283b492a9066be6cefa67d1abc62cc5299f840a85d331f3dc3c89c4749f909873
7
- data.tar.gz: 6f335df7c52911361be0cf90f84e621fb2d0a6f4880076069e8f0239d912b6610db4db35391b9c0bfd7f1d1fd0b83373e9f895a4d2d919ccb95b017419d11a90
6
+ metadata.gz: 6865ecb3a4c13fd56b4c0eb5b289ce07d0856ab10c8a4fe9b902ac166f0c2841e87bd4c8169926a600b47dc5d479f00c0189d5f7e5d554e72d8f1ab67d941736
7
+ data.tar.gz: 9d8bafdb8a589913c36cf9eb01a45d68ed2dd12b9bbeb655fe40e09842a9dd6dd70c115e76d3f3dd2f8200148cee8cd8092b7cef726641dcd09c1ad36a27caa8
data/README.md CHANGED
@@ -18,13 +18,13 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- $ soundcloud_stream help
21
+ $ soundcloud_streamer help
22
22
 
23
- $ soundcloud_stream help playlist
23
+ $ soundcloud_streamer help playlist
24
24
 
25
25
  ### Example
26
26
 
27
- $ soundcloud_stream playlist https://soundcloud.com/mathew-steven-klein/sets/her-soundtrack --client-id=07b516960d652769d2a00c9a6a26f27d --target-dir="Her Soundtrack by Arcade Fire"
27
+ $ soundcloud_streamer playlist https://soundcloud.com/mathew-steven-klein/sets/her-soundtrack --client-id=07b516960d652769d2a00c9a6a26f27d --target-dir="Her Soundtrack by Arcade Fire"
28
28
 
29
29
  ## Contributing
30
30
 
@@ -3,9 +3,9 @@ module SoundcloudStreamer
3
3
  package_name "Soundcloud Streamer v#{SoundcloudStreamer::VERSION}"
4
4
 
5
5
  desc "playlist <URL>", "streams and saves all tracks from the playlist"
6
- method_options client_id: :string, target_dir: :string
6
+ method_options client_id: :string, target_dir: :string, overwrite: :boolean
7
7
  def playlist(url)
8
- response = playlist = client.get('/resolve', url: url)
8
+ response = playlist = client.get('/resolve', url: url, limit: 100)
9
9
 
10
10
  if response.kind == 'playlist'
11
11
  instant_print "Going to Stream all #{playlist.tracks.count} Tracks from Playlist ...\r\n"
@@ -14,17 +14,27 @@ module SoundcloudStreamer
14
14
  exit(-8)
15
15
  end
16
16
 
17
- track_num_justr = (playlist.tracks.count / 10.0).ceil
17
+ track_num_justr = playlist.tracks.count.to_s.length
18
18
  playlist.tracks.each_with_index do |track, track_idx|
19
19
  track_num = track_idx + 1
20
20
  track_num_str = track_num.to_s.rjust(track_num_justr, '0')
21
21
 
22
- uri = URI.parse(track.stream_url)
23
- uri.query = URI.encode_www_form(SoundCloud::Client::CLIENT_ID_PARAM_NAME => client_id)
22
+ unless track.streamable?
23
+ instant_print "Unstreamable-#{track_num}.\r\n"
24
+ next
25
+ end
24
26
 
25
27
  download_name = File.join(target_dir, [ track_num_str, ' ', track.title, '.mp3' ].join.gsub('/',' - ') )
26
28
  download_file = nil
27
29
 
30
+ if File.exist?(download_name) && !overwrite?
31
+ instant_print "Exisiting-#{track_num}.\r\n"
32
+ next
33
+ end
34
+
35
+ uri = URI.parse(track.stream_url)
36
+ uri.query = URI.encode_www_form(client_id: client_id)
37
+
28
38
  request = Typhoeus::Request.new(uri, followlocation: true)
29
39
  request.on_headers do |response|
30
40
  if response.code == 200
@@ -126,6 +136,10 @@ module SoundcloudStreamer
126
136
  target_dir
127
137
  end
128
138
 
139
+ def overwrite?
140
+ options[:overwrite] || false
141
+ end
142
+
129
143
  def instant_print(*params)
130
144
  print(*params) { STDOUT.flush }
131
145
  end
@@ -1,3 +1,3 @@
1
1
  module SoundcloudStreamer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soundcloud_streamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Nowak