From 150d8b0b81404581c1271b8196ef34e93f28f8b2 Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Sun, 10 May 2020 18:52:50 +0530 Subject: [PATCH] Search format enhancements --- CHANGES.md | 6 ++++-- spotdl/command_line/arguments.py | 5 ++++- spotdl/metadata/providers/youtube.py | 2 +- spotdl/metadata_search.py | 13 ++----------- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4dcb88a..58c2c73 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -31,14 +31,16 @@ All the below changes were made as a part of #690. - Display a combined *download & encode* progress bar. ### Changed -- **[Breaking]** Tracks are now downloaded in the current working directory (instead of Music directory) - by default. +- **[Breaking]** Tracks are now downloaded in the current working directory (instead of + user's Music directory) by default. - **[Breaking]** Short for `--album` is now `-a` instead of `-b`. - **[Breaking]** Short for `--all-albums` is now `-aa` instead of `-ab`. - Allow "&" character in filenames. - **[Breaking]** Merge parameters `-ff` and `-f` to `-f` (`--output-file`). - **[Breaking]** Do not prefix formats with a dot when specifying `-i` and `-o` parameters Such as `-o .mp3` is now written as `-o mp3`. +- **[Breaking]** Search format now uses hyphen for word break instead of underscore. Such as + `-sf "{artist} - {track_name}"` is now written as `-sf "{artist} - {track-name}"`. - Partial re-write and internal API refactor. - Enhance debug log output readability. - Internally adapt to latest changes made in Spotipy library. diff --git a/spotdl/command_line/arguments.py b/spotdl/command_line/arguments.py index e9160c8..2389c09 100644 --- a/spotdl/command_line/arguments.py +++ b/spotdl/command_line/arguments.py @@ -153,6 +153,7 @@ def get_arguments(argv=None, base_config_file=spotdl.config.default_config_file) default=config["output_file"], help="path where to write the downloaded track to, special tags " "are to be surrounded by curly braces. Possible tags: " + # TODO: Add possible tags # "{}".format([spotdl.util.formats[x] for x in spotdl.util.formats]), ) parser.add_argument( @@ -167,6 +168,7 @@ def get_arguments(argv=None, base_config_file=spotdl.config.default_config_file) default=config["search_format"], help="search format to search for on YouTube, special tags " "are to be surrounded by curly braces. Possible tags: " + # TODO: Add possible tags # "{}".format([spotdl.util.formats[x] for x in spotdl.util.formats]), ) parser.add_argument( @@ -198,7 +200,8 @@ def get_arguments(argv=None, base_config_file=spotdl.config.default_config_file) "-ns", "--no-spaces", default=config["no_spaces"], - help="replace spaces with underscores in file names", + help="replace spaces in metadata values with underscores when " + "generating filenames", action="store_true", ) parser.add_argument( diff --git a/spotdl/metadata/providers/youtube.py b/spotdl/metadata/providers/youtube.py index 6deeb2d..c25616d 100644 --- a/spotdl/metadata/providers/youtube.py +++ b/spotdl/metadata/providers/youtube.py @@ -111,7 +111,7 @@ class YouTubeSearch: def search(self, query, limit=10, retries=5): """ Search and scrape YouTube to return a list of matching videos. """ search_url = self.generate_search_url(query) - logger.debug('Fetching YouTube results for "{}".'.format(search_url)) + logger.debug('Fetching YouTube results for "{}" at "{}".'.format(query, search_url)) html = self._fetch_response_html(search_url) videos = self._fetch_search_results(html, limit=limit) to_retry = retries > 0 and self._is_server_side_invalid_response(videos, html) diff --git a/spotdl/metadata_search.py b/spotdl/metadata_search.py index 89762d3..a1964b4 100644 --- a/spotdl/metadata_search.py +++ b/spotdl/metadata_search.py @@ -181,10 +181,6 @@ class MetadataSearch: def _on_youtube_and_spotify_for_type_spotify(self): logger.debug("Extracting YouTube and Spotify metadata for input Spotify URI.") spotify_metadata = self._on_spotify_for_type_spotify(self.track) - lyric_query = spotdl.metadata.format_string( - "{artist} - {track-name}", - spotify_metadata, - ) search_query = spotdl.metadata.format_string(self.yt_search_format, spotify_metadata) youtube_video = self._best_on_youtube_search_for_type_spotify(search_query) youtube_metadata = self.providers["youtube"].from_url(youtube_video["url"]) @@ -197,7 +193,7 @@ class MetadataSearch: def _on_youtube_and_spotify_for_type_youtube(self): logger.debug("Extracting YouTube and Spotify metadata for input YouTube URL.") youtube_metadata = self._on_youtube_for_type_youtube(self.track) - search_query = spotdl.metadata.format_string(self.yt_search_format, youtube_metadata) + search_query = spotdl.metadata.format_string("{track-name}", youtube_metadata) spotify_metadata = self._on_spotify_for_type_query(search_query) metadata = spotdl.util.merge( youtube_metadata, @@ -208,7 +204,6 @@ class MetadataSearch: def _on_youtube_and_spotify_for_type_query(self): logger.debug("Extracting YouTube and Spotify metadata for input track query.") search_query = self.track - lyric_query = search_query # Make use of threads here to search on both YouTube & Spotify # at the same time. spotify_metadata = spotdl.util.ThreadWithReturnValue( @@ -226,10 +221,6 @@ class MetadataSearch: def _on_youtube_for_type_spotify(self): logger.debug("Extracting YouTube metadata for input Spotify URI.") spotify_metadata = self._on_spotify_for_type_spotify(self.track) - lyric_query = spotdl.metadata.format_string( - "{artist} - {track-name}", - spotify_metadata, - ) search_query = spotdl.metadata.format_string(self.yt_search_format, spotify_metadata) youtube_video = self._best_on_youtube_search_for_type_spotify(search_query) youtube_metadata = self.providers["youtube"].from_url(youtube_video["url"]) @@ -249,7 +240,7 @@ class MetadataSearch: def _on_spotify_for_type_youtube(self, url): logger.debug("Extracting Spotify metadata for input YouTube URL.") youtube_metadata = self.providers["youtube"].from_url(url) - search_query = spotdl.metadata.format_string(self.yt_search_format, youtube_metadata) + search_query = spotdl.metadata.format_string("{track-name}", youtube_metadata) spotify_metadata = self.providers["spotify"].from_query(search_query) return spotify_metadata