drum 0.2.0 → 0.2.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
  SHA256:
3
- metadata.gz: 744d7de8c05fe7f7dc8f843b04b2ccd1a77a2688228369706fa4fca79ddf6c07
4
- data.tar.gz: c72fc4a18d59cb12017692e1a6fad3cb73cbec24ea73a64adf68279331c3eafb
3
+ metadata.gz: c57a5a57b0b2a67b669af5f6880f8f8811ba396847918e7c2a05a2a14cc80728
4
+ data.tar.gz: a82247076c0d3065cf851bb05ac2f2785c5e70b460b6d3411176be4b2eb233c8
5
5
  SHA512:
6
- metadata.gz: 9cd77d6cf666ef8cd90709b357b59994da0eb20f2a7afaea68f5a60c3aae909d4acf49b407426dd21af4e56caf542e2906dabae73e9270e8221272d543a02e5a
7
- data.tar.gz: 488848553a20609b7f72bbd11431c46ba03e8d20db4ad428cca5d34df434a061a1ae55a668ee3a304836f42eb84ba5af84bf84e3a5ab0168271f1b86fd3e8f71
6
+ metadata.gz: 82c97fae35962275b4d9f38daaece537c8ef4a66ae5101396294f98d43371473b76d522f0798979dc16dcf9312e516881c1ec06d75bc515c07bea739cdeca94b
7
+ data.tar.gz: cc88ce5d6624f2ff2c12b2dd7dcc8b46701bc9ddfa9da21a453c39a733b438288071ccd3d7b698c30a226045422d154b9ef2bb8f3b366dbd5d5e7f3a747ffebf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- drum (0.2.0)
4
+ drum (0.2.2)
5
5
  highline (~> 2.0)
6
6
  jwt (~> 2.2)
7
7
  launchy (~> 2.4)
