예제 #1
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"])
예제 #2
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"])