added source to artist
This commit is contained in:
parent
d1af921157
commit
cb5b1b1fcc
13
src/goof.py
13
src/goof.py
@ -7,7 +7,8 @@ from music_kraken import (
|
||||
Album,
|
||||
Artist,
|
||||
ID3Timestamp,
|
||||
source_types
|
||||
SourcePages,
|
||||
SourceTypes
|
||||
)
|
||||
|
||||
from music_kraken.tagging import (
|
||||
@ -28,8 +29,12 @@ def div(msg: str = ""):
|
||||
cache = music_kraken.database.new_database.Database("test.db")
|
||||
cache.reset()
|
||||
|
||||
|
||||
main_artist = Artist(
|
||||
name="I'm in a coffin"
|
||||
name="I'm in a coffin",
|
||||
sources=[
|
||||
Source(SourcePages.ENCYCLOPAEDIA_METALLUM, "https://www.metal-archives.com/bands/I%27m_in_a_Coffin/127727")
|
||||
]
|
||||
)
|
||||
|
||||
artist_ref = main_artist.reference
|
||||
@ -65,8 +70,8 @@ song_input = Song(
|
||||
Lyrics(text="test", language="en")
|
||||
],
|
||||
sources=[
|
||||
Source(source_types.SONG, src="youtube", url="https://youtu.be/dfnsdajlhkjhsd"),
|
||||
Source(source_types.SONG, src="musify", url="https://ln.topdf.de/Music-Kraken/")
|
||||
Source(SourcePages.YOUTUBE, "https://youtu.be/dfnsdajlhkjhsd"),
|
||||
Source(SourcePages.MUSIFY, "https://ln.topdf.de/Music-Kraken/")
|
||||
],
|
||||
album=album_input,
|
||||
main_artist_list=[main_artist],
|
||||
|
@ -41,7 +41,8 @@ musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeI
|
||||
Song = database.Song
|
||||
Artist = database.Artist
|
||||
Source = database.Source
|
||||
source_types = database.source_types
|
||||
SourceTypes = database.SourceTypes
|
||||
SourcePages = database.SourcePages
|
||||
Target = database.Target
|
||||
Lyrics = database.Lyrics
|
||||
Album = database.Album
|
||||
|
@ -4,7 +4,8 @@ from . import (
|
||||
)
|
||||
|
||||
ID3Timestamp = objects.ID3Timestamp
|
||||
source_types = objects.source_types
|
||||
SourceTypes = objects.SourceTypes
|
||||
SourcePages = objects.SourcePages
|
||||
Song = objects.Song
|
||||
Source = objects.Source
|
||||
Target = objects.Target
|
||||
|
@ -16,10 +16,10 @@ from .objects import (
|
||||
Artist,
|
||||
Album,
|
||||
ID3Timestamp,
|
||||
source_types
|
||||
SourceTypes,
|
||||
SourcePages
|
||||
)
|
||||
|
||||
|
||||
logger = logging.getLogger("database")
|
||||
|
||||
# Due to this not being deployed on a Server **HOPEFULLY**
|
||||
@ -186,7 +186,7 @@ class Database:
|
||||
# add sources
|
||||
for source in song.sources:
|
||||
source.add_song(song)
|
||||
source.type_enum = source_types.SONG
|
||||
source.type_enum = SourceTypes.SONG
|
||||
self.push_source(source=source)
|
||||
|
||||
# add lyrics
|
||||
@ -223,8 +223,6 @@ class Database:
|
||||
self.connection.commit()
|
||||
|
||||
def push_source(self, source: Source):
|
||||
|
||||
|
||||
if source.song_ref_id is None:
|
||||
logger.warning("the Source don't refer to a song")
|
||||
|
||||
@ -234,7 +232,7 @@ class Database:
|
||||
source.id,
|
||||
source.type_str,
|
||||
source.song_ref_id,
|
||||
source.site_str,
|
||||
source.page_str,
|
||||
source.url
|
||||
)
|
||||
|
||||
@ -316,6 +314,10 @@ class Database:
|
||||
for album in artist.main_albums:
|
||||
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]:
|
||||
"""
|
||||
Gets a list of sources. if lyrics_ref is passed in the List will most likely only
|
||||
@ -342,7 +344,7 @@ class Database:
|
||||
language=lyrics_row['language']
|
||||
) for lyrics_row in lyrics_rows]
|
||||
|
||||
def pull_sources(self, type_enum, 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) -> 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.
|
||||
@ -357,19 +359,23 @@ class Database:
|
||||
if song_ref is not None:
|
||||
where = f"song_id=\"{song_ref.id}\""
|
||||
elif source_ref is not None:
|
||||
where = f"id=\"{source_ref.id}\""
|
||||
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}\""
|
||||
|
||||
query = SOURCE_QUERY.format(where=where)
|
||||
self.cursor.execute(query)
|
||||
|
||||
source_rows = self.cursor.fetchall()
|
||||
|
||||
return [Source(
|
||||
source_types(source_row['type']),
|
||||
id_=source_row['id'],
|
||||
src=source_row['src'],
|
||||
url=source_row['url']
|
||||
) for source_row in source_rows]
|
||||
return [
|
||||
Source(
|
||||
page_enum=SourcePages(source_row['src']),
|
||||
type_enum=SourceTypes(source_row['type']),
|
||||
url=source_row['url'],
|
||||
id_=source_row['id']
|
||||
) for source_row in source_rows
|
||||
]
|
||||
|
||||
def pull_artist_song(self, song_ref: Reference = None, artist_ref: Reference = None) -> List[tuple]:
|
||||
table = "SongArtist"
|
||||
@ -422,7 +428,8 @@ class Database:
|
||||
|
||||
artist_obj = Artist(
|
||||
id_=artist_id,
|
||||
name=artist_row['artist_name']
|
||||
name=artist_row['artist_name'],
|
||||
sources=self.pull_sources(artist_ref=Reference(id_=artist_id))
|
||||
)
|
||||
if flat:
|
||||
return artist_obj
|
||||
@ -491,7 +498,7 @@ class Database:
|
||||
file=song_result['file'],
|
||||
path=song_result['path']
|
||||
),
|
||||
sources=self.pull_sources(type_enum=source_types.SONG, 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)),
|
||||
)
|
||||
|
||||
|
@ -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,8 +122,7 @@ class Song(DatabaseObject, ID3Metadata):
|
||||
self.tracksort: int | None = tracksort
|
||||
self.genre: str = genre
|
||||
|
||||
self.sources: List[Source] = []
|
||||
if sources is not None:
|
||||
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,10 +347,10 @@ class Artist(DatabaseObject, ID3Metadata):
|
||||
|
||||
self.main_albums = main_albums
|
||||
|
||||
self.sources = []
|
||||
if sources is not None:
|
||||
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,13 +7,15 @@ 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"
|
||||
GENIUS = "genius"
|
||||
@ -25,14 +27,13 @@ class sources(Enum):
|
||||
homepage_map = {
|
||||
cls.YOUTUBE: "https://www.youtube.com/",
|
||||
cls.MUSIFY: "https://musify.club/",
|
||||
cls.MUSICBRAINZ:"https://musicbrainz.org/",
|
||||
cls.MUSICBRAINZ: "https://musicbrainz.org/",
|
||||
cls.ENCYCLOPAEDIA_METALLUM: "https://www.metal-archives.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))
|
||||
|
BIN
src/test.db
BIN
src/test.db
Binary file not shown.
Loading…
Reference in New Issue
Block a user