From 029e8a8289c44379f3bd4de4af1fd90a368c238f Mon Sep 17 00:00:00 2001 From: tehkillerbee Date: Tue, 1 Oct 2024 22:18:45 +0200 Subject: [PATCH] Add track to user playlist from ISRC (Fixes #96) --- tidalapi/playlist.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tidalapi/playlist.py b/tidalapi/playlist.py index d18ad7a..61e9333 100644 --- a/tidalapi/playlist.py +++ b/tidalapi/playlist.py @@ -276,8 +276,8 @@ def add( :param media_ids: List of Media IDs to add. :param allow_duplicates: Allow adding duplicate items - :param position: Insert items at a specific position. Default: insert at the end - of the playlist + :param position: Insert items at a specific position. + Default: insert at the end of the playlist :return: True, if successful. """ # Insert items at a specific index @@ -302,6 +302,35 @@ def add( self._reparse() return res.ok + def add_by_isrc( + self, + isrc: str, + allow_duplicates: bool = False, + position: int = -1, + ) -> bool: + """ + Add an item to a playlist, using the track ISRC + + :param isrc: The ISRC to be added + :param allow_duplicates: Allow adding duplicate items + :param position: Insert items at a specific position. + Default: insert at the end of the playlist + :return: True, if successful. + """ + try: + track = self.session.get_tracks_by_isrc(isrc) + if track: + # Add the first track in the list + return self.add( + [str(track[0].id)], + allow_duplicates=allow_duplicates, + position=position, + ) + else: + return False + except ObjectNotFound: + return False + def move_by_id(self, media_id: str, position: int) -> bool: """Move an item to a new position, by media ID.