added type to src
This commit is contained in:
@@ -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
|
||||
|
@@ -4,6 +4,7 @@ from . import (
|
||||
)
|
||||
|
||||
ID3Timestamp = objects.ID3Timestamp
|
||||
source_types = objects.source_types
|
||||
Song = objects.Song
|
||||
Source = objects.Source
|
||||
Target = objects.Target
|
||||
|
@@ -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]:
|
||||
|
@@ -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))
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user