added source to artist
This commit is contained in:
@@ -7,7 +7,8 @@ from . import (
|
||||
ID3_MAPPING = metadata.Mapping
|
||||
ID3Timestamp = metadata.ID3Timestamp
|
||||
|
||||
source_types = source.source_types
|
||||
SourceTypes = source.SourceTypes
|
||||
SourcePages = source.SourcePages
|
||||
|
||||
Song = song.Song
|
||||
Artist = song.Artist
|
||||
|
||||
@@ -18,7 +18,11 @@ from .parents import (
|
||||
SongAttribute,
|
||||
ID3Metadata
|
||||
)
|
||||
from .source import Source
|
||||
from .source import (
|
||||
Source,
|
||||
SourceTypes,
|
||||
SourcePages
|
||||
)
|
||||
|
||||
"""
|
||||
All Objects dependent
|
||||
@@ -118,9 +122,8 @@ class Song(DatabaseObject, ID3Metadata):
|
||||
self.tracksort: int | None = tracksort
|
||||
self.genre: str = genre
|
||||
|
||||
self.sources: List[Source] = []
|
||||
if sources is not None:
|
||||
self.sources = sources
|
||||
self._sources: List[Source] = []
|
||||
self.sources = sources
|
||||
|
||||
self.album = album
|
||||
|
||||
@@ -192,6 +195,15 @@ class Song(DatabaseObject, ID3Metadata):
|
||||
|
||||
return metadata
|
||||
|
||||
def set_sources(self, source_list: List[Source]):
|
||||
if source_list is None:
|
||||
return
|
||||
|
||||
self._sources = source_list
|
||||
for source in self._sources:
|
||||
source.type_enum = SourceTypes.SONG
|
||||
|
||||
sources: List[Source] = property(fget=lambda self: self._sources, fset=set_sources)
|
||||
metadata = property(fget=get_metadata)
|
||||
|
||||
|
||||
@@ -335,9 +347,9 @@ class Artist(DatabaseObject, ID3Metadata):
|
||||
|
||||
self.main_albums = main_albums
|
||||
|
||||
self.sources = []
|
||||
if sources is not None:
|
||||
self.sources = sources
|
||||
self._sources = []
|
||||
self.sources = sources
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.name or ""
|
||||
@@ -381,13 +393,28 @@ class Artist(DatabaseObject, ID3Metadata):
|
||||
return flat_copy_discography
|
||||
|
||||
def get_id3_dict(self) -> dict:
|
||||
"""
|
||||
TODO refactor
|
||||
:return:
|
||||
"""
|
||||
id3_dict = {
|
||||
ID3_MAPPING.ARTIST: [self.name]
|
||||
}
|
||||
if len(self.sources) <= 0:
|
||||
return id3_dict
|
||||
id3_dict.update(self.sources[0].get_id3_dict())
|
||||
|
||||
return id3_dict
|
||||
|
||||
def set_sources(self, source_list: List[Source]):
|
||||
if source_list is None:
|
||||
return
|
||||
|
||||
self._sources = source_list
|
||||
for source in self._sources:
|
||||
source.type_enum = SourceTypes.ARTIST
|
||||
|
||||
sources: List[Source] = property(fget=lambda self: self._sources, fset=set_sources)
|
||||
discography: List[Album] = property(fget=get_discography)
|
||||
features: Album = property(fget=get_features)
|
||||
songs: Album = property(fget=get_songs)
|
||||
|
||||
@@ -7,15 +7,17 @@ from .parents import (
|
||||
ID3Metadata
|
||||
)
|
||||
|
||||
class source_types(Enum):
|
||||
|
||||
class SourceTypes(Enum):
|
||||
SONG = "song"
|
||||
ALBUM = "album"
|
||||
ARTIST = "artist"
|
||||
LYRICS = "lyrics"
|
||||
|
||||
class sources(Enum):
|
||||
|
||||
class SourcePages(Enum):
|
||||
YOUTUBE = "youtube"
|
||||
MUSIFY = "musify"
|
||||
MUSIFY = "musify"
|
||||
GENIUS = "genius"
|
||||
MUSICBRAINZ = "musicbrainz"
|
||||
ENCYCLOPAEDIA_METALLUM = "encyclopaedia metallum"
|
||||
@@ -23,16 +25,15 @@ class sources(Enum):
|
||||
@classmethod
|
||||
def get_homepage(cls, attribute) -> str:
|
||||
homepage_map = {
|
||||
cls.YOUTUBE: "https://www.youtube.com/",
|
||||
cls.MUSIFY: "https://musify.club/",
|
||||
cls.MUSICBRAINZ:"https://musicbrainz.org/",
|
||||
cls.YOUTUBE: "https://www.youtube.com/",
|
||||
cls.MUSIFY: "https://musify.club/",
|
||||
cls.MUSICBRAINZ: "https://musicbrainz.org/",
|
||||
cls.ENCYCLOPAEDIA_METALLUM: "https://www.metal-archives.com/",
|
||||
cls.GENIUS: "https://genius.com/"
|
||||
cls.GENIUS: "https://genius.com/"
|
||||
}
|
||||
return homepage_map[attribute]
|
||||
|
||||
|
||||
|
||||
class Source(DatabaseObject, SongAttribute, ID3Metadata):
|
||||
"""
|
||||
create somehow like that
|
||||
@@ -42,22 +43,23 @@ class Source(DatabaseObject, SongAttribute, ID3Metadata):
|
||||
```
|
||||
"""
|
||||
|
||||
def __init__(self, type_enum, id_: str = None, src: str = None, url: str = None) -> None:
|
||||
def __init__(self, page_enum, url: str, id_: str = None, type_enum=None) -> None:
|
||||
DatabaseObject.__init__(self, id_=id_)
|
||||
SongAttribute.__init__(self)
|
||||
|
||||
self.type_enum = type_enum
|
||||
self.src = sources(src)
|
||||
self.page_enum = page_enum
|
||||
|
||||
self.url = url
|
||||
|
||||
def get_id3_dict(self) -> dict:
|
||||
if self.type_enum == source_types.SONG:
|
||||
if self.type_enum == SourceTypes.SONG:
|
||||
return {
|
||||
Mapping.FILE_WEBPAGE_URL: [self.url],
|
||||
Mapping.SOURCE_WEBPAGE_URL: [self.homepage]
|
||||
}
|
||||
|
||||
if self.type_enum == source_types.ARTIST:
|
||||
|
||||
if self.type_enum == SourceTypes.ARTIST:
|
||||
return {
|
||||
Mapping.ARTIST_WEBPAGE_URL: [self.url]
|
||||
}
|
||||
@@ -65,8 +67,8 @@ class Source(DatabaseObject, SongAttribute, ID3Metadata):
|
||||
return {}
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.src}: {self.url}"
|
||||
return f"{self.page_enum}: {self.url}"
|
||||
|
||||
site_str = property(fget=lambda self: self.src.value)
|
||||
page_str = property(fget=lambda self: self.page_enum.value)
|
||||
type_str = property(fget=lambda self: self.type_enum.value)
|
||||
homepage = property(fget=lambda self: sources.get_homepage(self.src))
|
||||
homepage = property(fget=lambda self: SourcePages.get_homepage(self.page_enum))
|
||||
|
||||
Reference in New Issue
Block a user