started implementing the multiple page search
This commit is contained in:
parent
7ceb9bb5fe
commit
855ca4b531
@ -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()
|
@ -4,11 +4,7 @@ from .musify import Musify
|
|||||||
EncyclopaediaMetallum = EncyclopaediaMetallum
|
EncyclopaediaMetallum = EncyclopaediaMetallum
|
||||||
Musify = Musify
|
Musify = Musify
|
||||||
|
|
||||||
MetadataPages = {
|
from . import download_center
|
||||||
EncyclopaediaMetallum,
|
|
||||||
Musify
|
Search = download_center.Search
|
||||||
}
|
|
||||||
|
|
||||||
AudioPages = {
|
|
||||||
Musify
|
|
||||||
}
|
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
from . import search
|
||||||
|
|
||||||
|
Search = search.Search
|
@ -1,14 +1,19 @@
|
|||||||
from typing import Set
|
from typing import Tuple
|
||||||
|
|
||||||
from ..abstract import Page
|
from ..abstract import Page
|
||||||
from ..encyclopaedia_metallum import EncyclopaediaMetallum
|
from ..encyclopaedia_metallum import EncyclopaediaMetallum
|
||||||
from ..musify import Musify
|
from ..musify import Musify
|
||||||
|
|
||||||
ALL_PAGES: Set[Page] = {
|
ALL_PAGES: Tuple[Page] = (
|
||||||
EncyclopaediaMetallum,
|
EncyclopaediaMetallum,
|
||||||
Musify
|
Musify
|
||||||
}
|
)
|
||||||
|
|
||||||
|
AUDIO_PAGES: Tuple[Page] = (
|
||||||
|
Musify,
|
||||||
|
)
|
||||||
|
|
||||||
|
SHADY_PAGES: Tuple[Page] = (
|
||||||
|
Musify,
|
||||||
|
)
|
||||||
|
|
||||||
AUDIO_PAGES: Set[Page] = {
|
|
||||||
Musify
|
|
||||||
}
|
|
||||||
|
@ -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:
|
class Search:
|
||||||
def __init__(
|
def __init__(
|
||||||
|
self,
|
||||||
query: str,
|
query: str,
|
||||||
exclude_pages: set
|
pages: Tuple[Page] = page_attributes.ALL_PAGES,
|
||||||
) -> None:
|
exclude_pages: Set[Page] = set(),
|
||||||
pass
|
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])
|
||||||
|
|
@ -100,7 +100,7 @@ class Musify(Page):
|
|||||||
try:
|
try:
|
||||||
type_enum = MusifyTypes(path[1])
|
type_enum = MusifyTypes(path[1])
|
||||||
except ValueError as e:
|
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
|
raise e
|
||||||
|
|
||||||
return MusifyUrl(
|
return MusifyUrl(
|
||||||
@ -267,11 +267,8 @@ class Musify(Page):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_contact_container(cls, contact_container_soup: BeautifulSoup) -> List[Union[Artist, Album]]:
|
def parse_contact_container(cls, contact_container_soup: BeautifulSoup) -> List[Union[Artist, Album]]:
|
||||||
# print(contact_container_soup.prettify)
|
|
||||||
contacts = []
|
contacts = []
|
||||||
|
|
||||||
# print(contact_container_soup)
|
|
||||||
|
|
||||||
contact: BeautifulSoup
|
contact: BeautifulSoup
|
||||||
for contact in contact_container_soup.find_all("div", {"class": "contacts__item"}):
|
for contact in contact_container_soup.find_all("div", {"class": "contacts__item"}):
|
||||||
|
|
||||||
@ -281,7 +278,6 @@ class Musify(Page):
|
|||||||
url = anchor_soup.get("href")
|
url = anchor_soup.get("href")
|
||||||
|
|
||||||
if url is not None:
|
if url is not None:
|
||||||
# print(url)
|
|
||||||
if "artist" in url:
|
if "artist" in url:
|
||||||
contacts.append(cls.parse_artist_contact(contact))
|
contacts.append(cls.parse_artist_contact(contact))
|
||||||
elif "release" in url:
|
elif "release" in url:
|
||||||
@ -301,7 +297,6 @@ class Musify(Page):
|
|||||||
anchor_list = playlist_details.find_all("a")
|
anchor_list = playlist_details.find_all("a")
|
||||||
|
|
||||||
if len(anchor_list) >= 2:
|
if len(anchor_list) >= 2:
|
||||||
print(anchor_list)
|
|
||||||
# artists
|
# artists
|
||||||
artist_anchor: BeautifulSoup
|
artist_anchor: BeautifulSoup
|
||||||
for artist_anchor in anchor_list[:-1]:
|
for artist_anchor in anchor_list[:-1]:
|
||||||
|
Loading…
Reference in New Issue
Block a user