From 01292298b9963028b0e3e11cb0f41bc6ccea7bdb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 3 Jul 2024 08:44:33 +0200 Subject: [PATCH] Bump ruff from 0.4.10 to 0.5.0 (#1430) * Bump ruff from 0.4.10 to 0.5.0 Bumps [ruff](https://github.com/astral-sh/ruff) from 0.4.10 to 0.5.0. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](https://github.com/astral-sh/ruff/compare/v0.4.10...0.5.0) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:production update-type: version-update:semver-minor ... --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Marcel van der Veldt --- music_assistant/common/helpers/util.py | 4 ++-- music_assistant/common/models/config_entries.py | 4 ++-- music_assistant/common/models/media_items.py | 5 +---- music_assistant/server/helpers/compare.py | 15 +++++---------- pyproject.toml | 2 +- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/music_assistant/common/helpers/util.py b/music_assistant/common/helpers/util.py index 62b5c433..cdc4f1c0 100644 --- a/music_assistant/common/helpers/util.py +++ b/music_assistant/common/helpers/util.py @@ -21,8 +21,8 @@ keyword_pattern = re.compile("title=|artist=") title_pattern = re.compile(r"title=\"(?P.*?)\"") artist_pattern = re.compile(r"artist=\"(?P<artist>.*?)\"") dot_com_pattern = re.compile(r"(?P<netloc>\(?\w+\.(?:\w+\.)?(\w{2,3})\)?)") -ad_pattern = re.compile(r"((ad|advertisement)_)|^AD\s\d+$|ADBREAK", flags=re.I) -title_artist_order_pattern = re.compile(r"(?P<title>.+)\sBy:\s(?P<artist>.+)", flags=re.I) +ad_pattern = re.compile(r"((ad|advertisement)_)|^AD\s\d+$|ADBREAK", flags=re.IGNORECASE) +title_artist_order_pattern = re.compile(r"(?P<title>.+)\sBy:\s(?P<artist>.+)", flags=re.IGNORECASE) multi_space_pattern = re.compile(r"\s{2,}") end_junk_pattern = re.compile(r"(.+?)(\s\W+)$") diff --git a/music_assistant/common/models/config_entries.py b/music_assistant/common/models/config_entries.py index 27ccf59d..7dc60b1d 100644 --- a/music_assistant/common/models/config_entries.py +++ b/music_assistant/common/models/config_entries.py @@ -146,10 +146,10 @@ class ConfigEntry(DataClassDictMixin): value = self.label if not isinstance(value, expected_type): # handle common conversions/mistakes - if expected_type == float and isinstance(value, int): + if expected_type is float and isinstance(value, int): self.value = float(value) return self.value - if expected_type == int and isinstance(value, float): + if expected_type is int and isinstance(value, float): self.value = int(value) return self.value for val_type in (int, float): diff --git a/music_assistant/common/models/media_items.py b/music_assistant/common/models/media_items.py index d271b111..28a3a4cd 100644 --- a/music_assistant/common/models/media_items.py +++ b/music_assistant/common/models/media_items.py @@ -415,6 +415,7 @@ class Album(MediaItem): class Track(MediaItem): """Model for a track.""" + __hash__ = _MediaItemBase.__hash__ __eq__ = _MediaItemBase.__eq__ media_type: MediaType = MediaType.TRACK @@ -425,10 +426,6 @@ class Track(MediaItem): disc_number: int | None = None # required for album tracks track_number: int | None = None # required for album tracks - def __hash__(self) -> int: - """Return custom hash.""" - return hash((self.provider, self.item_id)) - @property def has_chapters(self) -> bool: """ diff --git a/music_assistant/server/helpers/compare.py b/music_assistant/server/helpers/compare.py index 38f3c391..69289060 100644 --- a/music_assistant/server/helpers/compare.py +++ b/music_assistant/server/helpers/compare.py @@ -192,16 +192,13 @@ def compare_track( for track_album in track_albums: if compare_album(track_album, compare_item.album, False): return True - # edge case: albumless track - if ( + # accept last resort: albumless track and (near) exact duration + # otherwise fail all other cases + return ( base_item.album is None and compare_item.album is None and abs(base_item.duration - compare_item.duration) <= 1 - ): - return True - - # all efforts failed, this is NOT a match - return False + ) def compare_playlist( @@ -384,9 +381,7 @@ def loose_compare_strings(base: str, alt: str) -> bool: alt_comp = create_safe_string(alt) if base_comp in alt_comp: return True - if alt_comp in base_comp: - return True - return False + return alt_comp in base_comp def compare_strings(str1: str, str2: str, strict: bool = True) -> bool: diff --git a/pyproject.toml b/pyproject.toml index 28c16849..58232821 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,7 @@ test = [ "pytest-cov==5.0.0", "syrupy==4.6.1", "tomli==2.0.1", - "ruff==0.4.10", + "ruff==0.5.0", ] [project.scripts] -- 2.34.1