added some more types
This commit is contained in:
parent
c4f10e7906
commit
c682342303
@ -1,6 +1,7 @@
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from ...utils.shared import YOUTUBE_MUSIC_LOGGER as LOGGER
|
||||||
from ...objects import Source, DatabaseObject
|
from ...objects import Source, DatabaseObject
|
||||||
from ..abstract import Page
|
from ..abstract import Page
|
||||||
from ...objects import (
|
from ...objects import (
|
||||||
@ -27,17 +28,25 @@ class PageType(Enum):
|
|||||||
def parse_run_element(run_element: dict) -> Optional[DatabaseObject]:
|
def parse_run_element(run_element: dict) -> Optional[DatabaseObject]:
|
||||||
navigation_endpoint = run_element.get("navigationEndpoint", {}).get("browseEndpoint", {})
|
navigation_endpoint = run_element.get("navigationEndpoint", {}).get("browseEndpoint", {})
|
||||||
|
|
||||||
element_type = PageType(navigation_endpoint.get("browseEndpointContextSupportedConfigs", {}).get("browseEndpointContextMusicConfig", {}).get("pageType", ""))
|
page_type_string = navigation_endpoint.get("browseEndpointContextSupportedConfigs", {}).get("browseEndpointContextMusicConfig", {}).get("pageType", "")
|
||||||
|
element_type = PageType(page_type_string)
|
||||||
|
|
||||||
element_id = navigation_endpoint.get("browseId")
|
element_id = navigation_endpoint.get("browseId")
|
||||||
element_text = run_element.get("text")
|
element_text = run_element.get("text")
|
||||||
|
|
||||||
if element_id is None or element_text is None:
|
if element_id is None or element_text is None:
|
||||||
|
LOGGER.warning("Couldn't find either the id or text of a Youtube music element.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if element_type == PageType.ARTIST:
|
if element_type == PageType.ARTIST or element_type == PageType.CHANNEL:
|
||||||
source = Source(SOURCE_PAGE, f"https://music.youtube.com/channel/{element_id}")
|
source = Source(SOURCE_PAGE, f"https://music.youtube.com/channel/{element_id}")
|
||||||
return Artist(name=element_text, source_list=[source])
|
return Artist(name=element_text, source_list=[source])
|
||||||
|
|
||||||
|
if element_type == PageType.ALBUM or element_type == PageType.PLAYLIST:
|
||||||
|
source = Source(SOURCE_PAGE, f"https://music.youtube.com/playlist?list={element_id}")
|
||||||
|
return Album(title=element_text, source_list=[source])
|
||||||
|
|
||||||
|
LOGGER.warning(f"Type {page_type_string} wasn't implemented.")
|
||||||
|
|
||||||
|
|
||||||
def parse_run_list(run_list: List[dict]) -> List[DatabaseObject]:
|
def parse_run_list(run_list: List[dict]) -> List[DatabaseObject]:
|
||||||
|
Loading…
Reference in New Issue
Block a user