This commit is contained in:
Lars Noack 2022-12-13 11:16:19 +01:00
parent 2392336e0a
commit 0fe7c70f21
5 changed files with 39 additions and 32 deletions

View File

@ -50,12 +50,14 @@ song_input = Song(
Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd"), Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd"),
Source(src="musify", url="https://ln.topdf.de/Music-Kraken/") Source(src="musify", url="https://ln.topdf.de/Music-Kraken/")
], ],
album_ref=album_input.reference album = album_input,
main_artist_list = [main_artist],
feature_artist_list = [feature_artist]
) )
additional_song = Song( additional_song = Song(
title="A fcking Song", title="A fcking Song",
album_ref=album_input.reference album=album_input
) )
song_ref = song_input.reference song_ref = song_input.reference

View File

@ -316,6 +316,9 @@ class Database:
song_id = song_result['song_id'] song_id = song_result['song_id']
# maybee fetch album
album = None
song_obj = Song( song_obj = Song(
id_=song_id, id_=song_id,
title=song_result['title'], title=song_result['title'],
@ -329,7 +332,6 @@ class Database:
), ),
sources=self.pull_sources(song_ref=Reference(id_=song_id)), sources=self.pull_sources(song_ref=Reference(id_=song_id)),
lyrics=self.pull_lyrics(song_ref=Reference(id_=song_id)), lyrics=self.pull_lyrics(song_ref=Reference(id_=song_id)),
album_ref=Reference(song_result['album_id'])
) )
if Album not in exclude_relations and song_result['album_id'] is not None: if Album not in exclude_relations and song_result['album_id'] is not None:

View File

@ -17,17 +17,17 @@ All Objects dependent
class SongAttribute: class SongAttribute:
def __init__(self, song_ref: Reference = None): def __init__(self, song = None):
# the reference to the song the lyrics belong to # the reference to the song the lyrics belong to
self.song_ref = song_ref self.song = song
def add_song(self, song_ref: Reference): def add_song(self, song):
self.song_ref = song_ref self.song = song
def get_ref_song_id(self): def get_ref_song_id(self):
if self.song_ref is None: if self.song is None:
return None return None
return self.song_ref.id return self.song.reference.id
def set_ref_song_id(self, song_id): def set_ref_song_id(self, song_id):
self.song_ref = Reference(song_id) self.song_ref = Reference(song_id)
@ -150,8 +150,9 @@ class Song(DatabaseObject):
target: Target = None, target: Target = None,
lyrics: List[Lyrics] = None, lyrics: List[Lyrics] = None,
metadata: dict = {}, metadata: dict = {},
album_ref: Reference = None, album = None,
artist_refs: List[Reference] = None main_artist_list: list = [],
feature_artist_list: list = []
) -> None: ) -> None:
""" """
id: is not NECESARRILY the musicbrainz id, but is DISTINCT for every song id: is not NECESARRILY the musicbrainz id, but is DISTINCT for every song
@ -176,31 +177,42 @@ class Song(DatabaseObject):
sources = [] sources = []
self.sources: List[Source] = sources self.sources: List[Source] = sources
for source in self.sources: for source in self.sources:
source.add_song(self.reference) source.add_song(self)
if target is None: if target is None:
target = Target() target = Target()
self.target: Target = target self.target: Target = target
self.target.add_song(self.reference) self.target.add_song(self)
if lyrics is None: if lyrics is None:
lyrics = [] lyrics = []
self.lyrics: List[Lyrics] = lyrics self.lyrics: List[Lyrics] = lyrics
for lyrics_ in self.lyrics: for lyrics_ in self.lyrics:
lyrics_.add_song(self.reference) lyrics_.add_song(self)
self.album_ref = album_ref self.album: Album = album
self.artist_refs = artist_refs
self._album: Album | None = None self.main_artist_list = main_artist_list
self.feature_artist_list = feature_artist_list
def __eq__(self, other): def __eq__(self, other):
if type(other) != type(self): if type(other) != type(self):
return False return False
return self.id == other.id return self.id == other.id
def get_artist_credits(self) -> str:
feature_str = ""
if len(self.feature_artist_list) > 0:
feature_str = " feat. " + ", ".join([artist.name for artist in self.feature_artist_list])
return ", ".join([artist.name for artist in self.main_artist_list]) + feature_str
def __str__(self) -> str: def __str__(self) -> str:
return f"\"{self.title}\" by {', '.join(self.artist_names)}" artist_credit_str = ""
artist_credits = self.get_artist_credits()
if artist_credits != "":
artist_credit_str = f" by {artist_credits}"
return f"\"{self.title}\"{artist_credit_str}"
def __repr__(self) -> str: def __repr__(self) -> str:
return self.__str__() return self.__str__()
@ -224,20 +236,12 @@ class Song(DatabaseObject):
raise TypeError(f"length of a song must be of the type int not {type(length)}") raise TypeError(f"length of a song must be of the type int not {type(length)}")
self.length_ = length self.length_ = length
def get_album_id(self) -> str | None: def get_album_id(self):
if self.album_ref is None: if self.album is None:
return None return None
return self.album_ref.id return self.album.id
def set_album(self, album): album_id: str = property(fget=get_album_id)
if self.album_ref.id is not None:
if self.album_ref.id != album.id:
logger.warning(f"song already refers to different album, overriding reference.")
self.album_ref = Reference(album.id)
self._album = album
album = property(fget=lambda self: self._album, fset=set_album)
length: int = property(fget=get_length, fset=set_length) length: int = property(fget=get_length, fset=set_length)
@ -338,7 +342,6 @@ class Artist(DatabaseObject):
self.songs: List[ArtistSong] = [] self.songs: List[ArtistSong] = []
self.album_refs: List[Album] = [] self.album_refs: List[Album] = []
self.song
self.set_discography(discography) self.set_discography(discography)
self.set_features(features) self.set_features(features)

View File

@ -33,7 +33,7 @@ CREATE TABLE Album
date TEXT, date TEXT,
country TEXT, country TEXT,
barcode TEXT, barcode TEXT,
album_sort INT, albumsort INT,
is_split BOOLEAN NOT NULL DEFAULT 0 is_split BOOLEAN NOT NULL DEFAULT 0
); );

BIN
test.db

Binary file not shown.