sffkldöföajd
This commit is contained in:
parent
9d43dfd129
commit
070b6fef43
15
src/goof.py
15
src/goof.py
@ -4,7 +4,8 @@ from music_kraken import (
|
|||||||
Lyrics,
|
Lyrics,
|
||||||
Target,
|
Target,
|
||||||
Source,
|
Source,
|
||||||
Album
|
Album,
|
||||||
|
Artist
|
||||||
)
|
)
|
||||||
|
|
||||||
import music_kraken.database.new_database as db
|
import music_kraken.database.new_database as db
|
||||||
@ -16,6 +17,18 @@ def div():
|
|||||||
cache = music_kraken.database.new_database.Database("test.db")
|
cache = music_kraken.database.new_database.Database("test.db")
|
||||||
cache.reset()
|
cache.reset()
|
||||||
|
|
||||||
|
main_artist = Artist(
|
||||||
|
name="I'm in a coffin"
|
||||||
|
)
|
||||||
|
|
||||||
|
split_artist = Artist(
|
||||||
|
name="split"
|
||||||
|
)
|
||||||
|
|
||||||
|
feature_artist = Artist(
|
||||||
|
name="feature"
|
||||||
|
)
|
||||||
|
|
||||||
album_input = Album(
|
album_input = Album(
|
||||||
title="One Final Action"
|
title="One Final Action"
|
||||||
)
|
)
|
||||||
|
@ -4,7 +4,6 @@ from . import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
Song = objects.Song
|
Song = objects.Song
|
||||||
Artist = objects.Artist
|
|
||||||
Source = objects.Source
|
Source = objects.Source
|
||||||
Target = objects.Target
|
Target = objects.Target
|
||||||
Metadata = objects.Metadata
|
Metadata = objects.Metadata
|
||||||
@ -12,4 +11,5 @@ Lyrics = objects.Lyrics
|
|||||||
|
|
||||||
Album = objects.Album
|
Album = objects.Album
|
||||||
|
|
||||||
|
Artist = objects.Artist
|
||||||
# cache = temp_database.TempDatabase()
|
# cache = temp_database.TempDatabase()
|
||||||
|
@ -39,12 +39,12 @@ FROM Lyrics
|
|||||||
WHERE {where};
|
WHERE {where};
|
||||||
"""
|
"""
|
||||||
ALBUM_QUERY_UNJOINED = """
|
ALBUM_QUERY_UNJOINED = """
|
||||||
SELECT Album.id AS album_id, title, copyright, album_status, language, year, date, country, barcode
|
SELECT Album.id AS album_id, title, copyright, album_status, language, year, date, country, barcode, albumsort, is_split
|
||||||
FROM Album
|
FROM Album
|
||||||
WHERE {where};
|
WHERE {where};
|
||||||
"""
|
"""
|
||||||
ALBUM_QUERY_JOINED = """
|
ALBUM_QUERY_JOINED = """
|
||||||
SELECT a.id AS album_id, a.title, a.copyright, a.album_status, a.language, a.year, a.date, a.country, a.barcode
|
SELECT a.id AS album_id, a.title, a.copyright, a.album_status, a.language, a.year, a.date, a.country, a.barcode, a.albumsort, a.is_split
|
||||||
FROM Song
|
FROM Song
|
||||||
INNER JOIN Album a ON Song.album_id=a.id
|
INNER JOIN Album a ON Song.album_id=a.id
|
||||||
WHERE {where};
|
WHERE {where};
|
||||||
@ -87,6 +87,9 @@ class Database:
|
|||||||
return self.connection, self.cursor
|
return self.connection, self.cursor
|
||||||
|
|
||||||
def push_one(self, db_object: Song | Lyrics | Target | Artist | Source | Album):
|
def push_one(self, db_object: Song | Lyrics | Target | Artist | Source | Album):
|
||||||
|
if db_object.dynamic:
|
||||||
|
return
|
||||||
|
|
||||||
if type(db_object) == Song:
|
if type(db_object) == Song:
|
||||||
return self.push_song(song=db_object)
|
return self.push_song(song=db_object)
|
||||||
|
|
||||||
@ -122,7 +125,7 @@ class Database:
|
|||||||
|
|
||||||
def push_album(self, album: Album):
|
def push_album(self, album: Album):
|
||||||
table = "Album"
|
table = "Album"
|
||||||
query = f"INSERT OR REPLACE INTO {table} (id, title, copyright, album_status, language, year, date, country, barcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"
|
query = f"INSERT OR REPLACE INTO {table} (id, title, copyright, album_status, language, year, date, country, barcode, albumsort, is_split) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"
|
||||||
|
|
||||||
values = (
|
values = (
|
||||||
album.id,
|
album.id,
|
||||||
@ -133,7 +136,9 @@ class Database:
|
|||||||
album.year,
|
album.year,
|
||||||
album.date,
|
album.date,
|
||||||
album.country,
|
album.country,
|
||||||
album.barcode
|
album.barcode,
|
||||||
|
album.albumsort,
|
||||||
|
album.is_split
|
||||||
)
|
)
|
||||||
self.cursor.execute(query, values)
|
self.cursor.execute(query, values)
|
||||||
self.connection.commit()
|
self.connection.commit()
|
||||||
@ -220,8 +225,36 @@ class Database:
|
|||||||
self.cursor.execute(query, values)
|
self.cursor.execute(query, values)
|
||||||
self.connection.commit()
|
self.connection.commit()
|
||||||
|
|
||||||
|
def push_artist_song(self, artist_ref: Reference, song_ref: Reference, is_feature: bool):
|
||||||
|
table = "SongArtist"
|
||||||
|
# checking if already exists
|
||||||
|
query = f"SELECT * FROM {table} WHERE song_id=\"{song_ref.id}\" AND artist_id=\"{artist_ref.id}\""
|
||||||
|
self.cursor.execute(query)
|
||||||
|
if len(self.cursor.fetchall()) > 0:
|
||||||
|
# join already exists
|
||||||
|
return
|
||||||
|
|
||||||
|
query = f"INSERT OR REPLACE INTO {table} (song_id, artist_id, is_feature) VALUES (?, ?, ?);"
|
||||||
|
values = (
|
||||||
|
song_ref.id,
|
||||||
|
artist_ref.id,
|
||||||
|
is_feature
|
||||||
|
)
|
||||||
|
|
||||||
|
self.cursor.execute(query, values)
|
||||||
|
self.connection.commit()
|
||||||
|
|
||||||
def push_artist(self, artist: Artist):
|
def push_artist(self, artist: Artist):
|
||||||
pass
|
table = "Artist"
|
||||||
|
query = f"INSERT OR REPLACE INTO {table} (id, name) VALUES (?, ?);"
|
||||||
|
values = (
|
||||||
|
artist.id,
|
||||||
|
artist.name
|
||||||
|
)
|
||||||
|
|
||||||
|
self.cursor.execute(query, values)
|
||||||
|
self.connection.commit()
|
||||||
|
|
||||||
|
|
||||||
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]:
|
||||||
"""
|
"""
|
||||||
@ -354,7 +387,9 @@ class Database:
|
|||||||
year=album_result['year'],
|
year=album_result['year'],
|
||||||
date=album_result['date'],
|
date=album_result['date'],
|
||||||
country=album_result['country'],
|
country=album_result['country'],
|
||||||
barcode=album_result['barcode']
|
barcode=album_result['barcode'],
|
||||||
|
is_split=album_result['is_split'],
|
||||||
|
albumsort=album_result['albumsort']
|
||||||
)
|
)
|
||||||
|
|
||||||
if Song not in exclude_relations:
|
if Song not in exclude_relations:
|
||||||
|
@ -3,9 +3,7 @@ from . import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
Song = song.Song
|
Song = song.Song
|
||||||
|
Artist = song.Artist
|
||||||
Song = song.Song
|
|
||||||
Artist = None
|
|
||||||
Source = song.Source
|
Source = song.Source
|
||||||
Target = song.Target
|
Target = song.Target
|
||||||
Metadata = song.Metadata
|
Metadata = song.Metadata
|
||||||
|
@ -19,15 +19,21 @@ class Reference:
|
|||||||
|
|
||||||
|
|
||||||
class DatabaseObject:
|
class DatabaseObject:
|
||||||
def __init__(self, id_: str = None) -> None:
|
def __init__(self, id_: str = None, dynamic: bool = False) -> None:
|
||||||
self.id_: str | None = id_
|
self.id_: str | None = id_
|
||||||
|
self.dynamic = dynamic
|
||||||
|
|
||||||
def get_id(self) -> str:
|
def get_id(self) -> str:
|
||||||
"""
|
"""
|
||||||
returns the id if it is set, else
|
returns the id if it is set, else
|
||||||
it returns a randomly generated UUID
|
it returns a randomly generated UUID
|
||||||
https://docs.python.org/3/library/uuid.html
|
https://docs.python.org/3/library/uuid.html
|
||||||
|
|
||||||
|
if the object is dynamic, it raises an error
|
||||||
"""
|
"""
|
||||||
|
if self.dynamic:
|
||||||
|
raise ValueError("Dynamic objects have no idea, because they are not in the database")
|
||||||
|
|
||||||
if self.id_ is None:
|
if self.id_ is None:
|
||||||
self.id_ = str(uuid.uuid4())
|
self.id_ = str(uuid.uuid4())
|
||||||
logger.info(f"id for {self.__str__()} isn't set. Setting to {self.id_}")
|
logger.info(f"id for {self.__str__()} isn't set. Setting to {self.id_}")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
from typing import List
|
from typing import List, Tuple
|
||||||
from mutagen.easyid3 import EasyID3
|
from mutagen.easyid3 import EasyID3
|
||||||
|
|
||||||
from ...utils.shared import (
|
from ...utils.shared import (
|
||||||
@ -258,6 +258,7 @@ class Album(DatabaseObject):
|
|||||||
country TEXT,
|
country TEXT,
|
||||||
barcode TEXT,
|
barcode TEXT,
|
||||||
song_id BIGINT,
|
song_id BIGINT,
|
||||||
|
is_split BOOLEAN NOT NULL DEFAULT 0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -271,8 +272,11 @@ class Album(DatabaseObject):
|
|||||||
date: str = None,
|
date: str = None,
|
||||||
country: str = None,
|
country: str = None,
|
||||||
barcode: str = None,
|
barcode: str = None,
|
||||||
|
is_split: bool = False,
|
||||||
|
albumsort: int = None,
|
||||||
|
dynamic: bool = False
|
||||||
) -> None:
|
) -> None:
|
||||||
DatabaseObject.__init__(self, id_=id_)
|
DatabaseObject.__init__(self, id_=id_, dynamic=dynamic)
|
||||||
self.title: str = title
|
self.title: str = title
|
||||||
self.copyright: str = copyright_
|
self.copyright: str = copyright_
|
||||||
self.album_status: str = album_status
|
self.album_status: str = album_status
|
||||||
@ -281,6 +285,8 @@ class Album(DatabaseObject):
|
|||||||
self.date: str = date
|
self.date: str = date
|
||||||
self.country: str = country
|
self.country: str = country
|
||||||
self.barcode: str = barcode
|
self.barcode: str = barcode
|
||||||
|
self.is_split: bool = is_split
|
||||||
|
self.albumsort: int | None = albumsort
|
||||||
|
|
||||||
self.tracklist: List[Song] = []
|
self.tracklist: List[Song] = []
|
||||||
|
|
||||||
@ -294,7 +300,7 @@ class Album(DatabaseObject):
|
|||||||
self.tracklist = tracklist
|
self.tracklist = tracklist
|
||||||
|
|
||||||
for i, track in enumerate(self.tracklist):
|
for i, track in enumerate(self.tracklist):
|
||||||
track.tracksort = i+1
|
track.tracksort = i + 1
|
||||||
|
|
||||||
def add_song(self, song: Song):
|
def add_song(self, song: Song):
|
||||||
for existing_song in self.tracklist:
|
for existing_song in self.tracklist:
|
||||||
@ -303,3 +309,90 @@ class Album(DatabaseObject):
|
|||||||
|
|
||||||
song.tracksort = len(self.tracklist)
|
song.tracksort = len(self.tracklist)
|
||||||
self.tracklist.append(song)
|
self.tracklist.append(song)
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
All objects dependent on Artist
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class ArtistSong(Song):
|
||||||
|
"""
|
||||||
|
A subclass of Song with the additional attribute is_feature, which
|
||||||
|
makes only sense when in/from the Artist class
|
||||||
|
"""
|
||||||
|
is_feature: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
class Artist(DatabaseObject):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
id_: str = None,
|
||||||
|
name: str = None,
|
||||||
|
discography: List[Album] = [],
|
||||||
|
features: List[Song] = []
|
||||||
|
):
|
||||||
|
DatabaseObject.__init__(self, id_=id_)
|
||||||
|
|
||||||
|
self.name: str | None = name
|
||||||
|
|
||||||
|
self.songs: List[ArtistSong] = []
|
||||||
|
self.album_refs: List[Album] = []
|
||||||
|
self.song
|
||||||
|
|
||||||
|
self.set_discography(discography)
|
||||||
|
self.set_features(features)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name or ""
|
||||||
|
|
||||||
|
def add_album(self, album: Album):
|
||||||
|
self.album_refs.append(album)
|
||||||
|
|
||||||
|
for song in album.tracklist:
|
||||||
|
song.__class__ = ArtistSong
|
||||||
|
song.is_feature = False
|
||||||
|
|
||||||
|
self.songs.append(song)
|
||||||
|
|
||||||
|
def set_discography(self, discography: List[Album]):
|
||||||
|
"""
|
||||||
|
:param discography:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
for album in discography:
|
||||||
|
self.add_album(album)
|
||||||
|
|
||||||
|
def get_discography(self) -> List[Album]:
|
||||||
|
flat_copy_discography = self.discography.copy()
|
||||||
|
feature_release = Album(
|
||||||
|
title="features",
|
||||||
|
copyright_=self.name,
|
||||||
|
album_status="dynamically generated",
|
||||||
|
is_split=True,
|
||||||
|
albumsort=666,
|
||||||
|
dynamic=True
|
||||||
|
)
|
||||||
|
for song in self.songs:
|
||||||
|
if song.is_feature:
|
||||||
|
feature_release.add_song(song)
|
||||||
|
|
||||||
|
flat_copy_discography.append(feature_release)
|
||||||
|
return flat_copy_discography
|
||||||
|
|
||||||
|
def set_features(self, feature_tracks: List[Song]):
|
||||||
|
for song in feature_tracks:
|
||||||
|
song.__class__ = ArtistSong
|
||||||
|
song.is_feature = True
|
||||||
|
|
||||||
|
self.songs.append(song)
|
||||||
|
|
||||||
|
def get_features(self) -> List[ArtistSong]:
|
||||||
|
feature_releases = []
|
||||||
|
for song in self.songs:
|
||||||
|
if song.is_feature:
|
||||||
|
feature_releases.append(song)
|
||||||
|
return feature_releases
|
||||||
|
|
||||||
|
discography = property(fget=get_discography, fset=set_discography)
|
||||||
|
features = property(fget=get_features, fset=set_features)
|
||||||
|
@ -21,12 +21,6 @@ CREATE TABLE Source
|
|||||||
FOREIGN KEY(song_id) REFERENCES Song(id)
|
FOREIGN KEY(song_id) REFERENCES Song(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE Artist
|
|
||||||
(
|
|
||||||
id INTEGER AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
name TEXT
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE Album
|
CREATE TABLE Album
|
||||||
(
|
(
|
||||||
@ -38,7 +32,9 @@ CREATE TABLE Album
|
|||||||
year TEXT,
|
year TEXT,
|
||||||
date TEXT,
|
date TEXT,
|
||||||
country TEXT,
|
country TEXT,
|
||||||
barcode TEXT
|
barcode TEXT,
|
||||||
|
album_sort INT,
|
||||||
|
is_split BOOLEAN NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE Target
|
CREATE TABLE Target
|
||||||
@ -59,10 +55,17 @@ CREATE TABLE Lyrics
|
|||||||
FOREIGN KEY(song_id) REFERENCES Song(id)
|
FOREIGN KEY(song_id) REFERENCES Song(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Artist
|
||||||
|
(
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name TEXT
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE SongArtist
|
CREATE TABLE SongArtist
|
||||||
(
|
(
|
||||||
song_id BIGINT,
|
song_id BIGINT NOT NULL,
|
||||||
artist_id INTEGER,
|
artist_id BIGINT NOT NULL,
|
||||||
|
is_feature BOOLEAN NOT NULL DEFAULT 0,
|
||||||
FOREIGN KEY(song_id) REFERENCES Song(id),
|
FOREIGN KEY(song_id) REFERENCES Song(id),
|
||||||
FOREIGN KEY(artist_id) REFERENCES Artist(id)
|
FOREIGN KEY(artist_id) REFERENCES Artist(id)
|
||||||
);
|
);
|
||||||
@ -70,7 +73,7 @@ CREATE TABLE SongArtist
|
|||||||
CREATE TABLE AlbumArtist
|
CREATE TABLE AlbumArtist
|
||||||
(
|
(
|
||||||
album_id BIGINT,
|
album_id BIGINT,
|
||||||
artist_id INTEGER,
|
artist_id BIGINT,
|
||||||
FOREIGN KEY(album_id) REFERENCES Album(id),
|
FOREIGN KEY(album_id) REFERENCES Album(id),
|
||||||
FOREIGN KEY(artist_id) REFERENCES Artist(id)
|
FOREIGN KEY(artist_id) REFERENCES Artist(id)
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user