diff --git a/scdl.py b/scdl.py index ed82768..ca2afc4 100755 --- a/scdl.py +++ b/scdl.py @@ -2,8 +2,8 @@ """scdl allow you to download music from soundcloud Usage: - scdl.py -l [-a | -f | -t | -p][-c][-o ][--hidewarnings] - scdl.py me (-s | -a | -f | -t | -p)[-c][-o ][--hidewarnings] + scdl.py -l [-a | -f | -t | -p][-c][-o ][--hidewarnings][--addtofile] + scdl.py me (-s | -a | -f | -t | -p)[-c][-o ][--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[""] 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