added genre

This commit is contained in:
Lars Noack 2023-01-16 14:31:43 +01:00
parent 7817402a19
commit 48b1ab9288
5 changed files with 11 additions and 4 deletions

View File

@ -53,6 +53,7 @@ album_input.artists = [
] ]
song_input = Song( song_input = Song(
genre="HS Core",
title="Vein Deep in the Solution", title="Vein Deep in the Solution",
length=666, length=666,
isrc="US-S1Z-99-00001", isrc="US-S1Z-99-00001",

View File

@ -27,7 +27,7 @@ logger = logging.getLogger("database")
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, Song.tracksort,
Target.id AS target_id, Target.file AS file, Target.path AS path 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
WHERE {where}; WHERE {where};
@ -173,9 +173,10 @@ class Database:
song.isrc, song.isrc,
song.length, song.length,
song.get_album_id(), song.get_album_id(),
song.tracksort song.tracksort,
song.genre
) )
query = f"INSERT OR REPLACE INTO {table} (id, name, isrc, length, album_id, tracksort) VALUES (?, ?, ?, ?, ?, ?);" query = f"INSERT OR REPLACE INTO {table} (id, name, isrc, length, album_id, tracksort, genre) VALUES (?, ?, ?, ?, ?, ?, ?);"
self.cursor.execute(query, values) self.cursor.execute(query, values)
self.connection.commit() self.connection.commit()
@ -475,6 +476,7 @@ class Database:
isrc=song_result['isrc'], isrc=song_result['isrc'],
length=song_result['length'], length=song_result['length'],
tracksort=song_result['tracksort'], tracksort=song_result['tracksort'],
genre=song_result['genre'],
target=Target( target=Target(
id_=song_result['target_id'], id_=song_result['target_id'],
file=song_result['file'], file=song_result['file'],

View File

@ -93,6 +93,7 @@ class Song(DatabaseObject, ID3Metadata):
isrc: str = None, isrc: str = None,
length: int = None, length: int = None,
tracksort: int = None, tracksort: int = None,
genre: str = None,
sources: List[Source] = None, sources: List[Source] = None,
target: Target = None, target: Target = None,
lyrics: List[Lyrics] = None, lyrics: List[Lyrics] = None,
@ -115,6 +116,7 @@ class Song(DatabaseObject, ID3Metadata):
self.mb_id: str | None = mb_id self.mb_id: str | None = mb_id
self.album_name: str | None = album_name self.album_name: str | None = album_name
self.tracksort: int | None = tracksort self.tracksort: int | None = tracksort
self.genre: str = genre
self.sources: List[Source] = [] self.sources: List[Source] = []
if sources is not None: if sources is not None:
@ -175,7 +177,8 @@ class Song(DatabaseObject, ID3Metadata):
return { return {
ID3_MAPPING.TITLE: [self.title], ID3_MAPPING.TITLE: [self.title],
ID3_MAPPING.ISRC: [self.isrc], ID3_MAPPING.ISRC: [self.isrc],
ID3_MAPPING.LENGTH: [str(self.length)] ID3_MAPPING.LENGTH: [str(self.length)],
ID3_MAPPING.GENRE: [self.genre]
} }
def get_metadata(self) -> Metadata: def get_metadata(self) -> Metadata:

View File

@ -5,6 +5,7 @@ CREATE TABLE Song
isrc TEXT, isrc TEXT,
length INT, -- length is in milliseconds (could be wrong) length INT, -- length is in milliseconds (could be wrong)
tracksort INT, tracksort INT,
genre TEXT,
album_id BIGINT, album_id BIGINT,
FOREIGN KEY(album_id) REFERENCES Album(id) FOREIGN KEY(album_id) REFERENCES Album(id)
); );

BIN
test.db

Binary file not shown.