This commit is contained in:
Lars Noack
2023-01-12 16:25:50 +01:00
parent b6a8966503
commit 133e360562
10 changed files with 84 additions and 50 deletions

View File

@@ -4,17 +4,18 @@ import logging
from typing import List, Tuple
from pkg_resources import resource_string
from .objects.database_object import Reference
from .objects.parents import Reference
from .objects.source import Source
from .objects import (
Song,
Lyrics,
Metadata,
Target,
Artist,
Source,
Album
)
logger = logging.getLogger("database")
# Due to this not being deployed on a Server **HOPEFULLY**

View File

@@ -1,13 +1,14 @@
from . import (
song,
id3_mapping
id3_mapping,
source
)
ID3_MAPPING = id3_mapping.Mapping
Song = song.Song
Artist = song.Artist
Source = song.Source
Source = source.Source
Target = song.Target
Metadata = song.Metadata
Lyrics = song.Lyrics

View File

@@ -1,7 +1,7 @@
from ...utils.shared import (
DATABASE_LOGGER as logger
)
from .database_object import (
from .parents import (
DatabaseObject,
Reference
)

View File

@@ -45,3 +45,22 @@ class DatabaseObject:
id = property(fget=get_id)
reference = property(fget=get_reference)
class SongAttribute:
def __init__(self, song=None):
# the reference to the song the lyrics belong to
self.song = song
def add_song(self, song):
self.song = song
def get_ref_song_id(self):
if self.song is None:
return None
return self.song.reference.id
def set_ref_song_id(self, song_id):
self.song_ref = Reference(song_id)
song_ref_id = property(fget=get_ref_song_id, fset=set_ref_song_id)

View File

@@ -7,33 +7,19 @@ from ...utils.shared import (
MUSIC_DIR,
DATABASE_LOGGER as logger
)
from .database_object import (
from .parents import (
DatabaseObject,
Reference
Reference,
SongAttribute
)
from .source import Source
"""
All Objects dependent
"""
class SongAttribute:
def __init__(self, song=None):
# the reference to the song the lyrics belong to
self.song = song
def add_song(self, song):
self.song = song
def get_ref_song_id(self):
if self.song is None:
return None
return self.song.reference.id
def set_ref_song_id(self, song_id):
self.song_ref = Reference(song_id)
song_ref_id = property(fget=get_ref_song_id, fset=set_ref_song_id)
class Metadata:
@@ -58,7 +44,9 @@ class Metadata:
return
if type(value) != list:
raise ValueError(f"can only set attribute to list, not {type(value)}")
self.id3_attributes[key] = value
# self.id3_attributes[key] = [value[0], "HHHHSSSS"]
self.id3_attributes[key] = value[0]
def __getitem__(self, key):
if key not in self.id3_attributes:
@@ -96,24 +84,7 @@ class Metadata:
return "\n".join(rows)
class Source(DatabaseObject, SongAttribute):
"""
create somehow like that
```python
# url won't be a valid one due to it being just an example
Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd")
```
"""
def __init__(self, id_: str = None, src: str = None, url: str = None) -> None:
DatabaseObject.__init__(self, id_=id_)
SongAttribute.__init__(self)
self.src = src
self.url = url
def __str__(self):
return f"{self.src}: {self.url}"
class Target(DatabaseObject, SongAttribute):

View File

@@ -0,0 +1,41 @@
from enum import Enum
from .parents import (
DatabaseObject,
SongAttribute
)
class sources(Enum):
YOUTUBE = "youtube"
MUSIFY = "musify"
@classmethod
def get_homepage(cls, attribute) -> str:
homepage_map = {
cls.YOUTUBE: "https://www.youtube.com/",
cls.MUSIFY: "https://musify.club/"
}
return homepage_map[attribute]
class Source(DatabaseObject, SongAttribute):
"""
create somehow like that
```python
# url won't be a valid one due to it being just an example
Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd")
```
"""
def __init__(self, id_: str = None, src: str = None, url: str = None) -> None:
DatabaseObject.__init__(self, id_=id_)
SongAttribute.__init__(self)
self.src = sources(src)
self.url = url
def __str__(self):
return f"{self.src}: {self.url}"
homepage = property(fget=lambda self: sources.get_homepage(self.src))

View File

@@ -7,7 +7,7 @@ from ..utils.shared import (
MUSIC_DIR,
SONG_LOGGER as logger
)
from .objects.database_object import DatabaseObject
from .objects.parents import DatabaseObject
class Metadata:
def __init__(self) -> None: