def main(): """ Main function, call parse_url """ signal.signal(signal.SIGINT, signal_handler) global offset global arguments # import conf file get_config() # Parse argument arguments = docopt(__doc__, version=__version__) if arguments['--debug']: logger.level = logging.DEBUG elif arguments['--error']: logger.level = logging.ERROR logger.info('Soundcloud Downloader') logger.debug(arguments) if arguments['-o'] is not None: try: offset = int(arguments['-o']) - 1 except: logger.error('Offset should be an integer...') sys.exit() logger.debug('offset: %d', offset) if arguments['--min-size'] is not None: try: arguments['--min-size'] = utils.size_in_bytes( arguments['--min-size'] ) except: logger.exception( 'Min size should be an integer with a possible unit suffix' ) sys.exit() logger.debug('min-size: %d', arguments['--min-size']) if arguments['--max-size'] is not None: try: arguments['--max-size'] = utils.size_in_bytes( arguments['--max-size'] ) except: logger.error( 'Max size should be an integer with a possible unit suffix' ) sys.exit() logger.debug('max-size: %d', arguments['--max-size']) if arguments['--hidewarnings']: warnings.filterwarnings('ignore') if arguments['--path'] is not None: if os.path.exists(arguments['--path']): os.chdir(arguments['--path']) else: logger.error('Invalid path in arguments...') sys.exit() logger.debug('Downloading to '+os.getcwd()+'...') logger.newline() if arguments['-l']: parse_url(arguments['-l']) elif arguments['me']: if arguments['-f']: download(who_am_i(), 'favorites', 'likes') elif arguments['-t']: download(who_am_i(), 'tracks', 'uploaded tracks') elif arguments['-a']: download(who_am_i(), 'all', 'tracks and reposts') elif arguments['-p']: download(who_am_i(), 'playlists', 'playlists')
def main(): """ Main function, parses the URL from command line arguments """ signal.signal(signal.SIGINT, signal_handler) global offset global arguments # Parse argument arguments = docopt(__doc__, version=__version__) if arguments['--debug']: logger.level = logging.DEBUG elif arguments['--error']: logger.level = logging.ERROR # import conf file get_config() logger.info('Soundcloud Downloader') logger.debug(arguments) if arguments['-o'] is not None: try: offset = int(arguments['-o']) if offset < 0: raise except: logger.error('Offset should be a positive integer...') sys.exit() logger.debug('offset: %d', offset) if arguments['--min-size'] is not None: try: arguments['--min-size'] = utils.size_in_bytes( arguments['--min-size'] ) except: logger.exception( 'Min size should be an integer with a possible unit suffix' ) sys.exit() logger.debug('min-size: %d', arguments['--min-size']) if arguments['--max-size'] is not None: try: arguments['--max-size'] = utils.size_in_bytes( arguments['--max-size'] ) except: logger.error( 'Max size should be an integer with a possible unit suffix' ) sys.exit() logger.debug('max-size: %d', arguments['--max-size']) if arguments['--hidewarnings']: warnings.filterwarnings('ignore') if arguments['--path'] is not None: if os.path.exists(arguments['--path']): os.chdir(arguments['--path']) else: logger.error('Invalid path in arguments...') sys.exit() logger.debug('Downloading to ' + os.getcwd() + '...') if arguments['-l']: parse_url(arguments['-l']) elif arguments['me']: if arguments['-f']: download(who_am_i(), 'favorites', 'likes') if arguments['-C']: download(who_am_i(), 'commented', 'commented tracks') elif arguments['-t']: download(who_am_i(), 'tracks', 'uploaded tracks') elif arguments['-a']: download(who_am_i(), 'all', 'tracks and reposts') elif arguments['-p']: download(who_am_i(), 'playlists', 'playlists') elif arguments['-m']: download(who_am_i(), 'playlists-liked', 'my and liked playlists') if arguments['--remove']: remove_files()
def main(): """ Main function, parses the URL from command line arguments """ signal.signal(signal.SIGINT, signal_handler) global client global offset global arguments global name_format global client_id global token # Parse argument arguments = docopt(__doc__, version=__version__) if arguments["--debug"]: logger.level = logging.DEBUG elif arguments["--error"]: logger.level = logging.ERROR # import conf file get_config() logger.info("Soundcloud Downloader") logger.debug(arguments) if arguments["--client-id"]: client_id = arguments["--client-id"] if arguments["--auth-token"]: token = arguments["--auth-token"] client = SoundCloud(client_id, token if token else None) if not client.is_client_id_valid(): raise ValueError(f"CLIENT_ID: '{client_id}' is not valid") if token and not client.is_auth_token_valid(): raise ValueError(f"auth_token is not valid") if arguments["-o"] is not None: try: offset = int(arguments["-o"]) if offset < 1: raise ValueError() except: logger.error("Offset should be a positive integer...") sys.exit(-1) logger.debug("offset: %d", offset) if arguments["--min-size"] is not None: try: arguments["--min-size"] = utils.size_in_bytes(arguments["--min-size"]) except: logger.exception( "Min size should be an integer with a possible unit suffix" ) sys.exit(-1) logger.debug("min-size: %d", arguments["--min-size"]) if arguments["--max-size"] is not None: try: arguments["--max-size"] = utils.size_in_bytes(arguments["--max-size"]) except: logger.error("Max size should be an integer with a possible unit suffix") sys.exit(-1) logger.debug("max-size: %d", arguments["--max-size"]) if arguments["--hidewarnings"]: warnings.filterwarnings("ignore") if arguments["--path"] is not None: if os.path.exists(arguments["--path"]): os.chdir(arguments["--path"]) else: logger.error("Invalid path in arguments...") sys.exit(-1) logger.debug("Downloading to " + os.getcwd() + "...") if arguments["--name-format"]: name_format = arguments["--name-format"] if arguments["-l"]: parse_url(arguments["-l"]) if arguments["--remove"]: remove_files()