drum 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/drum/service/spotify.rb +25 -3
- data/lib/drum/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1cf895018608f7c8ecbf68a5f243228d1569af86b9015c0f178b13f6614cd7c
|
4
|
+
data.tar.gz: f52ba7d7d00e81cd8f3f3a1793d637def247beb9c88a58d167d64e9c890ab841
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c24724da7a46dc623202cef18dc779f9c5fa98d0f34491da5a4445927ee47cf7b0dda2f0372c9ed0d26a6a3a4ec13cfb9f515227009ffb0239d6bb751908038
|
7
|
+
data.tar.gz: 806e30e6353f897cd3f163f663769913ccb33f9f5df7b1f629cf97b5258cf3f682b9bbc185906785b570d8f97e9930b74fa837d5fd1a5cc019336e42d5708528
|
data/Gemfile.lock
CHANGED
data/lib/drum/service/spotify.rb
CHANGED
@@ -31,6 +31,8 @@ module Drum
|
|
31
31
|
TO_SPOTIFY_TRACKS_CHUNK_SIZE = 50
|
32
32
|
UPLOAD_PLAYLIST_TRACKS_CHUNK_SIZE = 100
|
33
33
|
|
34
|
+
MAX_PLAYLIST_TRACKS = 10_000
|
35
|
+
|
34
36
|
CLIENT_ID_VAR = 'SPOTIFY_CLIENT_ID'
|
35
37
|
CLIENT_SECRET_VAR = 'SPOTIFY_CLIENT_SECRET'
|
36
38
|
|
@@ -254,6 +256,13 @@ module Drum
|
|
254
256
|
while !(sp_tracks = sp_playlist.tracks(limit: TRACKS_CHUNK_SIZE, offset: offset)).empty?
|
255
257
|
offset += TRACKS_CHUNK_SIZE
|
256
258
|
all_sp_tracks += sp_tracks
|
259
|
+
if offset > sp_playlist.total + TRACKS_CHUNK_SIZE
|
260
|
+
log.warn "Truncating playlist '#{sp_playlist.name}' at #{offset}, which strangely seems to yield more tracks than its length of #{sp_playlist.total} would suggest."
|
261
|
+
break
|
262
|
+
elsif offset > MAX_PLAYLIST_TRACKS
|
263
|
+
log.warn "Truncating playlist '#{sp_playlist.name}' at #{offset}, since it exceeds the maximum of #{MAX_PLAYLIST_TRACKS} tracks."
|
264
|
+
break
|
265
|
+
end
|
257
266
|
end
|
258
267
|
all_sp_tracks
|
259
268
|
end
|
@@ -555,6 +564,14 @@ module Drum
|
|
555
564
|
log.info 'Fetching playlists...'
|
556
565
|
Enumerator.new(sp_playlists.length) do |enum|
|
557
566
|
sp_playlists.each do |sp_playlist|
|
567
|
+
# These playlists seem to cause trouble for some reason, by either
|
568
|
+
# 404ing or by returning seemingly endless amounts of tracks, so
|
569
|
+
# we'll ignore them for now...
|
570
|
+
if sp_playlist.name.start_with?('Your Top Songs')
|
571
|
+
log.info "Skipping '#{sp_playlist.name}'"
|
572
|
+
next
|
573
|
+
end
|
574
|
+
|
558
575
|
3.times do |attempt|
|
559
576
|
begin
|
560
577
|
if attempt > 0
|
@@ -565,10 +582,15 @@ module Drum
|
|
565
582
|
break
|
566
583
|
rescue RestClient::TooManyRequests => e
|
567
584
|
seconds = e.response.headers[:retry_after]&.to_f || 0.5
|
568
|
-
|
569
|
-
|
585
|
+
if seconds <= 300
|
586
|
+
log.warn "Got 429 Too Many Requests while downloading '#{sp_playlist.name}', retrying in #{seconds} seconds..."
|
587
|
+
sleep seconds
|
588
|
+
else
|
589
|
+
log.error "Got 429 Too Many Requests while downloading '#{sp_playlist.name}' with a too large retry time of #{seconds} seconds"
|
590
|
+
raise
|
591
|
+
end
|
570
592
|
rescue StandardError => e
|
571
|
-
log.
|
593
|
+
log.warn "Could not download playlist '#{sp_playlist.name}': #{e}"
|
572
594
|
break
|
573
595
|
end
|
574
596
|
end
|
data/lib/drum/version.rb
CHANGED