Merge pull request #145 from e2del/forked

Windows fix issues
master
Ronan 6 years ago committed by GitHub
commit 8177ed0883
  1. 12
      scdl/scdl.py

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

Loading…
Cancel
Save