Esempio n. 1
0
def test_album(tmpdir):
    expect_tracks = 15
    global text_file
    text_file = os.path.join(str(tmpdir), 'test_al.txt')
    spotify_tools.write_album('https://open.spotify.com/album/499J8bIsEnU7DSrosFDJJg', text_file)
    with open(text_file, 'r') as tin:
        tracks = len(tin.readlines())
    assert tracks == expect_tracks
Esempio n. 2
0
def main():
    const.args = handle.get_arguments()

    if const.args.version:
        print('spotdl {version}'.format(version=__version__))
        sys.exit()

    internals.filter_path(const.args.folder)
    youtube_tools.set_api_key()

    const.log = const.logzero.setup_logger(formatter=const._formatter,
                                           level=const.args.log_level)
    global log
    log = const.log
    log.debug('Python version: {}'.format(sys.version))
    log.debug('Platform: {}'.format(platform.platform()))
    log.debug(pprint.pformat(const.args.__dict__))

    try:
        if const.args.song:
            download_single(raw_song=const.args.song)
        elif const.args.list:
            download_list(text_file=const.args.list)
        elif const.args.playlist:
            spotify_tools.write_playlist(playlist_url=const.args.playlist)
        elif const.args.album:
            spotify_tools.write_album(album_url=const.args.album)
        elif const.args.username:
            spotify_tools.write_user_playlist(username=const.args.username)

        # actually we don't necessarily need this, but yeah...
        # explicit is better than implicit!
        sys.exit(0)

    except KeyboardInterrupt as e:
        log.exception(e)
        sys.exit(3)
Esempio n. 3
0
    const.args = handle.get_arguments()
    internals.filter_path(const.args.folder)
    youtube_tools.set_api_key()

    const.log = const.logzero.setup_logger(formatter=const.formatter,
                                           level=const.args.log_level)
    log = const.log
    log.debug('Python version: {}'.format(sys.version))
    log.debug('Platform: {}'.format(platform.platform()))
    log.debug(pprint.pformat(const.args.__dict__))

    try:
        if const.args.song:
            download_single(raw_song=const.args.song)
        elif const.args.list:
            download_list(text_file=const.args.list)
        elif const.args.playlist:
            spotify_tools.write_playlist(playlist_url=const.args.playlist)
        elif const.args.album:
            spotify_tools.write_album(album_url=const.args.album)
        elif const.args.username:
            spotify_tools.write_user_playlist(username=const.args.username)

        # actually we don't necessarily need this, but yeah...
        # explicit is better than implicit!
        sys.exit(0)

    except KeyboardInterrupt as e:
        log.exception(e)
        sys.exit(3)
Esempio n. 4
0
def main():
    const.args = handle.get_arguments()

    if const.args.version:
        print('spotdl {version}'.format(version=__version__))
        sys.exit()

    internals.filter_path(const.args.folder)

    const.log = const.logzero.setup_logger(formatter=const._formatter,
                                           level=const.args.log_level)
    global log
    log = const.log
    log.debug('Python version: {}'.format(sys.version))
    log.debug('Platform: {}'.format(platform.platform()))
    log.debug(pprint.pformat(const.args.__dict__))

    try:
        if const.args.song:
            download_single(raw_song=const.args.song)
        elif const.args.list:
            if os.path.isdir(const.args.list):
                files = [
                    f for f in os.listdir(const.args.list)
                    if re.match(r'.*\.txt', f)
                    and not re.match(r'requirements\.txt', f)
                ]
                shuffle(files)
                timeout = time.time() + int(
                    os.getenv('MAX_DOWNLOAD_TIME_MIN', '300')) * 60
                index = 0
                while len(files) > 0:
                    list_file = files[index]
                    if time.time() > timeout:
                        log.info(
                            'Total timeout! Stopping download of playlists.')
                        break
                    folder = os.path.join(const.args.folder,
                                          list_file).rstrip('.txt')
                    internals.filter_path(folder)
                    if download_list(os.path.join(const.args.list, list_file),
                                     folder):
                        files.pop(index)
                    else:
                        index = index + 1
                    if index >= len(files):
                        index = 0
            else:
                download_list(text_file=const.args.list)
        elif const.args.playlist:
            spotify_tools.write_playlist(playlist_url=const.args.playlist)
        elif const.args.album:
            spotify_tools.write_album(album_url=const.args.album)
        elif const.args.username:
            if not os.path.exists('./playlists'):
                os.makedirs('./playlists')
            spotify_tools.write_user_playlist(username=const.args.username,
                                              path='./playlists')

        # actually we don't necessarily need this, but yeah...
        # explicit is better than implicit!
        sys.exit(0)

    except KeyboardInterrupt as e:
        log.exception(e)
        sys.exit(3)