From e5f18f9301a263b7f3326bbc445f39e712e45410 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Sat, 8 Apr 2023 20:26:45 +0300 Subject: [PATCH] use create_hash to compare album titles for is_single + add a few string checks for album.is_single --- app/lib/taglib.py | 1 + app/models/album.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/lib/taglib.py b/app/lib/taglib.py index 9102b99..832f114 100644 --- a/app/lib/taglib.py +++ b/app/lib/taglib.py @@ -68,6 +68,7 @@ def extract_date(date_str: str | None, filepath: str) -> int: try: return int(date_str.split("-")[0]) except: # pylint: disable=bare-except + # TODO: USE FILEPATH LAST-MOD DATE instead of current date return datetime.date.today().today().year diff --git a/app/models/album.py b/app/models/album.py index b01d33c..2c5778f 100644 --- a/app/models/album.py +++ b/app/models/album.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from .track import Track from .artist import Artist +from ..utils.hashing import create_hash @dataclass(slots=True) @@ -105,16 +106,22 @@ class Album: return self.title.strip().endswith(" EP") def check_is_single(self, tracks: list[Track]): + """ Checks if the album is a single. """ + keywords = ["single version", "- single"] + for keyword in keywords: + if keyword in self.title.lower(): + self.is_single = True + return + if ( len(tracks) == 1 - and tracks[0].title.lower() == self.title.lower() - + and create_hash(tracks[0].title) == create_hash(self.title) # if they have the same title # and tracks[0].track == 1 # and tracks[0].disc == 1 - # Todo: Are the above commented checks necessary? + # TODO: Review -> Are the above commented checks necessary? ): self.is_single = True