music-kraken-core/src/music_kraken/database/objects/source.py

65 lines
1.8 KiB
Python
Raw Normal View History

2023-01-12 15:25:50 +00:00
from enum import Enum
2023-01-12 22:01:19 +00:00
from .metadata import Mapping
2023-01-12 15:25:50 +00:00
from .parents import (
DatabaseObject,
2023-01-12 16:14:21 +00:00
SongAttribute,
ID3Metadata
2023-01-12 15:25:50 +00:00
)
2023-01-16 14:37:04 +00:00
class source_types(Enum):
SONG = "song"
ALBUM = "album"
ARTIST = "artist"
LYRICS = "lyrics"
2023-01-12 15:25:50 +00:00
class sources(Enum):
YOUTUBE = "youtube"
MUSIFY = "musify"
2023-01-16 14:37:04 +00:00
GENIUS = "genius"
MUSICBRAINZ = "musicbrainz"
ENCYCLOPAEDIA_METALLUM = "encyclopaedia metallum"
2023-01-12 15:25:50 +00:00
@classmethod
def get_homepage(cls, attribute) -> str:
homepage_map = {
cls.YOUTUBE: "https://www.youtube.com/",
2023-01-16 14:37:04 +00:00
cls.MUSIFY: "https://musify.club/",
cls.MUSICBRAINZ:"https://musicbrainz.org/",
cls.ENCYCLOPAEDIA_METALLUM: "https://www.metal-archives.com/",
cls.GENIUS: "https://genius.com/"
2023-01-12 15:25:50 +00:00
}
return homepage_map[attribute]
2023-01-12 16:14:21 +00:00
class Source(DatabaseObject, SongAttribute, ID3Metadata):
2023-01-12 15:25:50 +00:00
"""
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")
```
"""
2023-01-20 09:56:40 +00:00
def __init__(self, type_enum, id_: str = None, src: str = None, url: str = None) -> None:
2023-01-12 15:25:50 +00:00
DatabaseObject.__init__(self, id_=id_)
SongAttribute.__init__(self)
2023-01-20 09:56:40 +00:00
self.type_enum = type_enum
2023-01-12 15:25:50 +00:00
self.src = sources(src)
self.url = url
2023-01-12 16:14:21 +00:00
def get_id3_dict(self) -> dict:
return {
Mapping.FILE_WEBPAGE_URL: [self.url],
Mapping.SOURCE_WEBPAGE_URL: [self.homepage]
}
2023-01-12 15:25:50 +00:00
def __str__(self):
return f"{self.src}: {self.url}"
2023-01-16 14:37:04 +00:00
site_str = property(fget=lambda self: self.src.value)
2023-01-20 09:56:40 +00:00
type_str = property(fget=lambda self: self.type_enum.value)
2023-01-12 15:25:50 +00:00
homepage = property(fget=lambda self: sources.get_homepage(self.src))