diff --git a/.github/workflows/spotify-downloader-ci.yml b/.github/workflows/spotify-downloader-ci.yml index c0741a5ae..2cc7a1c43 100644 --- a/.github/workflows/spotify-downloader-ci.yml +++ b/.github/workflows/spotify-downloader-ci.yml @@ -12,7 +12,7 @@ jobs: max-parallel: 4 matrix: platform: [ ubuntu-latest, macos-latest, windows-latest ] - python-version: [ 3.6.7, 3.7, 3.8, 3.9 ] + python-version: [ 3.6.7, 3.7, 3.8, 3.9, 3.10.0 ] steps: - uses: actions/checkout@v2 diff --git a/setup.cfg b/setup.cfg index 27361f449..ae62d18c8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,8 @@ install_requires = spotipy >= 2.19.0 pytube >= 11.0.0 rich - rapidfuzz + thefuzz + thefuzz[speedup] mutagen ytmusicapi yt-dlp diff --git a/spotdl/providers/provider_utils.py b/spotdl/providers/provider_utils.py index 0cb656ed4..9ba01c6e9 100644 --- a/spotdl/providers/provider_utils.py +++ b/spotdl/providers/provider_utils.py @@ -1,14 +1,14 @@ import requests from typing import List -from rapidfuzz import fuzz +from thefuzz import fuzz from bs4 import BeautifulSoup from pathlib import Path def _match_percentage(str1: str, str2: str, score_cutoff: float = 0) -> float: """ - A wrapper around `rapidfuzz.fuzz.partial_ratio` to handle UTF-8 encoded + A wrapper around `thefuzz.fuzz.partial_ratio` to handle UTF-8 encoded emojis that usually cause errors `str` `str1` : a random sentence @@ -21,7 +21,12 @@ def _match_percentage(str1: str, str2: str, score_cutoff: float = 0) -> float: # ! this will throw an error if either string contains a UTF-8 encoded emoji try: - return fuzz.partial_ratio(str1, str2, score_cutoff=score_cutoff) + partial_ratio = fuzz.partial_ratio(str1, str2) + + if partial_ratio < score_cutoff: + return 0 + + return partial_ratio # ! we build new strings that contain only alphanumerical characters and spaces # ! and return the partial_ratio of that @@ -38,7 +43,12 @@ def _match_percentage(str1: str, str2: str, score_cutoff: float = 0) -> float: if each_letter.isalnum() or each_letter.isspace() ) - return fuzz.partial_ratio(new_str1, new_str2, score_cutoff=score_cutoff) + partial_ratio = fuzz.partial_ratio(new_str1, new_str2) + + if partial_ratio < score_cutoff: + return 0 + + return partial_ratio def _parse_duration(duration: str) -> float: diff --git a/tox.ini b/tox.ini index 9b732f488..fa71bde91 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py36,py37,py38,py39,mypy,flake8 +envlist = py36,py37,py38,py39,py310,mypy,flake8 [testenv] deps = .[test] @@ -19,3 +19,4 @@ python = 3.7: py37 3.8: py38 3.9: py39 + 3.10: py310