better filename

master
flyingrub 2014-10-23 23:40:50 +02:00
parent dae9048010
commit 35018fc74d
1 changed files with 18 additions and 14 deletions

32
scdl.py
View File

@ -2,8 +2,8 @@
"""scdl allow you to download music from soundcloud
Usage:
scdl.py -l <track_url> [-a | -f | -t | -p][-c][-o <offset>][--hidewarnings]
scdl.py me (-s | -a | -f | -t | -p)[-c][-o <offset>][--hidewarnings]
scdl.py -l <track_url> [-a | -f | -t | -p][-c][-o <offset>][--hidewarnings][--addtofile]
scdl.py me (-s | -a | -f | -t | -p)[-c][-o <offset>][--hidewarnings][--addtofile]
scdl.py -h | --help
scdl.py --version
@ -38,7 +38,6 @@ import json
token = ''
i_continue = False
offset=0
filename = ''
@ -52,8 +51,11 @@ def main():
"""
print("Soundcloud Downloader")
global offset
global i_continue
# import conf file
get_config()
# Parse argument
arguments = docopt(__doc__, version='0.1')
print(arguments)
if arguments["<offset>"] is not None:
@ -62,10 +64,6 @@ def main():
except:
print('Offset should be an Integer...')
sys.exit()
i_continue = arguments["-c"]
get_config()
if arguments["--hidewarnings"]:
warnings.filterwarnings("ignore")
@ -263,30 +261,36 @@ def download_track(track):
"""
Downloads a track
"""
global filename
arguments = docopt(__doc__, version='0.1')
if track.streamable:
stream_url = client.get(track.stream_url, allow_redirects=False)
else:
print('This track is not streamable...')
print('%s is not streamable...' % (track.title))
print('')
return
url = stream_url.location
title = track.title
print("Downloading " + title)
valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
global filename
# validate title
invalid_chars = '\/:*?|<>'
if track.user['username'] not in title and arguments["--addtofile"]:
title = track.user['username'] + ' - ' + title
title = ''.join(c for c in title if c not in invalid_chars)
filename = title +'.mp3'
filename = ''.join(c for c in filename if c in valid_chars)
# Download
if not os.path.isfile(filename):
if track.downloadable:
print('Downloading the orginal file.')
url = track.download_url + '?client_id=' + scdl_client_id
wget.download(url, filename)
elif track.streamable:
else:
wget.download(url, filename)
else:
if i_continue:
if arguments["-c"]:
print(title + " already Downloaded")
print('')
return