added type to src

This commit is contained in:
Lars Noack
2023-01-20 10:56:40 +01:00
parent a876ebc708
commit 4b4a3e8fc3
24 changed files with 316 additions and 307 deletions

View File

@@ -6,7 +6,8 @@ from music_kraken import (
Source,
Album,
Artist,
ID3Timestamp
ID3Timestamp,
source_types
)
from music_kraken.tagging import (
@@ -64,8 +65,8 @@ song_input = Song(
Lyrics(text="test", language="en")
],
sources=[
Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd"),
Source(src="musify", url="https://ln.topdf.de/Music-Kraken/")
Source(source_types.SONG, src="youtube", url="https://youtu.be/dfnsdajlhkjhsd"),
Source(source_types.SONG, src="musify", url="https://ln.topdf.de/Music-Kraken/")
],
album=album_input,
main_artist_list=[main_artist],

View File

@@ -41,6 +41,7 @@ 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
Target = database.Target
Lyrics = database.Lyrics
Album = database.Album

View File

@@ -4,6 +4,7 @@ from . import (
)
ID3Timestamp = objects.ID3Timestamp
source_types = objects.source_types
Song = objects.Song
Source = objects.Source
Target = objects.Target

View File

@@ -113,6 +113,7 @@ class Database:
return self.push_artist(artist=db_object)
if type(db_object) == Source:
# needs to have the property type_enum or type_str set
return self.push_source(source=db_object)
if type(db_object) == Album:
@@ -185,6 +186,7 @@ class Database:
# add sources
for source in song.sources:
source.add_song(song)
source.type_enum = source_types.SONG
self.push_source(source=source)
# add lyrics
@@ -221,6 +223,8 @@ 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")
@@ -228,7 +232,7 @@ class Database:
query = f"INSERT OR REPLACE INTO {table} (id, type, song_id, src, url) VALUES (?, ?, ?, ?, ?);"
values = (
source.id,
source.type,
source.type_str,
source.song_ref_id,
source.site_str,
source.url
@@ -359,11 +363,12 @@ class Database:
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'],
type_str=type_enum.value
url=source_row['url']
) for source_row in source_rows]
def pull_artist_song(self, song_ref: Reference = None, artist_ref: Reference = None) -> List[tuple]:

View File

@@ -42,13 +42,11 @@ class Source(DatabaseObject, SongAttribute, ID3Metadata):
```
"""
def __init__(self, id_: str = None, src: str = None, url: str = None, type_str: str = None) -> None:
def __init__(self, type_enum, id_: str = None, src: str = None, url: str = None) -> None:
DatabaseObject.__init__(self, id_=id_)
SongAttribute.__init__(self)
self.type_enum = None
if type_str is not None:
self.type_enum = source_types(type_str)
self.type_enum = type_enum
self.src = sources(src)
self.url = url
@@ -62,4 +60,5 @@ class Source(DatabaseObject, SongAttribute, ID3Metadata):
return f"{self.src}: {self.url}"
site_str = property(fget=lambda self: self.src.value)
type_str = property(fget=lambda self: self.type_enum.value)
homepage = property(fget=lambda self: sources.get_homepage(self.src))

View File

@@ -14,7 +14,7 @@ CREATE TABLE Song
CREATE TABLE Source
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
type TEXT NOT NULL
type TEXT NOT NULL,
src TEXT NOT NULL,
url TEXT NOT NULL,
certainty INT NOT NULL DEFAULT 0, -- certainty=0 -> it is definitely a valid source