Skip to content

Commit 1c9fa2a

Browse files
committed
added sort by date-added to playlist tracks
1 parent fcc3c56 commit 1c9fa2a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

zotify/playlist.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from zotify.const import ITEMS, ID, TRACK, NAME
22
from zotify.termoutput import Printer
33
from zotify.track import download_track
4-
from zotify.utils import split_input
4+
from zotify.utils import split_input, strptime_utc
55
from zotify.zotify import Zotify
66

77
MY_PLAYLISTS_URL = 'https://api.spotify.com/v1/me/playlists'
@@ -37,6 +37,8 @@ def get_playlist_songs(playlist_id):
3737
if len(resp[ITEMS]) < limit:
3838
break
3939

40+
songs.sort(key=lambda s: strptime_utc(s['added_at']), reverse=True)
41+
4042
return songs
4143

4244

zotify/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,7 @@ def fmt_seconds(secs: float) -> str:
282282
return f'{m}'.zfill(2) + ':' + f'{s}'.zfill(2)
283283
else:
284284
return f'{h}'.zfill(2) + ':' + f'{m}'.zfill(2) + ':' + f'{s}'.zfill(2)
285+
286+
def strptime_utc(dtstr):
287+
return datetime.datetime.strptime(dtstr[:-1], '%Y-%m-%dT%H:%M:%S').replace(tzinfo=datetime.timezone.utc)
288+

0 commit comments

Comments
 (0)