fix: empty track_uris guard, None duration handling, README env block
This commit is contained in:
@@ -46,6 +46,8 @@ def get_client() -> spotipy.Spotify:
|
||||
|
||||
|
||||
def _format_duration(ms: int) -> str:
|
||||
if ms is None:
|
||||
return "unknown"
|
||||
seconds = ms // 1000
|
||||
minutes, seconds = divmod(seconds, 60)
|
||||
return f"{minutes}:{seconds:02d}"
|
||||
@@ -154,6 +156,8 @@ def create_playlist(name: str, description: str = "", public: bool = False) -> d
|
||||
|
||||
|
||||
def add_tracks_to_playlist(playlist_id: str, track_uris: list[str]) -> dict:
|
||||
if not track_uris:
|
||||
raise ValueError("track_uris must not be empty")
|
||||
sp = get_client()
|
||||
for i in range(0, len(track_uris), 100):
|
||||
sp.playlist_add_items(playlist_id, track_uris[i : i + 100])
|
||||
|
||||
Reference in New Issue
Block a user