def test_download_single_song(setup): song_obj = create_song_obj() DownloadManager().download_single_song(song_obj) assert [ file.basename for file in setup.directory.listdir() if file.isfile() ] == ["test artist - test song.mp3"]
def console_entry_point(): ''' This is where all the console processing magic happens. Its super simple, rudimentary even but, it's dead simple & it works. ''' arguments = parse_arguments() SpotifyClient.init(client_id='4fe3fecfe5334023a1472516cc99d805', client_secret='0f02b7c483c04257984695007a4a8d5c') if arguments.path: if not os.path.isdir(arguments.path): sys.exit("The output directory doesn't exist.") print(f"Will download to: {os.path.abspath(arguments.path)}") os.chdir(arguments.path) with DownloadManager() as downloader: for request in arguments.url: if 'open.spotify.com' in request and 'track' in request: print('Fetching Song...') song = SongObj.from_url(request) if song.get_youtube_link() is not None: downloader.download_single_song(song) else: print( 'Skipping %s (%s) as no match could be found on youtube' % (song.get_song_name(), request)) elif 'open.spotify.com' in request and 'album' in request: print('Fetching Album...') songObjList = get_album_tracks(request) downloader.download_multiple_songs(songObjList) elif 'open.spotify.com' in request and 'playlist' in request: print('Fetching Playlist...') songObjList = get_playlist_tracks(request) downloader.download_multiple_songs(songObjList) elif 'open.spotify.com' in request and 'artist' in request: print('Fetching artist...') artistObjList = get_artist_tracks(request) downloader.download_multiple_songs(artistObjList) elif request.endswith('.spotdlTrackingFile'): print('Preparing to resume download...') downloader.resume_download_from_tracking_file(request) else: print('Searching for song "%s"...' % request) try: song = search_for_song(request) downloader.download_single_song(song) except Exception as e: print(e)
def console_entry_point(): ''' This is where all the console processing magic happens. Its super simple, rudimentary even but, it's dead simple & it works. ''' if '--help' in sys.argv or '-h' in sys.argv or len(sys.argv) == 1: print(help_notice) #! We use 'return None' as a convenient exit/break from the function return None spotifyClient.initialize( clientId='4fe3fecfe5334023a1472516cc99d805', clientSecret='0f02b7c483c04257984695007a4a8d5c' ) downloader = DownloadManager() for request in sys.argv[1:]: if 'open.spotify.com' in request and 'track' in request: print('Fetching Song...') song = SongObj.from_url(request) if song.get_youtube_link() != None: downloader.download_single_song(song) else: print('Skipping %s (%s) as no match could be found on youtube' % ( song.get_song_name(), request )) elif 'open.spotify.com' in request and 'album' in request: print('Fetching Album...') songObjList = get_album_tracks(request) downloader.download_multiple_songs(songObjList) elif 'open.spotify.com' in request and 'playlist' in request: print('Fetching Playlist...') songObjList = get_playlist_tracks(request) downloader.download_multiple_songs(songObjList) elif request.endswith('.spotdlTrackingFile'): print('Preparing to resume download...') downloader.resume_download_from_tracking_file(request) else: print('Searching for song "%s"...' % request) try: song = search_for_song(request) downloader.download_single_song(song) except Exception: print('No song named "%s" could be found on spotify' % request) downloader.close()
def test_download_long_name_song(setup): # ! Generates a long title name,numbered 1 to 260, to trigger filename length cases # ! In this case the program cannot save the song, and fails with an OSError song = "a" * 260 song_obj = create_song_obj(name=song) with pytest.raises(OSError): with DownloadManager() as dm: dm.download_single_song(song_obj)
def test_download_long_artists_song(setup): # ! Generates a long list of artists, numbered 1 to 260, to trigger filename length cases artists = [str(i) for i in range(260)] song_obj = create_song_obj(artists_input=artists) with DownloadManager() as dm: dm.download_single_song(song_obj) assert [ file.basename for file in setup.directory.listdir() if file.isfile() ] == ["0 - test song.mp3"]
def console_entry_point(): """ This is where all the console processing magic happens. Its super simple, rudimentary even but, it's dead simple & it works. """ arguments = parse_arguments() args_dict = vars(arguments) if (ffmpeg.has_correct_version(arguments.ignore_ffmpeg_version, arguments.ffmpeg or "ffmpeg") is False): sys.exit(1) for request in arguments.query: if "saved" == request and not arguments.userAuth: arguments.userAuth = True print( "Detected 'saved' in command line, but no --user-auth flag. Enabling Anyways." ) print("Please Log In...") SpotifyClient.init( client_id="5f573c9620494bae87890c0f08a60293", client_secret="212476d9b0f3472eaa762d90b19b0ba8", user_auth=arguments.userAuth, ) if arguments.path: if not os.path.isdir(arguments.path): sys.exit("The output directory doesn't exist.") print(f"Will download to: {os.path.abspath(arguments.path)}") os.chdir(arguments.path) with DownloadManager(args_dict) as downloader: if not arguments.debug_termination: def gracefulExit(signal, frame): downloader.displayManager.close() sys.exit(0) signal.signal(signal.SIGINT, gracefulExit) signal.signal(signal.SIGTERM, gracefulExit) songObjList = [] for request in arguments.query: if request.endswith(".spotdlTrackingFile"): print("Preparing to resume download...") downloader.resume_download_from_tracking_file(request) else: songObjList.extend( songGatherer.from_query(request, arguments.format)) # linefeed to visually separate output for each query print() if len(songObjList) > 0: downloader.download_multiple_songs(songObjList)
def dlmusic(): Dir=Dirfield.get() url=musfield.get() temp=SongObj.from_url(url) currdir=os.getcwd() os.chdir(Dir) download=DownloadManager() download.download_single_song(songObj=temp) os.remove('./Temp') os.chdir(currdir) return
def download_songs(query: list, loc: str) -> None: init_spotdl(loc.strip("\\").strip("/")) songs = list() with DownloadManager({"ffmpeg_path": get_ffmpeg()}) as dm: for song in query: songs.extend(songGatherer.from_query(song)) if len(songs): dm.download_multiple_songs(songs) if os.path.exists("./Temp"): os.rmdir("./Temp") if os.path.exists("./.cache"): os.remove("./.cache")
def console_entry_point(): ''' This is where all the console processing magic happens. Its super simple, rudimentary even but, it's dead simple & it works. ''' arguments = parse_arguments() if ffmpeg.has_correct_version(arguments.ignore_ffmpeg_version, arguments.ffmpeg or "ffmpeg") is False: sys.exit(1) SpotifyClient.init(client_id='5f573c9620494bae87890c0f08a60293', client_secret='212476d9b0f3472eaa762d90b19b0ba8') if arguments.path: if not os.path.isdir(arguments.path): sys.exit("The output directory doesn't exist.") print(f"Will download to: {os.path.abspath(arguments.path)}") os.chdir(arguments.path) with DownloadManager(arguments.ffmpeg) as downloader: if not arguments.debug_termination: def gracefulExit(signal, frame): downloader.displayManager.close() sys.exit(0) signal.signal(signal.SIGINT, gracefulExit) signal.signal(signal.SIGTERM, gracefulExit) for request in arguments.url: if os.path.isfile(request): print('Processing file ...') try: with open(request) as input: for line in input.readlines(): process_request(downloader, line) except Exception as e: print(e) else: process_request(downloader, request)
def test_download_multiple_songs(pytestconfig, setup): if not "--disable-vcr" in pytestconfig.invocation_params.args: # this test is very similar to the other one, and the http request # seems not deterministic so it can't be reliably capture into cassette, # therefore run this test only when VCR is disabled pytest.skip() song_objs = [ create_song_obj(name="song1"), create_song_obj(name="song2"), create_song_obj(name="song3"), ] DownloadManager().download_multiple_songs(song_objs) assert sorted([ file.basename for file in setup.directory.listdir() if file.isfile() ]) == sorted([ "test artist - song1.mp3", "test artist - song2.mp3", "test artist - song3.mp3", ])
def console_entry_point(): ''' This is where all the console processing magic happens. Its super simple, rudimentary even but, it's dead simple & it works. ''' arguments = parse_arguments() if ffmpeg.has_correct_version(arguments.ignore_ffmpeg_version) is False: sys.exit(1) SpotifyClient.init(client_id='5f573c9620494bae87890c0f08a60293', client_secret='212476d9b0f3472eaa762d90b19b0ba8') if arguments.path: if not os.path.isdir(arguments.path): sys.exit("The output directory doesn't exist.") print(f"Will download to: {os.path.abspath(arguments.path)}") os.chdir(arguments.path) with DownloadManager() as downloader: for request in arguments.url: if 'open.spotify.com' in request and 'track' in request: print('Fetching Song...') song = SongObj.from_url(request) if song.get_youtube_link() is not None: downloader.download_single_song(song) else: print( 'Skipping %s (%s) as no match could be found on youtube' % (song.get_song_name(), request)) elif 'open.spotify.com' in request and 'album' in request: print('Fetching Album...') songObjList = get_album_tracks(request) downloader.download_multiple_songs(songObjList) elif 'open.spotify.com' in request and 'playlist' in request: print('Fetching Playlist...') songObjList = get_playlist_tracks(request) downloader.download_multiple_songs(songObjList) elif 'open.spotify.com' in request and 'artist' in request: print('Fetching artist...') artistObjList = get_artist_tracks(request) downloader.download_multiple_songs(artistObjList) elif request.endswith('.spotdlTrackingFile'): print('Preparing to resume download...') downloader.resume_download_from_tracking_file(request) else: print('Searching for song "%s"...' % request) try: song = search_for_song(request) downloader.download_single_song(song) except Exception as e: print(e)
def console_entry_point(): ''' This is where all the console processing magic happens. Its super simple, rudimentary even but, it's dead simple & it works. ''' if '--help' in cliArgs or '-h' in cliArgs: print(help_notice) #! We use 'return None' as a convenient exit/break from the function return None if '--quiet' in cliArgs: #! removing --quiet so it doesnt mess up with the download cliArgs.remove('--quiet') #! make stdout & stderr silent sys.stdout = quiet() sys.stderr = quiet() initialize(clientId='4fe3fecfe5334023a1472516cc99d805', clientSecret='0f02b7c483c04257984695007a4a8d5c') downloader = DownloadManager() for request in cliArgs[1:]: if ('open.spotify.com' in request and 'track' in request) or 'spotify:track:' in request: print('Fetching Song...') song = SongObj.from_url(request) if song.get_youtube_link() != None: downloader.download_single_song(song) else: print( 'Skipping %s (%s) as no match could be found on youtube' % (song.get_song_name(), request)) elif ('open.spotify.com' in request and 'album' in request) or 'spotify:album:' in request: print('Fetching Album...') songObjList = get_album_tracks(request) downloader.download_multiple_songs(songObjList) elif ('open.spotify.com' in request and 'playlist' in request) or 'spotify:playlist:' in request: print('Fetching Playlist...') songObjList = get_playlist_tracks(request) downloader.download_multiple_songs(songObjList) elif request.endswith('.txt'): print('Fetching songs from %s...' % request) songObjList = [] with open(request, 'r') as songFile: for songLink in songFile.readlines(): song = SongObj.from_url(songLink) songObjList.append(song) downloader.download_multiple_songs(songObjList) elif request.endswith('.spotdlTrackingFile'): print('Preparing to resume download...') downloader.resume_download_from_tracking_file(request) else: print('Searching for song "%s"...' % request) try: song = search_for_song(request) downloader.download_single_song(song) except Exception: print('No song named "%s" could be found on spotify' % request) downloader.close()
def console_entry_point(): ''' This is where all the console processing magic happens. Its super simple, rudimentary even but, it's dead simple & it works. ''' arguments = parse_arguments() spotifyClient.initialize(clientId='03eb56e5ab2843e98507b3a6a0359a56', clientSecret='4e6600fae80845ef8dab67ccaaecee4d') if arguments.path: if not os.path.isdir(arguments.path): sys.exit("The output directory doesn't exist.") print(f"Will download to: {os.path.abspath(arguments.path)}") os.chdir(arguments.path) downloader = DownloadManager() for request in arguments.url: if 'open.spotify.com' in request and 'track' in request: print('Fetching Song...') song = SongObj.from_url(request) if song.get_youtube_link() is not None: downloader.download_single_song(song) else: print( 'Skipping %s (%s) as no match could be found on youtube' % (song.get_song_name(), request)) elif 'open.spotify.com' in request and 'album' in request: print('Fetching Album...') songObjList = get_album_tracks(request) downloader.download_multiple_songs(songObjList) elif 'open.spotify.com' in request and 'playlist' in request: print('Fetching Playlist...') songObjList = get_playlist_tracks(request) downloader.download_multiple_songs(songObjList) elif 'open.spotify.com' in request and 'artist' in request: print('Fetching artist...') artistObjList = get_artist_tracks(request) downloader.download_multiple_songs(artistObjList) elif request.endswith('.spotdlTrackingFile'): print('Preparing to resume download...') downloader.resume_download_from_tracking_file(request) else: print('Searching for song "%s"...' % request) try: song = search_for_song(request) downloader.download_single_song(song) except Exception: print('No song named "%s" could be found on spotify' % request) downloader.close()
def console_entry_point(): """ This is where all the console processing magic happens. Its super simple, rudimentary even but, it's dead simple & it works. """ if "--help" in cliArgs or "-h" in cliArgs: print(help_notice) #! We use 'return None' as a convenient exit/break from the function return None initialize( clientId="4fe3fecfe5334023a1472516cc99d805", clientSecret="0f02b7c483c04257984695007a4a8d5c", ) downloader = DownloadManager() for request in cliArgs[1:]: if "?" in request: # strip unnecessary data for both url and uri # e.g https://open.spotify.com/track/4Q34FP1AT7GEl9oLgNtiWj?context=spotify%3Aplaylist%3A37i9dQZF1DXcBWIGoYBM5M&si=DlMAsJ5pSD6tdUSn2XqB0g # becomes https://open.spotify.com/track/4Q34FP1AT7GEl9oLgNtiWj # e.g spotify:track:4Q34FP1AT7GEl9oLgNtiWj?context=spotify%3Aplaylist%3A37i9dQZF1DXcBWIGoYBM5M # becomes spotify:track:4Q34FP1AT7GEl9oLgNtiWj request = request[:request.find("?")] if "open.spotify.com" in request: # it's a url if "track" in request: print("Fetching Song...") song = SongObj.from_url(request) if song.get_youtube_link() != None: downloader.download_single_song(song) else: print( "Skipping %s (%s) as no match could be found on youtube" % (song.get_song_name(), request)) elif "album" in request: print("Fetching Album...") songObjList = get_album_tracks(request) downloader.download_multiple_songs(songObjList) elif "playlist" in request: print("Fetching Playlist...") songObjList = get_playlist_tracks(request) downloader.download_multiple_songs(songObjList) elif "spotify:" in request: # it's a URI with format Spotify:...:ID if "track:" in request: print("Fetching Song...") # yes, passing a URI to this function still works coz it relies on another # spotipy function that simply extracts the ID, ideally u can just pass the ID # and the track downloads song = SongObj.from_url(request) if song.get_youtube_link() != None: downloader.download_single_song(song) else: print( f"Skipping {song.get_song_name()} ({request}) as no match could be found on youtube" ) elif "album:" in request: print("Fetching Album...") songObjList = get_album_tracks(request) downloader.download_multiple_songs(songObjList) elif "playlist:" in request: print("Fetching Playlist...") songObjList = get_playlist_tracks(request) downloader.download_multiple_songs(songObjList) elif request.endswith(".spotdlTrackingFile"): print("Preparing to resume download...") downloader.resume_download_from_tracking_file(request) else: print('Searching for song "%s"...' % request) try: song = search_for_song(request) downloader.download_single_song(song) except Exception: print('No song named "%s" could be found on spotify' % request) downloader.close()