calculate playlist duration

- use python's `sum()` method to add durations instead of for loop
This commit is contained in:
geoffrey45
2022-07-02 13:19:09 +03:00
committed by Mungai Geoffrey
parent 5bc0eaf8e6
commit b318c0d324
7 changed files with 27 additions and 25 deletions
+7 -3
View File
@@ -60,12 +60,16 @@ def get_album():
album.count = len(tracks)
try:
album.duration = albumslib.get_album_duration(tracks)
album.duration = sum([t.length for t in tracks])
except AttributeError:
album.duration = 0
if (album.count == 1 and tracks[0].title == album.title
and tracks[0].tracknumber == 1 and tracks[0].disknumber == 1):
if (
album.count == 1
and tracks[0].title == album.title
and tracks[0].tracknumber == 1
and tracks[0].disknumber == 1
):
album.is_single = True
return {"tracks": tracks, "info": album}
+6 -1
View File
@@ -84,7 +84,12 @@ def get_playlist(playlistid: str):
playlist = models.Playlist(p)
tracks = playlistlib.create_playlist_tracks(playlist.pretracks)
return {"info": serializer.Playlist(playlist), "tracks": tracks}
duration = sum([t.length for t in tracks])
playlist = serializer.Playlist(playlist)
playlist.duration = duration
return {"info": playlist, "tracks": tracks}
@playlist_bp.route("/playlist/<playlistid>/update", methods=["PUT"])