From ec9f392d737243a3c8d513719de5219609f69014 Mon Sep 17 00:00:00 2001 From: cwilvx Date: Tue, 7 Jan 2025 23:21:31 +0300 Subject: [PATCH] write path hash on image property --- app/api/scrobble/__init__.py | 2 +- app/models/album.py | 2 +- app/models/track.py | 8 +++++--- app/utils/stats.py | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/api/scrobble/__init__.py b/app/api/scrobble/__init__.py index b2d60ccf..65e8b093 100644 --- a/app/api/scrobble/__init__.py +++ b/app/api/scrobble/__init__.py @@ -357,7 +357,7 @@ def get_stats(): else "—" ), ( - tracks[0].image + "?pathhash=" + tracks[0].pathhash + tracks[0].image if len(tracks) > 0 else None ), diff --git a/app/models/album.py b/app/models/album.py index 68147aa3..5a5714bc 100644 --- a/app/models/album.py +++ b/app/models/album.py @@ -54,7 +54,7 @@ class Album: self.fav_userids.append(userid) def __post_init__(self): - self.image = self.albumhash + ".webp" + self.image = self.albumhash + ".webp" + "?pathhash=" + self.pathhash self.populate_versions() self.weakhash = create_hash( self.og_title, ",".join(a["name"] for a in self.albumartists) diff --git a/app/models/track.py b/app/models/track.py index e706487c..9d6958ba 100644 --- a/app/models/track.py +++ b/app/models/track.py @@ -52,12 +52,15 @@ class Track: image: str = "" explicit: bool = False fav_userids: list[int] = field(default_factory=list) - pathhash: str = "" @property def is_favorite(self): return get_current_userid() in self.fav_userids + @property + def pathhash(self): + return create_hash(self.folder) + def toggle_favorite_user(self, userid: int): """ Toggles the favorite status of the track for a given user. @@ -82,9 +85,8 @@ class Track: self.weakhash = create_hash(self.title, self.artists) explicit_tag = self.extra.get("explicit", ["0"]) self.explicit = int(explicit_tag[0]) == 1 - self.pathhash = create_hash(self.folder) - self.image = self.albumhash + ".webp" + self.image = self.albumhash + ".webp" + "?pathhash=" + self.pathhash self.extra = { "disc_total": self.extra.get("disc_total", 0), "track_total": self.extra.get("track_total", 0), diff --git a/app/utils/stats.py b/app/utils/stats.py index 689a4550..97e388ff 100644 --- a/app/utils/stats.py +++ b/app/utils/stats.py @@ -233,7 +233,7 @@ def get_track_group_stats(tracks: list[Track], is_album: bool = False): "toptrack", f"top track ({seconds_to_time_string(top_track.playduration)} listened)", f"{top_track.title}", - top_track.image + "?pathhash=" + top_track.pathhash if top_track else None, + top_track.image if top_track else None, ) if top_track else StatItem( @@ -251,7 +251,7 @@ def get_track_group_stats(tracks: list[Track], is_album: bool = False): "playcount": 0, "playduration": 0, "title": track.album, - "image": track.image + "?pathhash=" + track.pathhash if track.image else None, + "image": track.image if track.image else None, } albums_map[track.albumhash]["playcount"] += 1