diff --git a/bandcavall/download.py b/bandcavall/download.py index 340f96e..255723e 100644 --- a/bandcavall/download.py +++ b/bandcavall/download.py @@ -3,16 +3,21 @@ from os.path import join, exists import requests import mutagen.mp3 import logging +import unicodedata log = logging.getLogger(__name__) +def safefname(s): + asciified = unicodedata.normalize('NFKD', s).encode('ascii', 'ignore').decode('ascii') + return asciified.replace('/', '_').replace(' ', '_') + def download_track(track, args): - log.debug('Downloading "%s"' % track['title']) + log.debug('Downloading "%s"', track['title']) if 'album' in track: - fdir = join(track['artist'], track['album']).replace(' ', '_') + fdir = join(safefname(track['artist']), safefname(track['album'])) else: - fdir = join(track['artist']) - fname = track['title'].replace(' ', '_') + '.mp3' + fdir = join(safefname(track['artist'])) + fname = safefname(track['title'] + '.mp3') fpath = join(args.download_base, fdir, fname) os.makedirs(join(args.download_base, fdir), exist_ok=True) if exists(fpath):