Commit 677c0274 authored by petitminion's avatar petitminion
Browse files

clea xspf

parent 35ad9985
Pipeline #15587 failed with stages
in 31 seconds
......@@ -84,13 +84,13 @@ def generate_xspf_from_playlist(playlist_id):
"""
fw_playlist = Playlist.objects.get(id=playlist_id)
plt_tracks = fw_playlist.playlist_tracks.prefetch_related('track')
xpsf_playlist = Element("playlist")
xpsf_tracklist = write_xpsf_headers(xpsf_playlist, fw_playlist.name, str(fw_playlist.creation_date))
xspf_playlist = Element("playlist")
xspf_tracklist = write_xspf_headers(xspf_playlist, fw_playlist.name, str(fw_playlist.creation_date))
for plt_track in plt_tracks:
track = plt_track.track
write_xspf_track_data(track, xpsf_tracklist)
return prettify(xpsf_playlist)
write_xspf_track_data(track, xspf_tracklist)
return prettify(xspf_playlist)
def generate_xspf_from_tracks_ids(tracks_ids):
......@@ -99,30 +99,30 @@ def generate_xspf_from_tracks_ids(tracks_ids):
"""
xspf_title = "An automated generated playlist"
now = datetime.now()
xpsf_date = now.strftime("%m/%d/%Y")
xpsf_playlist = Element("playlist")
xpsf_tracklist = write_xpsf_headers(xpsf_playlist, xspf_title, xpsf_date)
xspf_date = now.strftime("%m/%d/%Y")
xspf_playlist = Element("playlist")
xspf_tracklist = write_xspf_headers(xspf_playlist, xspf_title, xspf_date)
for track_id in tracks_ids:
try:
track = Track.objects.get(id=track_id)
write_xspf_track_data(track, xpsf_tracklist)
write_xspf_track_data(track, xspf_tracklist)
except ObjectDoesNotExist as e:
logger.info(f"Error while quering database : {e!r}")
return prettify(xpsf_playlist)
return prettify(xspf_playlist)
def write_xpsf_headers(xpsf_playlist, xpsf_title, xpsf_date):
def write_xspf_headers(xspf_playlist, xspf_title, xspf_date):
"""
This generate the playlist metadata and return a trackList subelement used to insert each track
into the playlist
"""
xpsf_playlist.set("version", "1")
title_xspf = SubElement(xpsf_playlist, "title")
title_xspf.text = xpsf_title
date_xspf = SubElement(xpsf_playlist, "date")
date_xspf.text = xpsf_date
trackList_xspf = SubElement(xpsf_playlist, "trackList")
xspf_playlist.set("version", "1")
title_xspf = SubElement(xspf_playlist, "title")
title_xspf.text = xspf_title
date_xspf = SubElement(xspf_playlist, "date")
date_xspf.text = xspf_date
trackList_xspf = SubElement(xspf_playlist, "trackList")
return trackList_xspf
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment