add is_soundtrack and is_compilation flags to album objects

This commit is contained in:
geoffrey45
2022-06-07 16:47:44 +03:00
parent 4e1e1b8979
commit e75ac3e394
2 changed files with 22 additions and 4 deletions
+20 -4
View File
@@ -86,25 +86,41 @@ class Album:
hash: str hash: str
count: int = 0 count: int = 0
duration: int = 0 duration: int = 0
is_soundtrack: bool = False
is_compilation: bool = False
def __init__(self, tags): def __init__(self, tags):
self.title = tags["title"] self.title = tags["title"]
self.artist = tags["artist"] self.artist = tags["artist"]
self.date = tags["date"] self.date = tags["date"]
self.image = tags["image"] self.image = tags["image"]
self.hash = helpers.create_album_hash(self.title, self.artist)
try: try:
self.hash = tags["albumhash"] self.hash = tags["albumhash"]
except KeyError: except KeyError:
self.hash = helpers.create_album_hash(self.title, self.artist) self.hash = helpers.create_album_hash(self.title, self.artist)
@property
def is_soundtrack(self) -> bool:
keywords = ["motion picture", "soundtrack"]
for keyword in keywords:
if keyword in self.title.lower():
return True
return False
@property
def is_compilation(self) -> bool:
return self.artist.lower() == "various artists"
def get_p_track(ptrack): def get_p_track(ptrack):
for track in api.TRACKS: for track in api.TRACKS:
if (track.title == ptrack["title"] if (
and track.artists == ptrack["artists"] track.title == ptrack["title"]
and ptrack["album"] == track.album): and track.artists == ptrack["artists"]
and ptrack["album"] == track.album
):
return track return track
+2
View File
@@ -31,6 +31,8 @@ interface AlbumInfo {
duration: number; duration: number;
date: string; date: string;
image: string; image: string;
is_compilation: boolean;
is_soundtrack: boolean;
} }
interface Artist { interface Artist {