cleaner genre tags

didnt need to use reduce function
This commit is contained in:
nathannathant 2021-03-06 12:51:03 -08:00
parent 41cc9a5333
commit 5886d274da

View File

@ -1,3 +1,4 @@
import re
import os import os
import logging import logging
@ -37,13 +38,12 @@ def _format_genres(genres: list) -> str:
"""Fixes the weirdly formatted genre lists returned by the API. """Fixes the weirdly formatted genre lists returned by the API.
>>> g = ['Pop/Rock', 'Pop/Rock→Rock', 'Pop/Rock→Rock→Alternatif et Indé'] >>> g = ['Pop/Rock', 'Pop/Rock→Rock', 'Pop/Rock→Rock→Alternatif et Indé']
>>> _format_genres(g) >>> _format_genres(g)
'Pop/Rock, Rock, Alternatif et Indé' 'Pop, Rock, Alternatif et Indé'
""" """
genres = re.findall(r"([^\u2192\/]+)", "/".join(genres))
if genres == []: no_repeats = []
return "" [no_repeats.append(g) for g in genres if g not in no_repeats]
else: return ", ".join(no_repeats)
return ", ".join(genres[-1].split("\u2192"))
# Use KeyError catching instead of dict.get to avoid empty tags # Use KeyError catching instead of dict.get to avoid empty tags