added Source objects to album
This commit is contained in:
parent
cb5b1b1fcc
commit
e51d4ca467
@ -51,7 +51,10 @@ album_input = Album(
|
||||
title="One Final Action",
|
||||
date=ID3Timestamp(year=1986, month=3, day=1),
|
||||
language=pycountry.languages.get(alpha_2="en"),
|
||||
label="cum productions"
|
||||
label="cum productions",
|
||||
sources=[
|
||||
Source(SourcePages.ENCYCLOPAEDIA_METALLUM, "https://www.metal-archives.com/albums/I%27m_in_a_Coffin/One_Final_Action/207614")
|
||||
]
|
||||
)
|
||||
album_input.artists = [
|
||||
main_artist,
|
||||
@ -110,6 +113,8 @@ print("--src--")
|
||||
for source in song.sources:
|
||||
print(source)
|
||||
|
||||
print("album", song.album.sources)
|
||||
|
||||
# try writing metadata
|
||||
write_metadata(song)
|
||||
|
||||
|
@ -159,6 +159,9 @@ class Database:
|
||||
self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference)
|
||||
self.push_artist(artist)
|
||||
|
||||
for source in album.sources:
|
||||
self.push_source(source=source)
|
||||
|
||||
def push_song(self, song: Song):
|
||||
# ADDING THE DATA FOR THE SONG OBJECT
|
||||
"""
|
||||
@ -224,7 +227,7 @@ class Database:
|
||||
|
||||
def push_source(self, source: Source):
|
||||
if source.song_ref_id is None:
|
||||
logger.warning("the Source don't refer to a song")
|
||||
logger.warning(f"the Source {source} don't refer to a song")
|
||||
|
||||
table = "Source"
|
||||
query = f"INSERT OR REPLACE INTO {table} (id, type, song_id, src, url) VALUES (?, ?, ?, ?, ?);"
|
||||
@ -315,7 +318,6 @@ class Database:
|
||||
self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference)
|
||||
|
||||
for source in artist.sources:
|
||||
source.add_song(artist)
|
||||
self.push_source(source)
|
||||
|
||||
def pull_lyrics(self, song_ref: Reference = None, lyrics_ref: Reference = None) -> List[Lyrics]:
|
||||
@ -344,7 +346,7 @@ class Database:
|
||||
language=lyrics_row['language']
|
||||
) for lyrics_row in lyrics_rows]
|
||||
|
||||
def pull_sources(self, artist_ref: Reference = None, song_ref: Reference = None, source_ref: Reference = None) -> List[Source]:
|
||||
def pull_sources(self, artist_ref: Reference = None, song_ref: Reference = None, source_ref: Reference = None, album_ref: Reference = None) -> List[Source]:
|
||||
"""
|
||||
Gets a list of sources. if source_ref is passed in the List will most likely only
|
||||
contain one Element if everything goes accordingly.
|
||||
@ -362,6 +364,8 @@ class Database:
|
||||
where = f"id=\"{source_ref.id}\" AND type=\"{SourceTypes.SONG.value}\""
|
||||
elif artist_ref is not None:
|
||||
where = f"song_id=\"{artist_ref.id}\" AND type=\"{SourceTypes.ARTIST.value}\""
|
||||
elif album_ref is not None:
|
||||
where = f"song_id=\"{album_ref.id}\" AND type=\"{SourceTypes.ALBUM.value}\""
|
||||
|
||||
query = SOURCE_QUERY.format(where=where)
|
||||
self.cursor.execute(query)
|
||||
@ -571,7 +575,8 @@ class Database:
|
||||
country=album_result['country'],
|
||||
barcode=album_result['barcode'],
|
||||
is_split=album_result['is_split'],
|
||||
albumsort=album_result['albumsort']
|
||||
albumsort=album_result['albumsort'],
|
||||
sources=self.pull_sources(album_ref=Reference(id_=album_id))
|
||||
)
|
||||
|
||||
if Song not in exclude_relations:
|
||||
|
@ -239,7 +239,8 @@ class Album(DatabaseObject, ID3Metadata):
|
||||
barcode: str = None,
|
||||
is_split: bool = False,
|
||||
albumsort: int = None,
|
||||
dynamic: bool = False
|
||||
dynamic: bool = False,
|
||||
sources: List[Source] = None
|
||||
) -> None:
|
||||
DatabaseObject.__init__(self, id_=id_, dynamic=dynamic)
|
||||
self.title: str = title
|
||||
@ -260,6 +261,9 @@ class Album(DatabaseObject, ID3Metadata):
|
||||
self.tracklist: List[Song] = []
|
||||
self.artists: List[Artist] = []
|
||||
|
||||
self._sources = []
|
||||
self.sources = sources
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Album: \"{self.title}\""
|
||||
|
||||
@ -304,6 +308,16 @@ class Album(DatabaseObject, ID3Metadata):
|
||||
|
||||
return self.language.alpha_3
|
||||
|
||||
def set_sources(self, source_list: List[Source]):
|
||||
if source_list is None:
|
||||
return
|
||||
|
||||
self._sources = source_list
|
||||
for source in self._sources:
|
||||
source.add_song(self)
|
||||
source.type_enum = SourceTypes.ALBUM
|
||||
|
||||
sources: List[Source] = property(fget=lambda self: self._sources, fset=set_sources)
|
||||
copyright = property(fget=get_copyright)
|
||||
iso_639_2_language = property(fget=get_iso_639_2_lang)
|
||||
|
||||
@ -412,6 +426,7 @@ class Artist(DatabaseObject, ID3Metadata):
|
||||
|
||||
self._sources = source_list
|
||||
for source in self._sources:
|
||||
source.add_song(self)
|
||||
source.type_enum = SourceTypes.ARTIST
|
||||
|
||||
sources: List[Source] = property(fget=lambda self: self._sources, fset=set_sources)
|
||||
|
Loading…
Reference in New Issue
Block a user