def test_playlist(tmpdir): expect_tracks = 14 text_file = os.path.join(str(tmpdir), 'test_pl.txt') spotify_tools.write_playlist('https://open.spotify.com/user/alex/playlist/0iWOVoumWlkXIrrBTSJmN8', text_file) with open(text_file, 'r') as tin: tracks = len(tin.readlines()) assert tracks == expect_tracks
def grab_playlist(playlist): if '/' in playlist: if playlist.endswith('/'): playlist = playlist[:-1] splits = playlist.split('/') else: splits = playlist.split(':') try: username = splits[-3] except IndexError: # Wrong format, in either case log.error('The provided playlist URL is not in a recognized format!') sys.exit(10) playlist_id = splits[-1] try: spotify_tools.write_playlist(username, playlist_id) except spotipy.client.SpotifyException: log.error('Unable to find playlist') log.info('Make sure the playlist is set to publicly visible and then try again') sys.exit(11)
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)
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)
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)