From 6721fb378e448172fae858fe2777f52aeca28399 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Fri, 15 Sep 2023 08:03:19 +0200 Subject: [PATCH] deezerart: Use astrcmp instead of difflib This provides both better comparison and also makes the plugin compatible with Picard packaged for Windows / macOS (where difflib is not included). --- plugins/deezerart/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/deezerart/__init__.py b/plugins/deezerart/__init__.py index 64728dd3..63a015fa 100644 --- a/plugins/deezerart/__init__.py +++ b/plugins/deezerart/__init__.py @@ -6,7 +6,6 @@ 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 @@ -14,6 +13,7 @@ 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 @@ -21,12 +21,13 @@ __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: