Skip to content

Commit bea748b

Browse files
authored
bugfix: replace rapidfuzz with thefuzz (spotDL#1391)
* bugfix: replacez rapidfuzz with thefuzz * misc: run ci on python3.10
1 parent 8bc2362 commit bea748b

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

.github/workflows/spotify-downloader-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
max-parallel: 4
1313
matrix:
1414
platform: [ ubuntu-latest, macos-latest, windows-latest ]
15-
python-version: [ 3.6.7, 3.7, 3.8, 3.9 ]
15+
python-version: [ 3.6.7, 3.7, 3.8, 3.9, 3.10.0 ]
1616

1717
steps:
1818
- uses: actions/checkout@v2

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ install_requires =
3131
spotipy >= 2.19.0
3232
pytube >= 11.0.0
3333
rich
34-
rapidfuzz
34+
thefuzz
35+
thefuzz[speedup]
3536
mutagen
3637
ytmusicapi
3738
yt-dlp

spotdl/providers/provider_utils.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import requests
22

33
from typing import List
4-
from rapidfuzz import fuzz
4+
from thefuzz import fuzz
55
from bs4 import BeautifulSoup
66
from pathlib import Path
77

88

99
def _match_percentage(str1: str, str2: str, score_cutoff: float = 0) -> float:
1010
"""
11-
A wrapper around `rapidfuzz.fuzz.partial_ratio` to handle UTF-8 encoded
11+
A wrapper around `thefuzz.fuzz.partial_ratio` to handle UTF-8 encoded
1212
emojis that usually cause errors
1313
1414
`str` `str1` : a random sentence
@@ -21,7 +21,12 @@ def _match_percentage(str1: str, str2: str, score_cutoff: float = 0) -> float:
2121

2222
# ! this will throw an error if either string contains a UTF-8 encoded emoji
2323
try:
24-
return fuzz.partial_ratio(str1, str2, score_cutoff=score_cutoff)
24+
partial_ratio = fuzz.partial_ratio(str1, str2)
25+
26+
if partial_ratio < score_cutoff:
27+
return 0
28+
29+
return partial_ratio
2530

2631
# ! we build new strings that contain only alphanumerical characters and spaces
2732
# ! and return the partial_ratio of that
@@ -38,7 +43,12 @@ def _match_percentage(str1: str, str2: str, score_cutoff: float = 0) -> float:
3843
if each_letter.isalnum() or each_letter.isspace()
3944
)
4045

41-
return fuzz.partial_ratio(new_str1, new_str2, score_cutoff=score_cutoff)
46+
partial_ratio = fuzz.partial_ratio(new_str1, new_str2)
47+
48+
if partial_ratio < score_cutoff:
49+
return 0
50+
51+
return partial_ratio
4252

4353

4454
def _parse_duration(duration: str) -> float:

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py36,py37,py38,py39,mypy,flake8
2+
envlist = py36,py37,py38,py39,py310,mypy,flake8
33

44
[testenv]
55
deps = .[test]
@@ -19,3 +19,4 @@ python =
1919
3.7: py37
2020
3.8: py38
2121
3.9: py39
22+
3.10: py310

0 commit comments

Comments
 (0)