From 855ca4b5315af5e6daed2e6b2819240d81d541c7 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Tue, 28 Mar 2023 14:04:15 +0200 Subject: [PATCH] started implementing the multiple page search --- src/donwload.py | 11 ++++ src/music_kraken/pages/__init__.py | 10 ++-- .../pages/download_center/__init__.py | 3 ++ .../pages/download_center/page_attributes.py | 17 ++++--- .../pages/download_center/search.py | 51 +++++++++++++++++-- src/music_kraken/pages/musify.py | 7 +-- 6 files changed, 77 insertions(+), 22 deletions(-) diff --git a/src/donwload.py b/src/donwload.py index e69de29..d2d6792 100644 --- a/src/donwload.py +++ b/src/donwload.py @@ -0,0 +1,11 @@ +from music_kraken import pages + + +def search_pages(): + search = pages.Search("#a Happy Days") + print("metadata", search.pages) + print("audio", search.audio_pages) + + +if __name__ == "__main__": + search_pages() diff --git a/src/music_kraken/pages/__init__.py b/src/music_kraken/pages/__init__.py index cb46e45..3794526 100644 --- a/src/music_kraken/pages/__init__.py +++ b/src/music_kraken/pages/__init__.py @@ -4,11 +4,7 @@ from .musify import Musify EncyclopaediaMetallum = EncyclopaediaMetallum Musify = Musify -MetadataPages = { - EncyclopaediaMetallum, - Musify -} +from . import download_center + +Search = download_center.Search -AudioPages = { - Musify -} diff --git a/src/music_kraken/pages/download_center/__init__.py b/src/music_kraken/pages/download_center/__init__.py index e69de29..a3a93fa 100644 --- a/src/music_kraken/pages/download_center/__init__.py +++ b/src/music_kraken/pages/download_center/__init__.py @@ -0,0 +1,3 @@ +from . import search + +Search = search.Search diff --git a/src/music_kraken/pages/download_center/page_attributes.py b/src/music_kraken/pages/download_center/page_attributes.py index db82dac..d6fa5b6 100644 --- a/src/music_kraken/pages/download_center/page_attributes.py +++ b/src/music_kraken/pages/download_center/page_attributes.py @@ -1,14 +1,19 @@ -from typing import Set +from typing import Tuple from ..abstract import Page from ..encyclopaedia_metallum import EncyclopaediaMetallum from ..musify import Musify -ALL_PAGES: Set[Page] = { +ALL_PAGES: Tuple[Page] = ( EncyclopaediaMetallum, Musify -} +) + +AUDIO_PAGES: Tuple[Page] = ( + Musify, +) + +SHADY_PAGES: Tuple[Page] = ( + Musify, +) -AUDIO_PAGES: Set[Page] = { - Musify -} diff --git a/src/music_kraken/pages/download_center/search.py b/src/music_kraken/pages/download_center/search.py index 2d76068..e244283 100644 --- a/src/music_kraken/pages/download_center/search.py +++ b/src/music_kraken/pages/download_center/search.py @@ -1,9 +1,54 @@ +from collections import defaultdict +from typing import Tuple, List, Set +from . import page_attributes +from ..abstract import Page + +from ...objects import Options class Search: def __init__( + self, query: str, - exclude_pages: set - ) -> None: - pass \ No newline at end of file + pages: Tuple[Page] = page_attributes.ALL_PAGES, + exclude_pages: Set[Page] = set(), + exclude_shady: bool = False + ) -> None: + _page_list: List[Page] = [] + _audio_page_list: List[Page] = [] + + for page in pages: + if exclude_shady and page in page_attributes.SHADY_PAGES: + continue + if page in exclude_pages: + continue + + _page_list.append(page) + + if page in page_attributes.AUDIO_PAGES: + _audio_page_list.append(page) + + self.pages: Tuple[Page] = tuple(_page_list) + self.audio_pages: Tuple[Page] = tuple(_audio_page_list) + + self.current_option_dict = defaultdict(lambda: Options()) + + self.search(query) + + def search(self, query: str): + """ + # The Query + + You can define a new parameter with "#", + the letter behind it defines the *type* of parameter, + followed by a space "#a Psychonaut 4 #r Tired, Numb and #t Drop by Drop" + if no # is in the query it gets treated as "unspecified query" + """ + + for page in self.pages: + self.current_option_dict[page] = page.search_by_query(query=query) + + print("-"*10, page.__name__, "-"*10) + print(self.current_option_dict[page]) + \ No newline at end of file diff --git a/src/music_kraken/pages/musify.py b/src/music_kraken/pages/musify.py index 066ebac..1fffec9 100644 --- a/src/music_kraken/pages/musify.py +++ b/src/music_kraken/pages/musify.py @@ -100,7 +100,7 @@ class Musify(Page): try: type_enum = MusifyTypes(path[1]) except ValueError as e: - print(f"{path[1]} is not yet implemented, add it to MusifyTypes") + LOGGER.warning(f"{path[1]} is not yet implemented, add it to MusifyTypes") raise e return MusifyUrl( @@ -267,11 +267,8 @@ class Musify(Page): @classmethod def parse_contact_container(cls, contact_container_soup: BeautifulSoup) -> List[Union[Artist, Album]]: - # print(contact_container_soup.prettify) contacts = [] - # print(contact_container_soup) - contact: BeautifulSoup for contact in contact_container_soup.find_all("div", {"class": "contacts__item"}): @@ -281,7 +278,6 @@ class Musify(Page): url = anchor_soup.get("href") if url is not None: - # print(url) if "artist" in url: contacts.append(cls.parse_artist_contact(contact)) elif "release" in url: @@ -301,7 +297,6 @@ class Musify(Page): anchor_list = playlist_details.find_all("a") if len(anchor_list) >= 2: - print(anchor_list) # artists artist_anchor: BeautifulSoup for artist_anchor in anchor_list[:-1]: