fixed exceptions

This commit is contained in:
Hellow2 2023-03-10 10:13:35 +01:00
parent 0423cb3139
commit 635c8b87a4
7 changed files with 45 additions and 50 deletions

View File

@ -1,14 +1,5 @@
import music_kraken
from music_kraken import objects from music_kraken import objects
from music_kraken.tagging import (
AudioMetadata,
write_metadata,
write_many_metadata
)
import music_kraken.database.old_database as db
import pycountry import pycountry
import logging import logging
@ -19,10 +10,7 @@ def div(msg: str = ""):
print("-" * 50 + msg + "-" * 50) print("-" * 50 + msg + "-" * 50)
cache.reset() def print_song(song_: objects.Song):
def print_song(song_: Song):
print(str(song_.metadata)) print(str(song_.metadata))
print("----album--") print("----album--")
print(song_.album) print(song_.album)
@ -34,49 +22,56 @@ def print_song(song_: Song):
print("\n") print("\n")
song = Song( song = objects.Song(
genre="HS Core", 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",
tracksort=2, tracksort=2,
target=Target(file="song.mp3", path="~/Music"), target=[
lyrics=[ objects.Target(file="song.mp3", path="example")
Lyrics(text="these are some depressive lyrics", language="en"), ],
Lyrics(text="Dies sind depressive Lyrics", language="de") lyrics_list=[
objects.Lyrics(text="these are some depressive lyrics", language="en"),
objects.Lyrics(text="Dies sind depressive Lyrics", language="de")
], ],
source_list=[ source_list=[
Source(SourcePages.YOUTUBE, "https://youtu.be/dfnsdajlhkjhsd"), objects.Source(objects.SourcePages.YOUTUBE, "https://youtu.be/dfnsdajlhkjhsd"),
Source(SourcePages.MUSIFY, "https://ln.topdf.de/Music-Kraken/") objects.Source(objects.SourcePages.MUSIFY, "https://ln.topdf.de/Music-Kraken/")
], ],
album=Album( album_list=[
objects.Album(
title="One Final Action", title="One Final Action",
date=ID3Timestamp(year=1986, month=3, day=1), date=objects.ID3Timestamp(year=1986, month=3, day=1),
language=pycountry.languages.get(alpha_2="en"), language=pycountry.languages.get(alpha_2="en"),
label="cum productions", label="cum productions",
source_list=[ source_list=[
Source(SourcePages.ENCYCLOPAEDIA_METALLUM, objects.Source(objects.SourcePages.ENCYCLOPAEDIA_METALLUM, "https://www.metal-archives.com/albums/I%27m_in_a_Coffin/One_Final_Action/207614")
"https://www.metal-archives.com/albums/I%27m_in_a_Coffin/One_Final_Action/207614")
]
),
main_artist_list=[
Artist(
name="I'm in a coffin",
source_list=[
Source(SourcePages.ENCYCLOPAEDIA_METALLUM,
"https://www.metal-archives.com/bands/I%27m_in_a_Coffin/127727")
] ]
), ),
Artist(name="some_split_artist")
], ],
feature_artist_list=[Artist(name="Ruffiction")], main_artist_list=[
objects.Artist(
name="I'm in a coffin",
source_list=[
objects.Source(
objects.SourcePages.ENCYCLOPAEDIA_METALLUM,
"https://www.metal-archives.com/bands/I%27m_in_a_Coffin/127727"
)
]
),
objects.Artist(name="some_split_artist")
],
feature_artist_list=[objects.Artist(name="Ruffiction")],
) )
print_song(song) print(song)
exit()
div() div()
song_ref = song.reference song_ref = song.reference
cache.push([song])
# getting song by song ref # getting song by song ref
song_list = cache.pull_songs(song_ref=song_ref) song_list = cache.pull_songs(song_ref=song_ref)

View File

@ -15,7 +15,6 @@ ID3Timestamp = metadata.ID3Timestamp
Source = source.Source Source = source.Source
SourceTypes = source.SourceTypes SourceTypes = source.SourceTypes
SourcePages = source.SourcePages SourcePages = source.SourcePages
SourceAttribute = source.SourceAttribute
Song = song.Song Song = song.Song
Artist = song.Artist Artist = song.Artist

View File

@ -34,7 +34,8 @@ class Collection:
""" """
self._attribute_to_object_map: Dict[str, Dict[object, DatabaseObject]] = defaultdict(dict) self._attribute_to_object_map: Dict[str, Dict[object, DatabaseObject]] = defaultdict(dict)
self.extend(data, merge_on_conflict=True) if data is not None:
self.extend(data, merge_on_conflict=True)
def sort(self, reverse: bool = False, **kwargs): def sort(self, reverse: bool = False, **kwargs):
self._data.sort(reverse=reverse, **kwargs) self._data.sort(reverse=reverse, **kwargs)
@ -51,7 +52,7 @@ class Collection:
""" """
# if the element type has been defined in the initializer it checks if the type matches # if the element type has been defined in the initializer it checks if the type matches
if self.element_type is not None and isinstance(element, self.element_type): if self.element_type is not None and not isinstance(element, self.element_type):
raise TypeError(f"{type(element)} is not the set type {self.element_type}") raise TypeError(f"{type(element)} is not the set type {self.element_type}")
for name, value in element.indexing_values: for name, value in element.indexing_values:

View File

@ -18,7 +18,7 @@ class Lyrics(DatabaseObject):
source_list: List[Source] = None, source_list: List[Source] = None,
**kwargs **kwargs
) -> None: ) -> None:
DatabaseObject.__init__(_id=_id, dynamic=dynamic) DatabaseObject.__init__(self, _id=_id, dynamic=dynamic)
self.text: FormattedText = text self.text: FormattedText = text
self.language: pycountry.Languages = language self.language: pycountry.Languages = language

View File

@ -20,7 +20,6 @@ from .source import (
Source, Source,
SourceTypes, SourceTypes,
SourcePages, SourcePages,
SourceAttribute,
SourceCollection SourceCollection
) )
from .formatted_text import FormattedText from .formatted_text import FormattedText
@ -462,7 +461,7 @@ Label
""" """
class Label(MainObject, SourceAttribute): class Label(MainObject):
COLLECTION_ATTRIBUTES = ("album_collection", "current_artist_collection") COLLECTION_ATTRIBUTES = ("album_collection", "current_artist_collection")
SIMPLE_ATTRIBUTES = ("name",) SIMPLE_ATTRIBUTES = ("name",)

View File

@ -47,7 +47,7 @@ class SourcePages(Enum):
return homepage_map[attribute] return homepage_map[attribute]
class Source(DatabaseObject, MetadataAttribute): class Source(DatabaseObject):
""" """
create somehow like that create somehow like that
```python ```python
@ -95,14 +95,14 @@ class Source(DatabaseObject, MetadataAttribute):
if url.startswith("https://twitter"): if url.startswith("https://twitter"):
return cls(SourcePages.TWITTER, url) return cls(SourcePages.TWITTER, url)
def get_song_metadata(self) -> MetadataAttribute.Metadata: def get_song_metadata(self) -> Metadata:
return MetadataAttribute.Metadata({ return Metadata({
Mapping.FILE_WEBPAGE_URL: [self.url], Mapping.FILE_WEBPAGE_URL: [self.url],
Mapping.SOURCE_WEBPAGE_URL: [self.homepage] Mapping.SOURCE_WEBPAGE_URL: [self.homepage]
}) })
def get_artist_metadata(self) -> MetadataAttribute.Metadata: def get_artist_metadata(self) -> Metadata:
return MetadataAttribute.Metadata({ return Metadata({
Mapping.ARTIST_WEBPAGE_URL: [self.url] Mapping.ARTIST_WEBPAGE_URL: [self.url]
}) })
@ -136,10 +136,11 @@ class Source(DatabaseObject, MetadataAttribute):
class SourceCollection(Collection): class SourceCollection(Collection):
def __init__(self, source_list: List[Source]): def __init__(self, source_list: List[Source]):
super().__init__(data=source_list, element_type=Source)
self._page_to_source_list: Dict[SourcePages, List[Source]] = defaultdict(list) self._page_to_source_list: Dict[SourcePages, List[Source]] = defaultdict(list)
super().__init__(data=source_list, element_type=Source)
def map_element(self, source: Source): def map_element(self, source: Source):
super().map_element(source) super().map_element(source)

View File

@ -2,7 +2,7 @@ from typing import (
List List
) )
from ..database import ( from ..objects import (
Song, Song,
Source, Source,
Album, Album,