safe filename
This commit is contained in:
parent
b8a9bee704
commit
cd973ae368
1 changed files with 9 additions and 4 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue