Skip to content

Commit

Permalink
deezerart: Use astrcmp instead of difflib
Browse files Browse the repository at this point in the history
This provides both better comparison and also makes the plugin compatible
with Picard packaged for Windows / macOS (where difflib is not included).
  • Loading branch information
phw committed Sep 15, 2023
1 parent 340178b commit 6721fb3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions plugins/deezerart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@
PLUGIN_LICENSE = "GPL-3.0-or-later"
PLUGIN_LICENSE_URL = "https://www.gnu.org/licenses/gpl-3.0.html"

from difflib import SequenceMatcher
from typing import Any, List, Optional
from urllib.parse import urlsplit

import picard
from picard import config
from picard.coverart import providers
from picard.coverart.image import CoverArtImage
from picard.util.astrcmp import astrcmp
from PyQt5 import QtNetwork as QtNet

from .deezer import Client, SearchOptions, obj
from .options import Ui_Form

__version__ = PLUGIN_VERSION

MIN_SIMILARITY_THRESHOLD = 0.65


def is_similar(str1: str, str2: str) -> bool:
if str1 in str2:
return True
# Python doc considers a ratio equal to 0.6 a good match.
return SequenceMatcher(None, str1, str2).quick_ratio() >= 0.65
return astrcmp(str1, str2) >= MIN_SIMILARITY_THRESHOLD


def is_deezer_url(url: str) -> bool:
Expand Down

0 comments on commit 6721fb3

Please sign in to comment.