Skip to content

Commit f8d2413

Browse files
committed
Sort playlist items by date added, before downloading
Merges PR zotify-dev#55 from upstream.
1 parent 42426c5 commit f8d2413

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

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, PrintChannel
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
import time
77

@@ -38,6 +38,8 @@ def get_playlist_songs(playlist_id):
3838
if len(resp[ITEMS]) < limit:
3939
break
4040

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

4345

zotify/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,6 @@ def fmt_seconds(secs: float) -> str:
295295
return f'{m}'.zfill(2) + ':' + f'{s}'.zfill(2)
296296
else:
297297
return f'{h}'.zfill(2) + ':' + f'{m}'.zfill(2) + ':' + f'{s}'.zfill(2)
298+
299+
def strptime_utc(dtstr):
300+
return datetime.datetime.strptime(dtstr[:-1], '%Y-%m-%dT%H:%M:%S').replace(tzinfo=datetime.timezone.utc)

0 commit comments

Comments
 (0)