diff --git a/zotify/playlist.py b/zotify/playlist.py index 53c19418..682688e0 100644 --- a/zotify/playlist.py +++ b/zotify/playlist.py @@ -1,7 +1,7 @@ from zotify.const import ITEMS, ID, TRACK, NAME from zotify.termoutput import Printer from zotify.track import download_track -from zotify.utils import split_input +from zotify.utils import split_input, strptime_utc from zotify.zotify import Zotify MY_PLAYLISTS_URL = 'https://api.spotify.com/v1/me/playlists' @@ -37,6 +37,8 @@ def get_playlist_songs(playlist_id): if len(resp[ITEMS]) < limit: break + songs.sort(key=lambda s: strptime_utc(s['added_at']), reverse=True) + return songs diff --git a/zotify/utils.py b/zotify/utils.py index df8a6611..a6129aac 100644 --- a/zotify/utils.py +++ b/zotify/utils.py @@ -282,3 +282,7 @@ def fmt_seconds(secs: float) -> str: return f'{m}'.zfill(2) + ':' + f'{s}'.zfill(2) else: return f'{h}'.zfill(2) + ':' + f'{m}'.zfill(2) + ':' + f'{s}'.zfill(2) + +def strptime_utc(dtstr): + return datetime.datetime.strptime(dtstr[:-1], '%Y-%m-%dT%H:%M:%S').replace(tzinfo=datetime.timezone.utc) +