예제 #1
0
    def match_arguments(self):
        logger.debug("Received arguments:\n{}".format(self.arguments))

        if self.arguments["remove_config"]:
            self.remove_saved_config()
            return 0
        self.save_default_config()

        spotify_tools = SpotifyHelpers()
        if self.arguments["song"]:
            for track in self.arguments["song"]:
                if track == "-":
                    for line in sys.stdin:
                        self.download_track(
                            line.strip(),
                        )
                else:
                    self.download_track(track)
        elif self.arguments["list"]:
            if self.arguments["write_m3u"]:
                self.write_m3u(
                    self.arguments["list"],
                    self.arguments["write_to"]
                )
            else:
                list_download = {
                    "synchronous": self.download_tracks_from_file,
                    # "threaded"  : self.download_tracks_from_file_threaded,
                }[self.arguments["processor"]]

                list_download(
                    self.arguments["list"],
                )
        elif self.arguments["playlist"]:
            try:
                playlist = spotify_tools.fetch_playlist(self.arguments["playlist"])
            except spotdl.helpers.exceptions.PlaylistNotFoundError:
                return spotdl.command_line.exitcodes.URI_NOT_FOUND_ERROR
            else:
                spotify_tools.write_playlist_tracks(playlist, self.arguments["write_to"])
        elif self.arguments["album"]:
            try:
                album = spotify_tools.fetch_album(self.arguments["album"])
            except spotdl.helpers.exceptions.AlbumNotFoundError:
                return spotdl.command_line.exitcodes.URI_NOT_FOUND_ERROR
            else:
                spotify_tools.write_album_tracks(album, self.arguments["write_to"])
        elif self.arguments["all_albums"]:
            try:
                albums = spotify_tools.fetch_albums_from_artist(self.arguments["all_albums"])
            except spotdl.helpers.exceptions.ArtistNotFoundError:
                return spotdl.command_line.exitcodes.URI_NOT_FOUND_ERROR
            else:
                spotify_tools.write_all_albums(albums, self.arguments["write_to"])
        elif self.arguments["username"]:
            try:
                playlist_url = spotify_tools.prompt_for_user_playlist(self.arguments["username"])
            except spotdl.helpers.exceptions.UserNotFoundError:
                return spotdl.command_line.exitcodes.URI_NOT_FOUND_ERROR
            else:
                playlist = spotify_tools.fetch_playlist(playlist_url)
                spotify_tools.write_playlist_tracks(playlist, self.arguments["write_to"])
예제 #2
0
    def match_arguments(self):
        logger.debug("Received arguments:\n{}".format(self.arguments))

        if self.arguments["remove_config"]:
            self.remove_saved_config()
            return
        self.save_default_config()

        AuthorizeSpotify(client_id=self.arguments["spotify_client_id"],
                         client_secret=self.arguments["spotify_client_secret"])
        spotify_tools = SpotifyHelpers()
        if self.arguments["song"]:
            for track in self.arguments["song"]:
                if track == "-":
                    for line in sys.stdin:
                        self.download_track(line.strip(), )
                else:
                    self.download_track(track)
        elif self.arguments["list"]:
            if self.arguments["write_m3u"]:
                self.write_m3u(self.arguments["list"],
                               self.arguments["write_to"])
            else:
                list_download = {
                    "synchronous": self.download_tracks_from_file,
                    # "threaded"  : self.download_tracks_from_file_threaded,
                }[self.arguments["processor"]]

                list_download(self.arguments["list"], )
        elif self.arguments["playlist"]:
            playlist = spotify_tools.fetch_playlist(self.arguments["playlist"])
            spotify_tools.write_playlist_tracks(playlist,
                                                self.arguments["write_to"])
        elif self.arguments["album"]:
            album = spotify_tools.fetch_album(self.arguments["album"])
            spotify_tools.write_album_tracks(album, self.arguments["write_to"])
        elif self.arguments["all_albums"]:
            albums = spotify_tools.fetch_albums_from_artist(
                self.arguments["all_albums"])
            spotify_tools.write_all_albums(albums, self.arguments["write_to"])
        elif self.arguments["username"]:
            playlist_url = spotify_tools.prompt_for_user_playlist(
                self.arguments["username"])
            playlist = spotify_tools.fetch_playlist(playlist_url)
            spotify_tools.write_playlist_tracks(playlist,
                                                self.arguments["write_to"])
예제 #3
0
        u_client_secret = input("Enter your client secret:")

        # Keys will be saved for the future in a local text file
        with open("spotify_keys.txt", "w") as keys:
            keys.writelines([u_client_id + "\n", u_client_secret])
        print(BColors.OKGREEN +
              "Success: Your keys were saved for future use!" + BColors.ENDC)

    else:
        print(BColors.WARNING +
              "Warning: Cannot proceed without the keys! Exiting Now..." + BColors.ENDC)
        sys.exit()
except:
    raise

helper_instance = SpotifyHelpers(spotify=AuthorizeSpotify(
    client_id=u_client_id, client_secret=u_client_secret))
spotdl_instance = Spotdl()


def logs():
    print(util.install_logger(level='INFO'))


log = Thread(target=logs)


def song(link):
    log.start()

    def download():
        spotdl_instance.download_track(link)
예제 #4
0
        print("Spotify track link should look like this: https://open.spotify.com/track/<gibberish-code>")
        url = str(input("Enter your song url: "))
        with Spotdl(args) as spotdl_handler:
            spotdl_handler.download_track(url)
        ch = str(input("Want to exit the program? Press[y/N]: "))
        if ch == 'y' or ch == 'Y':
            break
        else:
            continue

    if inp == 2:
        print("You pressed 2!")
        print("Spotify track link should look like this: https://open.spotify.com/album/<gibberish-code>")
        url = str(input("Enter your album url: "))
        with Spotdl() as spotdl_handler:
            spotify_tools = SpotifyHelpers()
            all_songs = spotify_tools.fetch_album(url)
            print(all_songs['name'] + ' - ' + all_songs['label'])
            spotify_tools.write_album_tracks(all_songs, file_name)
            spotdl_handler.download_tracks_from_file(file_name)
            os.system('del ' + file_name)
        ch = str(input("Want to exit the program? Press[y/N]: "))
        if ch == 'y' or ch == 'Y':
            break
        else:
            continue

    if inp == 3:
        print("You pressed 3!")
        print("Spotify track link should look like this: https://open.spotify.com/playlist/<gibberish-code>")
        url = str(input("Enter your album url: "))