data/README.md CHANGED
@@ -29,7 +29,8 @@ The basic usage pattern is always `drum cp [source] [destination]` where `source
29
29
  * `@stdout`
30
30
  * A dash `-`, synonymous with `@stdin` and `@stdout`, depending on usage
31
31
 
32
- > Note that if the source is folder-like, i.e. includes multiple playlists, the destination has to be folder-like too. (The reverse is not true though.)
32
+ > [!NOTE]
33
+ > If the source is folder-like, i.e. includes multiple playlists, the destination has to be folder-like too. (The reverse is not true though.)
33
34
 
34
35
  ### Examples
35
36
 
@@ -59,7 +60,8 @@ Currently, the following music services are supported:
59
60
  * Apple Music
60
61
  * Local, YAML-based playlists (via stdio or files)
61
62
 
62
- > Note that the tool only processes metadata, not the actual audio files.
63
+ > [!NOTE]
64
+ > The tool only processes metadata, not the actual audio files.
63
65
 
64
66
  ## Development
65
67
 
@@ -67,11 +69,13 @@ After checking out the repo, run `bin/setup` (or `bundle install`) to install de
67
69
 
68
70
  To run the application, run `bundle exec bin/drum`. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
69
71
 
70
- > Note that you may need to run `bundle exec ruby bin/drum` on Windows
72
+ > [!IMPORTANT]
73
+ > You may need to run `bundle exec ruby bin/drum` on Windows
71
74
 
72
75
  To package the application into a gem, run `bundle exec rake build`. The built gem should then be located in `pkg`.
73
76
 
74
- > Note: If you wish to install `drum` using `gem install`, you may need to install additional gems such as `rb-scpt` on macOS to use platform-specific integrations. See [the `Gemfile`](Gemfile) for more information.
77
+ > [!IMPORTANT]
78
+ > If you wish to install `drum` using `gem install`, you may need to install additional gems such as `rb-scpt` on macOS to use platform-specific integrations. See [the `Gemfile`](Gemfile) for more information.
75
79
 
76
80
  To install the gem, run `bundle exec rake install`.
77
81
 
@@ -79,6 +83,9 @@ To generate the documentation, run `bundle exec rake yard`.
79
83
 
80
84
  To run tests, run `bundle exec rake spec`.
81
85
 
86
+ > [!TIP]
87
+ > If you wish to use a language server such as Solargraph and code completion isn't working for required gems, you may have to run `yard gems`: https://solargraph.org/guides/troubleshooting
88
+
82
89
  ### Spotify
83
90
 
84
91
  To use the service integration with Spotify, set the following environment variables:
@@ -167,8 +167,6 @@ module Drum
167
167
  server.shutdown
168
168
  end
169
169
 
170
- trap 'INT' do server.shutdown end
171
-
172
170
  log.info "Launching callback HTTP server on port #{port}, waiting for auth code..."
173
171
  server.start
174
172
 
@@ -186,6 +184,8 @@ module Drum
186
184
  }
187
185
 
188
186
  user_token
187
+ ensure
188
+ server&.shutdown
189
189
  end
190
190
 
191
191
  def authenticate
@@ -137,8 +137,6 @@ module Drum
137
137
  authorize_url = "https://accounts.spotify.com/authorize?client_id=#{client_id}&response_type=code&redirect_uri=http%3A%2F%2Flocalhost:#{port}%2Fcallback&scope=#{scopes.join('%20')}&state=#{csrf_state}"
138
138
  Launchy.open(authorize_url)
139
139
 
140
- trap 'INT' do server.shutdown end
141
-
142
140
  log.info "Launching callback HTTP server on port #{port}, waiting for auth code..."
143
141
  server.start
144
142
 
@@ -155,6 +153,8 @@ module Drum
155
153
  })
156
154
 
157
155
  self.consume_authentication_response(auth_response)
156
+ ensure
157
+ server&.shutdown
158
158
  end
159
159
 
160
160
  def authenticate_user_via_refresh(client_id, client_secret, refresh_token)
@@ -241,30 +241,30 @@ module Drum
241
241
  # Download helpers
242
242
 
243
243
  def all_sp_library_playlists(offset: 0)
244
- sp_playlists = @me.playlists(limit: PLAYLISTS_CHUNK_SIZE, offset: offset)
245
- unless sp_playlists.empty?
246
- sp_playlists + self.all_sp_library_playlists(offset: offset + PLAYLISTS_CHUNK_SIZE)
247
- else
248
- []
244
+ all_sp_playlists = []
245
+ while !(sp_playlists = @me.playlists(limit: PLAYLISTS_CHUNK_SIZE, offset: offset)).empty?
246
+ offset += PLAYLISTS_CHUNK_SIZE
247
+ all_sp_playlists += sp_playlists
249
248
  end
249
+ all_sp_playlists
250
250
  end
251
251
 
252
252
  def all_sp_playlist_tracks(sp_playlist, offset: 0)
253
- sp_tracks = sp_playlist.tracks(limit: TRACKS_CHUNK_SIZE, offset: offset)
254
- unless sp_tracks.empty?
255
- sp_tracks + self.all_sp_playlist_tracks(sp_playlist, offset: offset + TRACKS_CHUNK_SIZE)
256
- else
257
- []
253
+ all_sp_tracks = []
254
+ while !(sp_tracks = sp_playlist.tracks(limit: TRACKS_CHUNK_SIZE, offset: offset)).empty?
255
+ offset += TRACKS_CHUNK_SIZE
256
+ all_sp_tracks += sp_tracks
258
257
  end
258
+ all_sp_tracks
259
259
  end
260
260
 
261
261
  def all_sp_library_tracks(offset: 0)
262
- sp_tracks = @me.saved_tracks(limit: SAVED_TRACKS_CHUNKS_SIZE, offset: offset)
263
- unless sp_tracks.empty?
264
- sp_tracks + self.all_sp_library_tracks(offset: offset + SAVED_TRACKS_CHUNKS_SIZE)
265
- else
266
- []
262
+ all_sp_tracks = []
263
+ while !(sp_tracks = @me.saved_tracks(limit: SAVED_TRACKS_CHUNKS_SIZE, offset: offset)).empty?
264
+ offset += SAVED_TRACKS_CHUNKS_SIZE
265
+ all_sp_tracks += sp_tracks
267
266
  end
267
+ all_sp_tracks
268
268
  end
269
269
 
270
270
  def extract_sp_features(sp_track)
@@ -555,11 +555,22 @@ module Drum
555
555
  log.info 'Fetching playlists...'
556
556
  Enumerator.new(sp_playlists.length) do |enum|
557
557
  sp_playlists.each do |sp_playlist|
558
- begin
559
- new_playlist = self.from_sp_playlist(sp_playlist)
560
- enum.yield new_playlist
561
- rescue StandardError => e
562
- log.info "Could not download playlist '#{sp_playlist.name}': #{e}"
558
+ 3.times do |attempt|
559
+ begin
560
+ if attempt > 0
561
+ log.info "Attempt \##{attempt + 1} to download '#{sp_playlist.name}'..."
562
+ end
563
+ new_playlist = self.from_sp_playlist(sp_playlist)
564
+ enum.yield new_playlist
565
+ break
566
+ rescue RestClient::TooManyRequests => e
567
+ seconds = e.response.headers[:retry_after]&.to_f || 0.5
568
+ log.info "Got 429 Too Many Requests while downloading '#{sp_playlist.name}', retrying in #{seconds} seconds..."
569
+ sleep seconds
570
+ rescue StandardError => e
571
+ log.info "Could not download playlist '#{sp_playlist.name}': #{e}"
572
+ break
573
+ end
563
574
  end
564
575
  end
565
576
  end
data/lib/drum/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Drum
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - fwcd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-19 00:00:00.000000000 Z
11
+ date: 2024-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor