File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 22from zotify .podcast import download_episode
33from zotify .termoutput import Printer
44from zotify .track import download_track
5- from zotify .utils import split_input
5+ from zotify .utils import split_input , strptime_utc
66from zotify .zotify import Zotify
77
88MY_PLAYLISTS_URL = 'https://api.spotify.com/v1/me/playlists'
@@ -30,14 +30,16 @@ def get_playlist_songs(playlist_id):
3030 songs = []
3131 offset = 0
3232 limit = 100
33-
33+
3434 while True :
3535 resp = Zotify .invoke_url_with_params (f'{ PLAYLISTS_URL } /{ playlist_id } /tracks' , limit = limit , offset = offset )
3636 offset += limit
3737 songs .extend (resp [ITEMS ])
3838 if len (resp [ITEMS ]) < limit :
3939 break
40-
40+
41+ songs .sort (key = lambda s : strptime_utc (s ['added_at' ]), reverse = True )
42+
4143 return songs
4244
4345
Original file line number Diff line number Diff line change @@ -339,17 +339,17 @@ def fix_filename(name):
339339
340340def fmt_seconds (secs : float ) -> str :
341341 val = math .floor (secs )
342-
342+
343343 s = math .floor (val % 60 )
344344 val -= s
345345 val /= 60
346-
346+
347347 m = math .floor (val % 60 )
348348 val -= m
349349 val /= 60
350-
350+
351351 h = math .floor (val )
352-
352+
353353 if h == 0 and m == 0 and s == 0 :
354354 return "0s"
355355 elif h == 0 and m == 0 :
@@ -358,3 +358,7 @@ def fmt_seconds(secs: float) -> str:
358358 return f'{ m } ' .zfill (2 ) + ':' + f'{ s } ' .zfill (2 )
359359 else :
360360 return f'{ h } ' .zfill (2 ) + ':' + f'{ m } ' .zfill (2 ) + ':' + f'{ s } ' .zfill (2 )
361+
362+
363+ def strptime_utc (dtstr ):
364+ return datetime .datetime .strptime (dtstr [:- 1 ], '%Y-%m-%dT%H:%M:%S' ).replace (tzinfo = datetime .timezone .utc )
You can’t perform that action at this time.
0 commit comments