From 54e24df0d1d0e606b2d6a7b8c7b1683796b24d69 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Tue, 18 Apr 2023 11:18:17 +0200 Subject: [PATCH] refactored source --- src/actual_donwload.py | 4 +- src/music_kraken/objects/source.py | 62 ++++++------------------ src/music_kraken/utils/enums/__init__.py | 0 src/music_kraken/utils/enums/source.py | 45 +++++++++++++++++ 4 files changed, 61 insertions(+), 50 deletions(-) create mode 100644 src/music_kraken/utils/enums/__init__.py create mode 100644 src/music_kraken/utils/enums/source.py diff --git a/src/actual_donwload.py b/src/actual_donwload.py index 8d446be..5a0ce7f 100644 --- a/src/actual_donwload.py +++ b/src/actual_donwload.py @@ -52,7 +52,7 @@ def real_download(): if __name__ == "__main__": music_kraken.cli(genre="test", command_list=[ - "#a Ghost Bath", - "1", + "#a Molchat Doma", + "0", "ok" ]) diff --git a/src/music_kraken/objects/source.py b/src/music_kraken/objects/source.py index 901a623..25b17ad 100644 --- a/src/music_kraken/objects/source.py +++ b/src/music_kraken/objects/source.py @@ -3,55 +3,12 @@ from enum import Enum from typing import List, Dict, Tuple, Optional from urllib.parse import urlparse +from ..utils.enums.source import SourcePages, SourceTypes from .metadata import Mapping, Metadata from .parents import DatabaseObject from .collection import Collection -class SourceTypes(Enum): - SONG = "song" - ALBUM = "album" - ARTIST = "artist" - LYRICS = "lyrics" - - -class SourcePages(Enum): - YOUTUBE = "youtube" - MUSIFY = "musify" - GENIUS = "genius" - MUSICBRAINZ = "musicbrainz" - ENCYCLOPAEDIA_METALLUM = "encyclopaedia metallum" - BANDCAMP = "bandcamp" - DEEZER = "deezer" - SPOTIFY = "spotify" - - # This has nothing to do with audio, but bands can be here - WIKIPEDIA = "wikipedia" - INSTAGRAM = "instagram" - FACEBOOK = "facebook" - TWITTER = "twitter" # I will use nitter though lol - MYSPACE = "myspace" # Yes somehow this ancient site is linked EVERYWHERE - - @classmethod - def get_homepage(cls, attribute) -> str: - homepage_map = { - cls.YOUTUBE: "https://www.youtube.com/", - cls.MUSIFY: "https://musify.club/", - cls.MUSICBRAINZ: "https://musicbrainz.org/", - cls.ENCYCLOPAEDIA_METALLUM: "https://www.metal-archives.com/", - cls.GENIUS: "https://genius.com/", - cls.BANDCAMP: "https://bandcamp.com/", - cls.DEEZER: "https://www.deezer.com/", - cls.INSTAGRAM: "https://www.instagram.com/", - cls.FACEBOOK: "https://www.facebook.com/", - cls.SPOTIFY: "https://open.spotify.com/", - cls.TWITTER: "https://twitter.com/", - cls.MYSPACE: "https://myspace.com/", - cls.WIKIPEDIA: "https://en.wikipedia.org/wiki/Main_Page" - } - return homepage_map[attribute] - - class Source(DatabaseObject): """ create somehow like that @@ -62,18 +19,27 @@ class Source(DatabaseObject): """ COLLECTION_ATTRIBUTES = tuple() SIMPLE_ATTRIBUTES = { - "type_enum": None, "page_enum": None, - "url": None + "url": None, + "referer_page": None, + "audio_url": None } - def __init__(self, page_enum: SourcePages, url: str, id_: str = None, type_enum=None) -> None: + def __init__( + self, + page_enum: SourcePages, + url: str, + id_: str = None, + referer_page: SourceTypes = None, + adio_url: str = None + ) -> None: DatabaseObject.__init__(self, id_=id_) - self.type_enum = type_enum self.page_enum = page_enum + self.referer_page = page_enum if referer_page is None else referer_page self.url = url + self.audio_url = adio_url @classmethod def match_url(cls, url: str) -> Optional["Source"]: diff --git a/src/music_kraken/utils/enums/__init__.py b/src/music_kraken/utils/enums/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/music_kraken/utils/enums/source.py b/src/music_kraken/utils/enums/source.py new file mode 100644 index 0000000..b536e5c --- /dev/null +++ b/src/music_kraken/utils/enums/source.py @@ -0,0 +1,45 @@ +from enum import Enum + + +class SourceTypes(Enum): + SONG = "song" + ALBUM = "album" + ARTIST = "artist" + LYRICS = "lyrics" + + +class SourcePages(Enum): + YOUTUBE = "youtube" + MUSIFY = "musify" + GENIUS = "genius" + MUSICBRAINZ = "musicbrainz" + ENCYCLOPAEDIA_METALLUM = "encyclopaedia metallum" + BANDCAMP = "bandcamp" + DEEZER = "deezer" + SPOTIFY = "spotify" + + # This has nothing to do with audio, but bands can be here + WIKIPEDIA = "wikipedia" + INSTAGRAM = "instagram" + FACEBOOK = "facebook" + TWITTER = "twitter" # I will use nitter though lol + MYSPACE = "myspace" # Yes somehow this ancient site is linked EVERYWHERE + + @classmethod + def get_homepage(cls, attribute) -> str: + homepage_map = { + cls.YOUTUBE: "https://www.youtube.com/", + cls.MUSIFY: "https://musify.club/", + cls.MUSICBRAINZ: "https://musicbrainz.org/", + cls.ENCYCLOPAEDIA_METALLUM: "https://www.metal-archives.com/", + cls.GENIUS: "https://genius.com/", + cls.BANDCAMP: "https://bandcamp.com/", + cls.DEEZER: "https://www.deezer.com/", + cls.INSTAGRAM: "https://www.instagram.com/", + cls.FACEBOOK: "https://www.facebook.com/", + cls.SPOTIFY: "https://open.spotify.com/", + cls.TWITTER: "https://twitter.com/", + cls.MYSPACE: "https://myspace.com/", + cls.WIKIPEDIA: "https://en.wikipedia.org/wiki/Main_Page" + } + return homepage_map[attribute] \ No newline at end of file