Skip to content

Commit

Permalink
bugfix: replace rapidfuzz with thefuzz (#1391)
Browse files Browse the repository at this point in the history
* bugfix: replacez rapidfuzz with thefuzz

* misc: run ci on python3.10
  • Loading branch information
xnetcat committed Oct 6, 2021
1 parent 8bc2362 commit bea748b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/spotify-downloader-ci.yml
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Expand Up @@ -31,7 +31,8 @@ install_requires =
spotipy >= 2.19.0
pytube >= 11.0.0
rich
rapidfuzz
thefuzz
thefuzz[speedup]
mutagen
ytmusicapi
yt-dlp
Expand Down
18 changes: 14 additions & 4 deletions 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
Expand All @@ -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
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion 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]
Expand All @@ -19,3 +19,4 @@ python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310

0 comments on commit bea748b

Please sign in to comment.