Skip to content

Only first two tracks per playlist are imported (with fix) #2

@dstudzinski

Description

@dstudzinski

Hey,

First of all thank you for your work and this script!

It works almost flawlessly but I had problem that only first two tracks were added to playlist. All further calls were ending with eg
Error adding track to playlist: 412 Client Error: for url: https://api.tidal.com/v1/playlists/XXXXXXX/items?sessionId=YYYYYYY&countryCode=PL&limit=100

I had to add code which refreshes the playlist before each addition

Index: main.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/main.py b/main.py
--- a/main.py	(revision 031b7b0e08cf07f8b54a90720a45f501570b3750)
+++ b/main.py	(revision 1eb8696fe48432475d875c761e684678cfa255dc)
@@ -106,6 +106,7 @@
     """Create a Tidal playlist and add songs"""
     # Create new playlist
     playlist = session.user.create_playlist(playlist_name, "Imported from CSV")
+    playlist_id = playlist.id
     
     # Add each song
     successful_adds = 0
@@ -216,6 +217,8 @@
             if best_match:
                 try:
                     track_id = best_match.id if hasattr(best_match, 'id') else best_match.get('id')
+                    # Refresh playlist each time to get the latest revision; Tidal returns 412 if revision is stale
+                    playlist = session.playlist(playlist_id)
                     playlist.add([track_id])
                     successful_adds += 1
                     print(f"Added ({successful_adds}/{total_songs}): {song['track']} - {song['artist']}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions