From 53e4a2464c2374724615c0b675feed416d6b8fdc Mon Sep 17 00:00:00 2001 From: petitminion Date: Wed, 9 Jun 2021 13:48:59 +0000 Subject: [PATCH] Update api/funkwhale_api/playlists/utils.py --- api/funkwhale_api/playlists/utils.py | 30 +++++++++------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/api/funkwhale_api/playlists/utils.py b/api/funkwhale_api/playlists/utils.py index ab5ec6dc..72177da7 100644 --- a/api/funkwhale_api/playlists/utils.py +++ b/api/funkwhale_api/playlists/utils.py @@ -18,7 +18,7 @@ logger = logging.getLogger(__name__) def clean_namespace_xspf(xspf_file): """ This will delete any namaespace found in the xspf file. It will also delete any encoding info. - This way xspf file will be compatible with our get_playlist_metadata_from_xspf function. + This way xspf file will be compatible with our get_track_id_from_xspf function. """ file = open(xspf_file) with file as f: @@ -44,36 +44,24 @@ def get_track_id_from_xspf(xspf_file): xspf_file_clean = clean_namespace_xspf(xspf_file) tree = etree.parse(xspf_file_clean) tracks = tree.findall(".//track") - total_track_count = 0 - added_file_count = 0 + added_track_count = 0 for track in tracks: track_id = "" - total_track_count = total_track_count + 1 - total = str(total_track_count) # Getting metadata of the xspf file try: artist = track.find(".//creator").text - except Exception as e: - logger.info("Error while parsing Xml file :%s" % e) - try: title = track.find(".//title").text - except Exception as e: - logger.info("Error while parsing Xml file :%s" % e) - try: album = track.find(".//album").text except Exception as e: - logger.info("Error while parsing Xml file :%s" % e) + logger.info(f"Error while parsing Xml file : {e!r}") # Finding track id in the db try: artist_id = Artist.objects.get(name=artist) - except Exception as e: - logger.info("Error while quering database : %s" % e) - try: album_id = Album.objects.get(title=album) except Exception as e: - logger.info("Error while quering database :%s" % e) + logger.info(f"Error while quering database : {e!r}") try: track_id = Track.objects.get( title=title, artist=artist_id.id, album=album_id.id @@ -83,16 +71,16 @@ def get_track_id_from_xspf(xspf_file): try: track_id = Track.objects.get(title=title, artist=artist_id.id) except Exception as e: - logger.info("Error while quering database :%s" % e) + logger.info(f"Error while quering database : {e!r}") if track_id: track_list.append(track_id.id) - added_file_count = added_file_count + 1 + added_track_count = added_track_count + 1 logger.info( - str(total) + str(len(tracks)) + " tracks where found in xspf file. " - + str(added_file_count) - + "are gonna be added to playlist." + + str(added_track_count) + + " are gonna be added to playlist." ) return track_list