Class: Drum::SpotifyService
Overview
A service implementation that uses the Spotify Web API to query playlists.
Constant Summary collapse
- PLAYLISTS_CHUNK_SIZE =
50
- TRACKS_CHUNK_SIZE =
100
- SAVED_TRACKS_CHUNKS_SIZE =
50
- TO_SPOTIFY_TRACKS_CHUNK_SIZE =
50
- UPLOAD_PLAYLIST_TRACKS_CHUNK_SIZE =
100
- MAX_PLAYLIST_TRACKS =
10_000
- CLIENT_ID_VAR =
'SPOTIFY_CLIENT_ID'
- CLIENT_SECRET_VAR =
'SPOTIFY_CLIENT_SECRET'
Instance Method Summary collapse
-
#all_sp_library_playlists(offset: 0) ⇒ Object
Download helpers.
- #all_sp_library_tracks(offset: 0) ⇒ Object
- #all_sp_playlist_tracks(sp_playlist, offset: 0) ⇒ Object
- #authenticate ⇒ Object
-
#authenticate_app(client_id, client_secret) ⇒ Object
Authentication.
- #authenticate_user(client_id, client_secret) ⇒ Object
- #authenticate_user_via_browser(client_id, client_secret) ⇒ Object
- #authenticate_user_via_refresh(client_id, client_secret, refresh_token) ⇒ Object
- #consume_authentication_response(auth_response) ⇒ Object
-
#download(ref) ⇒ Object
Service.
- #extract_sp_features(sp_track) ⇒ Object
- #fetch_me(access_token, token_type) ⇒ Object
- #from_sp_album(sp_album, new_playlist) ⇒ Object
- #from_sp_artist(sp_artist, new_playlist) ⇒ Object
-
#from_sp_id(sp_id, new_playlist) ⇒ Object
TODO: Replace hexdigest id generation with something that matches e.g.
- #from_sp_playlist(sp_playlist, sp_tracks = nil) ⇒ Object
- #from_sp_track(sp_track, new_playlist) ⇒ Object
- #from_sp_user(sp_user, new_playlist) ⇒ Object
-
#initialize(cache_dir, fetch_artist_images: false) ⇒ SpotifyService
constructor
Initializes the Spotify service.
- #name ⇒ Object
- #parse_ref(raw_ref) ⇒ Object
-
#parse_resource_type(raw) ⇒ Object
Ref parsing.
- #parse_spotify_link(raw) ⇒ Object
- #parse_spotify_uri(raw) ⇒ Object
-
#to_sp_track(track, playlist) ⇒ Object
Upload helpers.
- #to_sp_tracks(tracks, playlist) ⇒ Object
- #upload(ref, playlists) ⇒ Object
- #upload_playlist(playlist) ⇒ Object
- #upload_sp_playlist_tracks(sp_tracks, sp_playlist) ⇒ Object
Methods included from Log
Methods inherited from Service
Constructor Details
#initialize(cache_dir, fetch_artist_images: false) ⇒ SpotifyService
Initializes the Spotify service.
55 56 57 58 59 60 61 62 63 |
# File 'lib/drum/service/spotify.rb', line 55 def initialize(cache_dir, fetch_artist_images: false) @cache_dir = cache_dir / self.name @cache_dir.mkdir unless @cache_dir.directory? @auth_tokens = PersistentHash.new(@cache_dir / 'auth-tokens.yaml') @authenticated = false @fetch_artist_images = fetch_artist_images end |
Instance Method Details
#all_sp_library_playlists(offset: 0) ⇒ Object
Download helpers
245 246 247 248 249 250 251 252 |
# File 'lib/drum/service/spotify.rb', line 245 def all_sp_library_playlists(offset: 0) all_sp_playlists = [] while !(sp_playlists = @me.playlists(limit: PLAYLISTS_CHUNK_SIZE, offset: offset)).empty? offset += PLAYLISTS_CHUNK_SIZE all_sp_playlists += sp_playlists end all_sp_playlists end |
#all_sp_library_tracks(offset: 0) ⇒ Object
270 271 272 273 274 275 276 277 |
# File 'lib/drum/service/spotify.rb', line 270 def all_sp_library_tracks(offset: 0) all_sp_tracks = [] while !(sp_tracks = @me.saved_tracks(limit: SAVED_TRACKS_CHUNKS_SIZE, offset: offset)).empty? offset += SAVED_TRACKS_CHUNKS_SIZE all_sp_tracks += sp_tracks end all_sp_tracks end |
#all_sp_playlist_tracks(sp_playlist, offset: 0) ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/drum/service/spotify.rb', line 254 def all_sp_playlist_tracks(sp_playlist, offset: 0) all_sp_tracks = [] while !(sp_tracks = sp_playlist.tracks(limit: TRACKS_CHUNK_SIZE, offset: offset)).empty? offset += TRACKS_CHUNK_SIZE all_sp_tracks += sp_tracks if offset > sp_playlist.total + TRACKS_CHUNK_SIZE 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." break elsif offset > MAX_PLAYLIST_TRACKS log.warn "Truncating playlist '#{sp_playlist.name}' at #{offset}, since it exceeds the maximum of #{MAX_PLAYLIST_TRACKS} tracks." break end end all_sp_tracks end |
#authenticate ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/drum/service/spotify.rb', line 207 def authenticate if @authenticated return end client_id = ENV[CLIENT_ID_VAR] client_secret = ENV[CLIENT_SECRET_VAR] if client_id.nil? || client_secret.nil? raise "Please specify the env vars #{CLIENT_ID_VAR} and #{CLIENT_SECRET_VAR}!" end self.authenticate_app(client_id, client_secret) access_token, refresh_token, token_type = self.authenticate_user(client_id, client_secret) me_json = self.fetch_me(access_token, token_type) me_json['credentials'] = { 'token' => access_token, 'refresh_token' => refresh_token, 'access_refresh_callback' => Proc.new do |new_token, token_lifetime| new_expiry = DateTime.now + (token_lifetime / 86400.0) @auth_tokens[:latest] = { access_token: new_token, refresh_token: refresh_token, # TODO: Refresh token might change too token_type: token_type, expires_at: new_expiry } end } @me = RSpotify::User.new(me_json) @authenticated = true log.info "Successfully logged in to Spotify API as #{me_json['id']}." end |
#authenticate_app(client_id, client_secret) ⇒ Object
Authentication
71 72 73 |
# File 'lib/drum/service/spotify.rb', line 71 def authenticate_app(client_id, client_secret) RSpotify.authenticate(client_id, client_secret) end |
#authenticate_user(client_id, client_secret) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/drum/service/spotify.rb', line 178 def authenticate_user(client_id, client_secret) existing = @auth_tokens[:latest] unless existing.nil? || existing[:expires_at].nil? || existing[:expires_at] < DateTime.now log.info 'Skipping authentication...' return existing[:access_token], existing[:refresh_token], existing[:token_type] end unless existing.nil? || existing[:refresh_token].nil? log.info 'Authenticating via refresh...' self.authenticate_user_via_refresh(client_id, client_secret, existing[:refresh_token]) else log.info 'Authenticating via browser...' self.authenticate_user_via_browser(client_id, client_secret) end end |
#authenticate_user_via_browser(client_id, client_secret) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/drum/service/spotify.rb', line 98 def authenticate_user_via_browser(client_id, client_secret) # Generate a new access refresh token, # this might require user interaction. Since the # user has to authenticate through the browser # via Spotify's website, we use a small embedded # HTTP server as a 'callback'. port = 17998 server = WEBrick::HTTPServer.new Port: port csrf_state = SecureRandom.hex auth_code = nil error = nil server.mount_proc '/callback' do |req, res| error = req.query['error'] auth_code = req.query['code'] csrf_response = req.query['state'] if error.nil? && !auth_code.nil? && csrf_response == csrf_state res.body = 'Successfully got authorization code!' else res.body = "Could not authorize: #{error} Sorry :(" end server.shutdown end scopes = [ # Listening History 'user-read-recently-played', 'user-top-read', # Playlists 'playlist-modify-private', 'playlist-read-private', 'playlist-read-collaborative', # Library 'user-library-modify', 'user-library-read', # User 'user-read-private' ] = "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}" Launchy.open() log.info "Launching callback HTTP server on port #{port}, waiting for auth code..." server.start if auth_code.nil? raise "Did not get an auth code: #{error}" end auth_response = RestClient.post('https://accounts.spotify.com/api/token', { grant_type: 'authorization_code', code: auth_code, redirect_uri: "http://localhost:#{port}/callback", # validation only client_id: client_id, client_secret: client_secret }) self.consume_authentication_response(auth_response) ensure server&.shutdown end |
#authenticate_user_via_refresh(client_id, client_secret, refresh_token) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/drum/service/spotify.rb', line 162 def authenticate_user_via_refresh(client_id, client_secret, refresh_token) # Authenticate the user using an existing (cached) # refresh token. This is useful if the user already # has been authenticated or a non-interactive authentication # is required (e.g. in a CI script). encoded = Base64.strict_encode64("#{client_id}:#{client_secret}") auth_response = RestClient.post('https://accounts.spotify.com/api/token', { grant_type: 'refresh_token', refresh_token: refresh_token }, { 'Authorization' => "Basic #{encoded}" }) self.consume_authentication_response(auth_response) end |
#consume_authentication_response(auth_response) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/drum/service/spotify.rb', line 75 def consume_authentication_response(auth_response) unless auth_response.code >= 200 && auth_response.code < 300 raise "Something went wrong while fetching auth token: #{auth_response}" end auth_json = JSON.parse(auth_response.body) access_token = auth_json['access_token'] refresh_token = auth_json['refresh_token'] token_type = auth_json['token_type'] expires_in = auth_json['expires_in'] # seconds expires_at = DateTime.now + (expires_in / 86400.0) @auth_tokens[:latest] = { access_token: access_token, refresh_token: refresh_token || @auth_tokens[:latest][:refresh_token], token_type: token_type, expires_at: expires_at } log.info "Successfully added access token that expires at #{expires_at}." [access_token, refresh_token, token_type] end |
#download(ref) ⇒ Object
Service
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
# File 'lib/drum/service/spotify.rb', line 554 def download(ref) self.authenticate case ref.resource_type when :special case ref.resource_location when :playlists log.info 'Querying playlists...' sp_playlists = self.all_sp_library_playlists log.info 'Fetching playlists...' Enumerator.new(sp_playlists.length) do |enum| sp_playlists.each do |sp_playlist| # These playlists seem to cause trouble for some reason, by either # 404ing or by returning seemingly endless amounts of tracks, so # we'll ignore them for now... if sp_playlist.name.start_with?('Your Top Songs') log.info "Skipping '#{sp_playlist.name}'" next end 3.times do |attempt| begin if attempt > 0 log.info "Attempt \##{attempt + 1} to download '#{sp_playlist.name}'..." end new_playlist = self.from_sp_playlist(sp_playlist) enum.yield new_playlist break rescue RestClient::TooManyRequests => e seconds = e.response.headers[:retry_after]&.to_f || 0.5 if seconds <= 300 log.warn "Got 429 Too Many Requests while downloading '#{sp_playlist.name}', retrying in #{seconds} seconds..." sleep seconds else log.error "Got 429 Too Many Requests while downloading '#{sp_playlist.name}' with a too large retry time of #{seconds} seconds" raise end rescue StandardError => e log.warn "Could not download playlist '#{sp_playlist.name}': #{e}" break end end end end when :tracks log.info 'Querying saved tracks...' sp_saved_tracks = self.all_sp_library_tracks log.info 'Fetching saved tracks...' new_playlist = Playlist.new( name: 'Saved Tracks' ) new_me = self.from_sp_user(@me, new_playlist) new_playlist.id = self.from_sp_id(new_me.id, new_playlist) new_playlist. = new_me.id new_playlist.store_user(new_me) sp_saved_tracks.each do |sp_track| new_track, new_artists, new_album = self.from_sp_track(sp_track, new_playlist) new_artists.each do |new_artist| new_playlist.store_artist(new_artist) end new_playlist.store_album(new_album) new_playlist.store_track(new_track) end [new_playlist] else raise "Special resource location '#{ref.resource_location}' cannot be downloaded (yet)" end when :playlist sp_playlist = RSpotify::Playlist.find_by_id(ref.resource_location) new_playlist = self.from_sp_playlist(sp_playlist) [new_playlist] else raise "Resource type '#{ref.resource_type}' cannot be downloaded (yet)" end end |
#extract_sp_features(sp_track) ⇒ Object
279 280 281 |
# File 'lib/drum/service/spotify.rb', line 279 def extract_sp_features(sp_track) sp_track&.audio_features end |
#fetch_me(access_token, token_type) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/drum/service/spotify.rb', line 195 def fetch_me(access_token, token_type) auth_response = RestClient.get('https://api.spotify.com/v1/me', { Authorization: "#{token_type} #{access_token}" }) unless auth_response.code >= 200 && auth_response.code < 300 raise "Something went wrong while user data: #{auth_response}" end return JSON.parse(auth_response.body) end |
#from_sp_album(sp_album, new_playlist) ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/drum/service/spotify.rb', line 295 def from_sp_album(sp_album, new_playlist) new_id = self.from_sp_id(sp_album.id, new_playlist) new_album = new_playlist.albums[new_id] unless new_album.nil? return [new_album, []] end new_album = Album.new( id: self.from_sp_id(sp_album.id, new_playlist), name: sp_album.name, spotify: AlbumSpotify.new( id: sp_album.id, image_url: sp_album&.images.first&.dig('url') ) ) new_artists = sp_album.artists.map do |sp_artist| new_artist = self.from_sp_artist(sp_artist, new_playlist) new_album.artist_ids << new_artist.id new_artist end [new_album, new_artists] end |
#from_sp_artist(sp_artist, new_playlist) ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/drum/service/spotify.rb', line 346 def from_sp_artist(sp_artist, new_playlist) new_id = self.from_sp_id(sp_artist.id, new_playlist) new_playlist.artists[new_id] || Artist.new( id: new_id, name: sp_artist.name, spotify: ArtistSpotify.new( id: sp_artist.id, image_url: if @fetch_artist_images sp_artist&.images.first&.dig('url') else nil end ) ) end |
#from_sp_id(sp_id, new_playlist) ⇒ Object
TODO: Replace hexdigest id generation with something
that matches e.g. artists or albums with those
already in the playlist.
291 292 293 |
# File 'lib/drum/service/spotify.rb', line 291 def from_sp_id(sp_id, new_playlist) sp_id.try { |i| Digest::SHA1.hexdigest(sp_id) } end |
#from_sp_playlist(sp_playlist, sp_tracks = nil) ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/drum/service/spotify.rb', line 382 def from_sp_playlist(sp_playlist, sp_tracks = nil) new_playlist = Playlist.new( name: sp_playlist.name, description: sp_playlist&.description, spotify: PlaylistSpotify.new( id: sp_playlist.id, public: sp_playlist.public, collaborative: sp_playlist.collaborative, image_url: begin sp_playlist&.images.first&.dig('url') rescue StandardError => e nil end ) ) new_playlist.id = self.from_sp_id(sp_playlist.id, new_playlist) = sp_playlist&.owner unless .nil? = self.from_sp_user(, new_playlist) new_playlist. = .id new_playlist.store_user() end sp_added_bys = sp_playlist.tracks_added_by sp_added_ats = sp_playlist.tracks_added_at sp_tracks = sp_tracks || self.all_sp_playlist_tracks(sp_playlist) log.info "Got #{sp_tracks.length} playlist track(s) for '#{sp_playlist.name}'..." sp_tracks.each do |sp_track| new_track, new_artists, new_album = self.from_sp_track(sp_track, new_playlist) new_track.added_at = sp_added_ats[sp_track.id] sp_added_by = sp_added_bys[sp_track.id] unless sp_added_by.nil? new_added_by = self.from_sp_user(sp_added_by, new_playlist) new_track.added_by = new_added_by.id new_playlist.store_user(new_added_by) end new_artists.each do |new_artist| new_playlist.store_artist(new_artist) end new_playlist.store_album(new_album) new_playlist.store_track(new_track) end new_playlist end |
#from_sp_track(sp_track, new_playlist) ⇒ Object
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/drum/service/spotify.rb', line 320 def from_sp_track(sp_track, new_playlist) new_track = Track.new( name: sp_track.name, duration_ms: sp_track.duration_ms, explicit: sp_track.explicit, isrc: sp_track.external_ids&.dig('isrc'), spotify: TrackSpotify.new( id: sp_track.id ) ) new_artists = sp_track.artists.map do |sp_artist| new_artist = self.from_sp_artist(sp_artist, new_playlist) new_track.artist_ids << new_artist.id new_artist end new_album, new_album_artists = self.from_sp_album(sp_track.album, new_playlist) new_track.album_id = new_album.id new_artists += new_album_artists # TODO: Audio features [new_track, new_artists, new_album] end |
#from_sp_user(sp_user, new_playlist) ⇒ Object
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/drum/service/spotify.rb', line 362 def from_sp_user(sp_user, new_playlist) new_id = self.from_sp_id(sp_user.id, new_playlist) new_playlist.users[new_id] || User.new( id: self.from_sp_id(sp_user.id, new_playlist), display_name: begin sp_user.display_name unless sp_user.id.empty? rescue StandardError => e nil end, spotify: UserSpotify.new( id: sp_user.id, image_url: begin sp_user&.images.first&.dig('url') rescue StandardError => e nil end ) ) end |
#name ⇒ Object
65 66 67 |
# File 'lib/drum/service/spotify.rb', line 65 def name 'spotify' end |
#parse_ref(raw_ref) ⇒ Object
539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/drum/service/spotify.rb', line 539 def parse_ref(raw_ref) if raw_ref.is_token location = case raw_ref.text when "#{self.name}/tracks" then :tracks when "#{self.name}/playlists" then :playlists else return nil end Ref.new(self.name, :special, location) else self.parse_spotify_link(raw_ref.text) || self.parse_spotify_uri(raw_ref.text) end end |
#parse_resource_type(raw) ⇒ Object
Ref parsing
494 495 496 497 498 499 500 501 502 503 |
# File 'lib/drum/service/spotify.rb', line 494 def parse_resource_type(raw) case raw when 'playlist' then :playlist when 'album' then :album when 'track' then :track when 'user' then :user when 'artist' then :artist else nil end end |
#parse_spotify_link(raw) ⇒ Object
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/drum/service/spotify.rb', line 505 def parse_spotify_link(raw) uri = URI(raw) unless ['http', 'https'].include?(uri&.scheme) && uri&.host == 'open.spotify.com' return nil end parsed_path = uri.path.split('/') unless parsed_path.length == 3 return nil end resource_type = self.parse_resource_type(parsed_path[1]) resource_location = parsed_path[2] Ref.new(self.name, resource_type, resource_location) end |
#parse_spotify_uri(raw) ⇒ Object
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/drum/service/spotify.rb', line 522 def parse_spotify_uri(raw) uri = URI(raw) unless uri&.scheme == 'spotify' return nil end parsed_path = uri.opaque.split(':') unless parsed_path.length == 2 return nil end resource_type = self.parse_resource_type(parsed_path[0]) resource_location = parsed_path[1] Ref.new(self.name, resource_type, resource_location) end |
#to_sp_track(track, playlist) ⇒ Object
Upload helpers
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/drum/service/spotify.rb', line 436 def to_sp_track(track, playlist) sp_id = track&.spotify&.id unless sp_id.nil? # We already have an associated Spotify ID RSpotify::Track.find(sp_id) else # We need to search for the song search_phrase = playlist.track_search_phrase(track) sp_results = RSpotify::Track.search(search_phrase, limit: 1) sp_track = sp_results[0] unless sp_track.nil? log.info "Matched '#{track.name}' with '#{sp_track.name}' by '#{sp_track.artists.map { |a| a.name }.join(', ')}' from Spotify" end sp_track end end |
#to_sp_tracks(tracks, playlist) ⇒ Object
455 456 457 458 459 460 461 462 |
# File 'lib/drum/service/spotify.rb', line 455 def to_sp_tracks(tracks, playlist) unless tracks.nil? || tracks.empty? sp_tracks = tracks[...TO_SPOTIFY_TRACKS_CHUNK_SIZE].filter_map { |t| self.to_sp_track(t, playlist) } sp_tracks + to_sp_tracks(tracks[TO_SPOTIFY_TRACKS_CHUNK_SIZE...], playlist) else [] end end |
#upload(ref, playlists) ⇒ Object
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/drum/service/spotify.rb', line 635 def upload(ref, playlists) self.authenticate # Note that pushes currently intentionally always create a new playlist # TODO: Flag for overwriting (something like -f, --force?) # (the flag should be declared in the CLI and perhaps added # to Service.upload as a parameter) unless ref.resource_type == :special && ref.resource_location == :playlists raise 'Cannot upload to anything other than @spotify/playlists yet!' end playlists.each do |playlist| self.upload_playlist(playlist) end end |
#upload_playlist(playlist) ⇒ Object
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/drum/service/spotify.rb', line 471 def upload_playlist(playlist) sp_playlist = @me.create_playlist!( playlist.name, description: playlist.description, # TODO: Use public/collaborative from playlist? public: false, collaborative: false ) tracks = playlist.tracks log.info "Externalizing #{tracks.length} playlist track(s)..." sp_tracks = self.to_sp_tracks(tracks, playlist) log.info "Uploading #{sp_tracks.length} playlist track(s)..." self.upload_sp_playlist_tracks(sp_tracks, sp_playlist) # TODO: Clone the original playlist and insert potentially new Spotify ids nil end |
#upload_sp_playlist_tracks(sp_tracks, sp_playlist) ⇒ Object
464 465 466 467 468 469 |
# File 'lib/drum/service/spotify.rb', line 464 def upload_sp_playlist_tracks(sp_tracks, sp_playlist) unless sp_tracks.nil? || sp_tracks.empty? sp_playlist.add_tracks!(sp_tracks[...UPLOAD_PLAYLIST_TRACKS_CHUNK_SIZE]) self.upload_sp_playlist_tracks(sp_tracks[UPLOAD_PLAYLIST_TRACKS_CHUNK_SIZE...], sp_playlist) end end |