This commit is contained in:
Lars Noack
2023-01-17 18:07:06 +01:00
parent be44d35fab
commit a876ebc708
21 changed files with 392 additions and 501 deletions

View File

@@ -15,7 +15,8 @@ from .objects import (
Target,
Artist,
Album,
ID3Timestamp
ID3Timestamp,
source_types
)
@@ -33,7 +34,7 @@ LEFT JOIN Target ON Song.id=Target.song_id
WHERE {where};
"""
SOURCE_QUERY = """
SELECT id, src, url, song_id
SELECT id, type, src, url, song_id
FROM Source
WHERE {where};
"""
@@ -224,9 +225,10 @@ class Database:
logger.warning("the Source don't refer to a song")
table = "Source"
query = f"INSERT OR REPLACE INTO {table} (id, song_id, src, url) VALUES (?, ?, ?, ?);"
query = f"INSERT OR REPLACE INTO {table} (id, type, song_id, src, url) VALUES (?, ?, ?, ?, ?);"
values = (
source.id,
source.type,
source.song_ref_id,
source.site_str,
source.url
@@ -336,13 +338,14 @@ class Database:
language=lyrics_row['language']
) for lyrics_row in lyrics_rows]
def pull_sources(self, song_ref: Reference = None, source_ref: Reference = None) -> List[Source]:
def pull_sources(self, type_enum, 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.
**If neither song_ref nor source_ref are passed in it will return ALL sources**
:param song_ref:
:param source_ref:
:param type_str: the thing the source belongs to like eg. "song" or "album"
:return:
"""
@@ -359,7 +362,8 @@ class Database:
return [Source(
id_=source_row['id'],
src=source_row['src'],
url=source_row['url']
url=source_row['url'],
type_str=type_enum.value
) for source_row in source_rows]
def pull_artist_song(self, song_ref: Reference = None, artist_ref: Reference = None) -> List[tuple]:
@@ -482,7 +486,7 @@ class Database:
file=song_result['file'],
path=song_result['path']
),
sources=self.pull_sources(song_ref=Reference(id_=song_id)),
sources=self.pull_sources(type_enum=source_types.SONG, song_ref=Reference(id_=song_id)),
lyrics=self.pull_lyrics(song_ref=Reference(id_=song_id)),
)

View File

@@ -7,6 +7,8 @@ from . import (
ID3_MAPPING = metadata.Mapping
ID3Timestamp = metadata.ID3Timestamp
source_types = source.source_types
Song = song.Song
Artist = song.Artist
Source = source.Source

View File

@@ -78,11 +78,3 @@ CREATE TABLE AlbumArtist
FOREIGN KEY(album_id) REFERENCES Album(id),
FOREIGN KEY(artist_id) REFERENCES Artist(id)
);
CREATE TABLE id3
(
frame TEXT, -- 4 capital leters like TXXX
value TEXT,
song_id BIGINT,
FOREIGN KEY(song_id) REFERENCES Song(id)
);