started implementing the multiple page search

This commit is contained in:
Hellow2 2023-03-28 14:04:15 +02:00
parent 7ceb9bb5fe
commit 855ca4b531
6 changed files with 77 additions and 22 deletions

View File

@ -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()

View File

@ -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
}

View File

@ -0,0 +1,3 @@
from . import search
Search = search.Search

View File

@ -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
}

View File

@ -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
pages: Tuple[Page] = page_attributes.ALL_PAGES,
exclude_pages: Set[Page] = set(),
exclude_shady: bool = False
) -> None:
pass
_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])

View File

@ -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]: