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

51 lines
1.3 KiB
Python
Raw Normal View History

2023-01-12 15:25:50 +00:00
from enum import Enum
2023-01-12 16:14:21 +00:00
from .id3_mapping 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
)
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]
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")
```
"""
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
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-12 16:14:21 +00:00
type_str = property(fget=lambda self: self.src.value)
2023-01-12 15:25:50 +00:00
homepage = property(fget=lambda self: sources.get_homepage(self.src))