Skip to content

Commit

Permalink
matching fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xnetcat committed Aug 19, 2024
1 parent 0b5af7f commit 49dbaec
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
4 changes: 3 additions & 1 deletion spotdl/console/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def sync(
return None

# If the query is a single file, download it
if len(query) == 1 and query[0].endswith(".spotdl") and not save_path:
if (
len(query) == 1 and query[0].endswith(".spotdl") and not save_path
): # pylint: disable=R1702
# Load the sync file
with open(query[0], "r", encoding="utf-8") as sync_file:
sync_data = json.load(sync_file)
Expand Down
6 changes: 4 additions & 2 deletions spotdl/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ def search_lyrics(self, song: Song) -> Optional[str]:

return None

def search_and_download(self, song: Song) -> Tuple[Song, Optional[Path]]:
def search_and_download(
self, song: Song
) -> Tuple[Song, Optional[Path]]: # pylint: disable=R0911
"""
Search for the song and download it.
Expand Down Expand Up @@ -496,7 +498,7 @@ def search_and_download(self, song: Song) -> Tuple[Song, Optional[Path]]:

# If the file already exists and we don't want to overwrite it,
# we can skip the download
if (
if ( # pylint: disable=R1705
Path(str(output_file.absolute()) + ".skip").exists()
and self.settings["respect_skip_file"]
):
Expand Down
2 changes: 1 addition & 1 deletion spotdl/utils/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def create_path_object(string: str) -> Path:


def args_to_ytdlp_options(
argument_list: List[str], defaults: Dict[str, Any]
argument_list: List[str], defaults: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
"""
Convert a list of arguments to a dictionary of options.
Expand Down
27 changes: 26 additions & 1 deletion spotdl/utils/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,31 @@ def artists_match_fixup1(song: Song, result: Result, score: float) -> float:

score = max(score, artist_title_match)

# If artist match is still too low,
# we fallback to matching all song artist names
# with the result's artists
if score <= 70:
# Song artists: ['charlie-moncler', 'fukaj', 'mata', 'pedro']
# Result artists: ['fukaj-mata-charlie-moncler-und-pedro']

# For artist_list1
artist_list1 = []
for artist in song.artists:
artist_list1.extend(slugify(artist).split("-"))

# For artist_list2
artist_list2 = []
if result.artists:
for artist in result.artists:
artist_list2.extend(slugify(artist).split("-"))

artist_tuple1 = tuple(artist_list1)
artist_tuple2 = tuple(artist_list2)

artist_title_match = ratio(artist_tuple1, artist_tuple2)

score = max(score, artist_title_match)

return score


Expand Down Expand Up @@ -680,7 +705,7 @@ def order_results(
artists_match = artists_match / (2 if len(song.artists) > 1 else 1)
debug(song.song_id, result.result_id, f"First artists match: {artists_match}")

# # First attempt to fix artist match
# First attempt to fix artist match
artists_match = artists_match_fixup1(song, result, artists_match)
debug(
song.song_id,
Expand Down

0 comments on commit 49dbaec

Please sign in to comment.