From c682342303874816bb13a5e4f7476cb4ff521bf2 Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Fri, 28 Jul 2023 00:37:49 +0200 Subject: [PATCH] added some more types --- .../pages/youtube_music/_music_object_render.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/music_kraken/pages/youtube_music/_music_object_render.py b/src/music_kraken/pages/youtube_music/_music_object_render.py index b40b0d6..6e6aaed 100644 --- a/src/music_kraken/pages/youtube_music/_music_object_render.py +++ b/src/music_kraken/pages/youtube_music/_music_object_render.py @@ -1,6 +1,7 @@ from typing import List, Optional from enum import Enum +from ...utils.shared import YOUTUBE_MUSIC_LOGGER as LOGGER from ...objects import Source, DatabaseObject from ..abstract import Page from ...objects import ( @@ -27,17 +28,25 @@ class PageType(Enum): def parse_run_element(run_element: dict) -> Optional[DatabaseObject]: 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_text = run_element.get("text") 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 - 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}") 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]: