addepted the database binding tp the changes to the structure
This commit is contained in:
parent
b46b9f5149
commit
bfcec43433
@ -20,6 +20,9 @@ from music_kraken.tagging import (
|
|||||||
import music_kraken.database.new_database as db
|
import music_kraken.database.new_database as db
|
||||||
|
|
||||||
import pycountry
|
import pycountry
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logging.disable()
|
||||||
|
|
||||||
|
|
||||||
def div(msg: str = ""):
|
def div(msg: str = ""):
|
||||||
@ -31,6 +34,8 @@ cache.reset()
|
|||||||
|
|
||||||
def print_song(song_: Song):
|
def print_song(song_: Song):
|
||||||
print(str(song_.metadata))
|
print(str(song_.metadata))
|
||||||
|
print("----album--")
|
||||||
|
print(song_.album)
|
||||||
print("----src----")
|
print("----src----")
|
||||||
print("song:")
|
print("song:")
|
||||||
print(song_.source_list)
|
print(song_.source_list)
|
||||||
@ -79,18 +84,15 @@ print_song(song)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
div()
|
||||||
song_ref = song.reference
|
song_ref = song.reference
|
||||||
|
|
||||||
cache.push([song])
|
cache.push([song])
|
||||||
exit()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# getting song by song ref
|
# getting song by song ref
|
||||||
div()
|
|
||||||
song_list = cache.pull_songs(song_ref=song_ref)
|
song_list = cache.pull_songs(song_ref=song_ref)
|
||||||
song_from_db = song_list[0]
|
song_from_db = song_list[0]
|
||||||
|
|
||||||
|
print_song(song_from_db)
|
||||||
|
|
||||||
# try writing metadata
|
# try writing metadata
|
||||||
write_metadata(song)
|
write_metadata(song)
|
||||||
|
@ -27,7 +27,7 @@ logger = logging.getLogger("database")
|
|||||||
# use complicated query builder
|
# use complicated query builder
|
||||||
SONG_QUERY = """
|
SONG_QUERY = """
|
||||||
SELECT
|
SELECT
|
||||||
Song.id AS song_id, Song.name AS title, Song.isrc AS isrc, Song.length AS length, Song.album_id, Song.tracksort,
|
Song.id AS song_id, Song.name AS title, Song.isrc AS isrc, Song.length AS length, Song.album_id as album_id, Song.tracksort,
|
||||||
Target.id AS target_id, Target.file AS file, Target.path AS path, Song.genre AS genre
|
Target.id AS target_id, Target.file AS file, Target.path AS path, Song.genre AS genre
|
||||||
FROM Song
|
FROM Song
|
||||||
LEFT JOIN Target ON Song.id=Target.song_id
|
LEFT JOIN Target ON Song.id=Target.song_id
|
||||||
@ -119,10 +119,6 @@ class Database:
|
|||||||
if type(db_object) == Album:
|
if type(db_object) == Album:
|
||||||
return self.push_album(album=db_object)
|
return self.push_album(album=db_object)
|
||||||
|
|
||||||
if issubclass(type(db_object), SourceAttribute):
|
|
||||||
for source in db_object.source_list:
|
|
||||||
self.push_source(source=source)
|
|
||||||
|
|
||||||
logger.warning(f"type {type(db_object)} isn't yet supported by the db")
|
logger.warning(f"type {type(db_object)} isn't yet supported by the db")
|
||||||
|
|
||||||
def push(self, db_object_list: List[Song | Lyrics | Target | Artist | Source | Album]):
|
def push(self, db_object_list: List[Song | Lyrics | Target | Artist | Source | Album]):
|
||||||
@ -163,7 +159,8 @@ class Database:
|
|||||||
self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference)
|
self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference)
|
||||||
self.push_artist(artist)
|
self.push_artist(artist)
|
||||||
|
|
||||||
for source in album.sources:
|
for source in album.source_list:
|
||||||
|
source.type_enum = SourceTypes.ALBUM
|
||||||
self.push_source(source=source)
|
self.push_source(source=source)
|
||||||
|
|
||||||
def push_song(self, song: Song):
|
def push_song(self, song: Song):
|
||||||
@ -213,6 +210,9 @@ class Database:
|
|||||||
self.push_artist_song(artist_ref=Reference(feature_artist.id), song_ref=Reference(song.id), is_feature=True)
|
self.push_artist_song(artist_ref=Reference(feature_artist.id), song_ref=Reference(song.id), is_feature=True)
|
||||||
self.push_artist(artist=feature_artist)
|
self.push_artist(artist=feature_artist)
|
||||||
|
|
||||||
|
if song.album is not None:
|
||||||
|
self.push_album(song.album)
|
||||||
|
|
||||||
def push_lyrics(self, lyrics: Lyrics, ):
|
def push_lyrics(self, lyrics: Lyrics, ):
|
||||||
if lyrics.song_ref_id is None:
|
if lyrics.song_ref_id is None:
|
||||||
logger.warning("the Lyrics don't refer to a song")
|
logger.warning("the Lyrics don't refer to a song")
|
||||||
@ -321,7 +321,8 @@ class Database:
|
|||||||
for album in artist.main_albums:
|
for album in artist.main_albums:
|
||||||
self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference)
|
self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference)
|
||||||
|
|
||||||
for source in artist.sources:
|
for source in artist.source_list:
|
||||||
|
source.type_enum = SourceTypes.ARTIST
|
||||||
self.push_source(source)
|
self.push_source(source)
|
||||||
|
|
||||||
def pull_lyrics(self, song_ref: Reference = None, lyrics_ref: Reference = None) -> List[Lyrics]:
|
def pull_lyrics(self, song_ref: Reference = None, lyrics_ref: Reference = None) -> List[Lyrics]:
|
||||||
@ -437,7 +438,7 @@ class Database:
|
|||||||
artist_obj = Artist(
|
artist_obj = Artist(
|
||||||
id_=artist_id,
|
id_=artist_id,
|
||||||
name=artist_row['artist_name'],
|
name=artist_row['artist_name'],
|
||||||
sources=self.pull_sources(artist_ref=Reference(id_=artist_id))
|
source_list=self.pull_sources(artist_ref=Reference(id_=artist_id))
|
||||||
)
|
)
|
||||||
if flat:
|
if flat:
|
||||||
return artist_obj
|
return artist_obj
|
||||||
@ -506,11 +507,12 @@ class Database:
|
|||||||
file=song_result['file'],
|
file=song_result['file'],
|
||||||
path=song_result['path']
|
path=song_result['path']
|
||||||
),
|
),
|
||||||
sources=self.pull_sources(song_ref=Reference(id_=song_id)),
|
source_list=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)),
|
||||||
)
|
)
|
||||||
|
|
||||||
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:
|
||||||
|
print(dict(song_result))
|
||||||
album_obj = self.pull_albums(album_ref=Reference(song_result['album_id']),
|
album_obj = self.pull_albums(album_ref=Reference(song_result['album_id']),
|
||||||
exclude_relations=new_exclude_relations)
|
exclude_relations=new_exclude_relations)
|
||||||
if len(album_obj) > 0:
|
if len(album_obj) > 0:
|
||||||
@ -580,7 +582,7 @@ class Database:
|
|||||||
barcode=album_result['barcode'],
|
barcode=album_result['barcode'],
|
||||||
is_split=album_result['is_split'],
|
is_split=album_result['is_split'],
|
||||||
albumsort=album_result['albumsort'],
|
albumsort=album_result['albumsort'],
|
||||||
sources=self.pull_sources(album_ref=Reference(id_=album_id))
|
source_list=self.pull_sources(album_ref=Reference(id_=album_id))
|
||||||
)
|
)
|
||||||
|
|
||||||
if Song not in exclude_relations:
|
if Song not in exclude_relations:
|
||||||
|
@ -138,8 +138,6 @@ class Song(DatabaseObject, SourceAttribute, MetadataAttribute):
|
|||||||
if source_list:
|
if source_list:
|
||||||
self.source_list = source_list
|
self.source_list = source_list
|
||||||
|
|
||||||
self.album = album
|
|
||||||
|
|
||||||
self.target = Target()
|
self.target = Target()
|
||||||
if target is not None:
|
if target is not None:
|
||||||
self.target = target
|
self.target = target
|
||||||
|
@ -22,7 +22,7 @@ class AudioMetadata:
|
|||||||
self.file_location = file_location
|
self.file_location = file_location
|
||||||
|
|
||||||
def add_song_metadata(self, song: Song):
|
def add_song_metadata(self, song: Song):
|
||||||
for key, value in song.metadata:
|
for value in song.metadata:
|
||||||
"""
|
"""
|
||||||
https://www.programcreek.com/python/example/84797/mutagen.id3.ID3
|
https://www.programcreek.com/python/example/84797/mutagen.id3.ID3
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user