mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-07 03:35:35 +00:00
add methods to extract base album title from an album title string
+ add methods to extract album versions + implement these methods in the album model class
This commit is contained in:
parent
1fc340cb95
commit
3d5ee855d8
@ -4,7 +4,7 @@ from dataclasses import dataclass
|
|||||||
from .track import Track
|
from .track import Track
|
||||||
from .artist import Artist
|
from .artist import Artist
|
||||||
from ..utils.hashing import create_hash
|
from ..utils.hashing import create_hash
|
||||||
from ..utils.parsers import parse_feat_from_title
|
from ..utils.parsers import parse_feat_from_title, get_base_title_and_versions
|
||||||
|
|
||||||
from app.settings import FromFlags
|
from app.settings import FromFlags
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ class Album:
|
|||||||
is_favorite: bool = False
|
is_favorite: bool = False
|
||||||
is_live: bool = False
|
is_live: bool = False
|
||||||
genres: list[str] = dataclasses.field(default_factory=list)
|
genres: list[str] = dataclasses.field(default_factory=list)
|
||||||
|
versions: list[str] = dataclasses.field(default_factory=list)
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
self.og_title = self.title
|
self.og_title = self.title
|
||||||
@ -49,6 +50,12 @@ class Album:
|
|||||||
from ..store.tracks import TrackStore
|
from ..store.tracks import TrackStore
|
||||||
TrackStore.append_track_artists(self.albumhash, featured, self.title)
|
TrackStore.append_track_artists(self.albumhash, featured, self.title)
|
||||||
|
|
||||||
|
if FromFlags.REMOVE_REMASTER:
|
||||||
|
self.title, self.versions = get_base_title_and_versions(self.title)
|
||||||
|
|
||||||
|
if "super_deluxe" in self.versions:
|
||||||
|
self.versions.remove("deluxe")
|
||||||
|
|
||||||
self.albumartists_hashes = "-".join(a.artisthash for a in self.albumartists)
|
self.albumartists_hashes = "-".join(a.artisthash for a in self.albumartists)
|
||||||
|
|
||||||
def set_colors(self, colors: list[str]):
|
def set_colors(self, colors: list[str]):
|
||||||
|
@ -132,6 +132,9 @@ class FromFlags:
|
|||||||
Whether to remove the producers from the song title.
|
Whether to remove the producers from the song title.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
REMOVE_REMASTER = True
|
||||||
|
MERGE_REMASTERS = True
|
||||||
|
|
||||||
|
|
||||||
class TCOLOR:
|
class TCOLOR:
|
||||||
"""
|
"""
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
def split_artists(src: str, with_and: bool = False):
|
def split_artists(src: str, with_and: bool = False):
|
||||||
@ -84,3 +85,50 @@ def parse_feat_from_title(title: str) -> tuple[list[str], str]:
|
|||||||
# remove "feat" group from title
|
# remove "feat" group from title
|
||||||
new_title = re.sub(regex, "", title, flags=re.IGNORECASE)
|
new_title = re.sub(regex, "", title, flags=re.IGNORECASE)
|
||||||
return artists, new_title
|
return artists, new_title
|
||||||
|
|
||||||
|
|
||||||
|
def get_base_album_title(string):
|
||||||
|
pattern = re.compile(r'\s*(\(|\[).*?(version|remaster|deluxe|edition|expanded).*?(\)|\])', re.IGNORECASE)
|
||||||
|
match = pattern.search(string)
|
||||||
|
if match:
|
||||||
|
removed_block = match.group(0)
|
||||||
|
title = string.replace(removed_block, '').strip('()[] ')
|
||||||
|
return title, removed_block
|
||||||
|
|
||||||
|
return string, None
|
||||||
|
|
||||||
|
|
||||||
|
class AlbumVersionEnum(Enum):
|
||||||
|
REMASTER = ("remaster", "remastered")
|
||||||
|
DELUXE = ("deluxe",)
|
||||||
|
EXPANDED = ("expanded",)
|
||||||
|
SUPER_DELUXE = ("super deluxe",)
|
||||||
|
EXTENDED = ("extended",)
|
||||||
|
BONUS_TRACK = ("bonus track", "bonus tracks")
|
||||||
|
RE_RECORD = ("re-recorded", "rerecorded")
|
||||||
|
INTL_VERSION = ("international",)
|
||||||
|
ORIGINAL = ("original",)
|
||||||
|
RE_MIX = ("re-mix",)
|
||||||
|
RE_RECORDED = ("re-recorded", "rerecorded")
|
||||||
|
REISSUE = ("reissue",)
|
||||||
|
|
||||||
|
|
||||||
|
def get_album_info(bracket_text: str | None) -> list[str]:
|
||||||
|
if not bracket_text:
|
||||||
|
return []
|
||||||
|
|
||||||
|
versions = []
|
||||||
|
|
||||||
|
for version_keywords in AlbumVersionEnum:
|
||||||
|
for keyword in version_keywords.value:
|
||||||
|
if re.search(keyword, bracket_text, re.IGNORECASE):
|
||||||
|
versions.append(version_keywords.name.lower())
|
||||||
|
break
|
||||||
|
return versions
|
||||||
|
|
||||||
|
|
||||||
|
def get_base_title_and_versions(album: str) -> tuple[str, list[str]]:
|
||||||
|
album_title, version_block = get_base_album_title(album)
|
||||||
|
versions = get_album_info(version_block)
|
||||||
|
|
||||||
|
return album_title, versions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user