commit
8177ed0883
12
scdl/scdl.py
12
scdl/scdl.py
|
@ -48,6 +48,7 @@ import shutil
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import codecs
|
||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import mutagen
|
import mutagen
|
||||||
|
@ -314,14 +315,14 @@ def download_playlist(playlist):
|
||||||
global offset
|
global offset
|
||||||
invalid_chars = '\/:*?|<>"'
|
invalid_chars = '\/:*?|<>"'
|
||||||
playlist_name = playlist['title'].encode('utf-8', 'ignore')
|
playlist_name = playlist['title'].encode('utf-8', 'ignore')
|
||||||
playlist_name = playlist_name.decode(sys.stdout.encoding)
|
playlist_name = playlist_name.decode('utf8')
|
||||||
playlist_name = ''.join(c for c in playlist_name if c not in invalid_chars)
|
playlist_name = ''.join(c for c in playlist_name if c not in invalid_chars)
|
||||||
|
|
||||||
if not os.path.exists(playlist_name):
|
if not os.path.exists(playlist_name):
|
||||||
os.makedirs(playlist_name)
|
os.makedirs(playlist_name)
|
||||||
os.chdir(playlist_name)
|
os.chdir(playlist_name)
|
||||||
|
|
||||||
with open(playlist_name + '.m3u', 'w+') as playlist_file:
|
with codecs.open(playlist_name + '.m3u', 'w+', 'utf8') as playlist_file:
|
||||||
playlist_file.write('#EXTM3U' + os.linesep)
|
playlist_file.write('#EXTM3U' + os.linesep)
|
||||||
for counter, track_raw in enumerate(playlist['tracks'], 1):
|
for counter, track_raw in enumerate(playlist['tracks'], 1):
|
||||||
if offset > 0:
|
if offset > 0:
|
||||||
|
@ -364,7 +365,7 @@ def download_track(track, playlist_name=None, playlist_file=None):
|
||||||
global arguments
|
global arguments
|
||||||
|
|
||||||
title = track['title']
|
title = track['title']
|
||||||
title = title.encode('utf-8', 'ignore').decode(sys.stdout.encoding)
|
title = title.encode('utf-8', 'ignore').decode('utf8')
|
||||||
if track['streamable']:
|
if track['streamable']:
|
||||||
url = '{0}?client_id={1}'.format(track['stream_url'], scdl_client_id)
|
url = '{0}?client_id={1}'.format(track['stream_url'], scdl_client_id)
|
||||||
else:
|
else:
|
||||||
|
@ -382,13 +383,14 @@ def download_track(track, playlist_name=None, playlist_file=None):
|
||||||
d = r.headers['content-disposition']
|
d = r.headers['content-disposition']
|
||||||
filename = re.findall("filename=(.+)", d)[0][1:-1]
|
filename = re.findall("filename=(.+)", d)[0][1:-1]
|
||||||
else:
|
else:
|
||||||
invalid_chars = '\/:*?|<>"'
|
|
||||||
username = track['user']['username']
|
username = track['user']['username']
|
||||||
if username not in title and arguments['--addtofile']:
|
if username not in title and arguments['--addtofile']:
|
||||||
title = '{0} - {1}'.format(username, title)
|
title = '{0} - {1}'.format(username, title)
|
||||||
title = ''.join(c for c in title if c not in invalid_chars)
|
|
||||||
filename = title + '.mp3'
|
filename = title + '.mp3'
|
||||||
|
|
||||||
|
invalid_chars = '\/:*?|<>"'
|
||||||
|
filename = ''.join(c for c in filename if c not in invalid_chars)
|
||||||
|
|
||||||
logger.debug("filename : {0}".format(filename))
|
logger.debug("filename : {0}".format(filename))
|
||||||
# Add the track to the generated m3u playlist file
|
# Add the track to the generated m3u playlist file
|
||||||
if playlist_file:
|
if playlist_file:
|
||||||
|
|
Loading…
Reference in New Issue