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 ( ) : signal . signal ( signal . SIGINT , signal_handler ) global offset global arguments arguments = docopt ( __doc__ , version = __version__ ) if arguments [ '--debug' ] : logger . level = logging . DEBUG elif arguments [ '--error' ] : logger . level = logging . ERROR 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 ( )
Main function, parses the URL from command line arguments