From 406dc3d1e2113c4bd3a9f854113155d33350b082 Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:07:16 +0200 Subject: [PATCH] finished implementing general search --- .../pages/youtube_music/_music_object_render.py | 16 +++++++++------- .../pages/youtube_music/youtube_music.py | 8 +++++++- src/music_kraken/utils/config/connection.py | 7 +++++++ src/music_kraken/utils/shared.py | 2 ++ 4 files changed, 25 insertions(+), 8 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 690f3f1..ffca416 100644 --- a/src/music_kraken/pages/youtube_music/_music_object_render.py +++ b/src/music_kraken/pages/youtube_music/_music_object_render.py @@ -1,7 +1,7 @@ from typing import List, Optional from enum import Enum -from ...utils.shared import YOUTUBE_MUSIC_LOGGER as LOGGER +from ...utils.shared import YOUTUBE_MUSIC_LOGGER as LOGGER, YOUTUBE_MUSIC_CLEAN_DATA from ...objects import Source, DatabaseObject from ..abstract import Page from ...objects import ( @@ -23,7 +23,8 @@ class PageType(Enum): ALBUM = "MUSIC_PAGE_TYPE_ALBUM" CHANNEL = "MUSIC_PAGE_TYPE_USER_CHANNEL" PLAYLIST = "MUSIC_PAGE_TYPE_PLAYLIST" - SONG = "song" + SONG = "MUSIC_VIDEO_TYPE_ATV" + VIDEO = "MUSIC_VIDEO_TYPE_UGC" def parse_run_element(run_element: dict) -> Optional[DatabaseObject]: @@ -36,9 +37,10 @@ def parse_run_element(run_element: dict) -> Optional[DatabaseObject]: navigation_endpoint = _temp_nav.get("watchEndpoint" if is_video else "browseEndpoint", {}) element_type = PageType.SONG + page_type_string = navigation_endpoint.get("watchEndpointMusicSupportedConfigs", {}).get("watchEndpointMusicConfig", {}).get("musicVideoType", "") if not is_video: page_type_string = navigation_endpoint.get("browseEndpointContextSupportedConfigs", {}).get("browseEndpointContextMusicConfig", {}).get("pageType", "") - element_type = PageType(page_type_string) + element_type = PageType(page_type_string) element_id = navigation_endpoint.get("videoId" if is_video else "browseId") element_text = run_element.get("text") @@ -47,19 +49,19 @@ def parse_run_element(run_element: dict) -> Optional[DatabaseObject]: LOGGER.warning("Couldn't find either the id or text of a Youtube music element.") return - if is_video: + if element_type == PageType.SONG or (element_type == PageType.VIDEO and not YOUTUBE_MUSIC_CLEAN_DATA): source = Source(SOURCE_PAGE, f"https://music.youtube.com/watch?v={element_id}") return Song(title=element_text, source_list=[source]) - if element_type == PageType.ARTIST or element_type == PageType.CHANNEL: + if element_type == PageType.ARTIST or (element_type == PageType.CHANNEL and not YOUTUBE_MUSIC_CLEAN_DATA): 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: + if element_type == PageType.ALBUM or (element_type == PageType.PLAYLIST and not YOUTUBE_MUSIC_CLEAN_DATA): 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.") + LOGGER.debug(f"Type {page_type_string} wasn't implemented.") def parse_run_list(run_list: List[dict]) -> List[DatabaseObject]: diff --git a/src/music_kraken/pages/youtube_music/youtube_music.py b/src/music_kraken/pages/youtube_music/youtube_music.py index 902306f..c9de779 100644 --- a/src/music_kraken/pages/youtube_music/youtube_music.py +++ b/src/music_kraken/pages/youtube_music/youtube_music.py @@ -274,11 +274,17 @@ class YoutubeMusic(Page): cant use fixed indices, because if something has no entries, the list dissappears instead I have to try parse everything, and just reject community playlists and profiles. """ + + for renderer in renderer_list: + results.extend(parse_renderer(renderer)) + + """ results.extend(parse_renderer(renderer_list[1])) results.extend(parse_renderer(renderer_list[2])) results.extend(parse_renderer(renderer_list[4])) results.extend(parse_renderer(renderer_list[6])) - + """ + return results def label_search(self, label: Label) -> List[Label]: diff --git a/src/music_kraken/utils/config/connection.py b/src/music_kraken/utils/config/connection.py index 42fb7aa..2dfe629 100644 --- a/src/music_kraken/utils/config/connection.py +++ b/src/music_kraken/utils/config/connection.py @@ -112,6 +112,12 @@ class ConnectionSection(Section): description="This is the API key used by YouTube-Music internally.\nDw. if it is empty, Rachel will fetch it automatically for you <333\n(she will also update outdated api keys/those that don't work)", value="AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30" ) + + self.YOUTUBE_MUSIC_CLEAN_DATA = BoolAttribute( + name="youtube_music_clean_data", + description="If set to true, it exclusively fetches artists/albums/songs, not things like user channels etc.", + value="true" + ) self.ALL_YOUTUBE_URLS = UrlListAttribute( name="youtube_url", @@ -140,6 +146,7 @@ class ConnectionSection(Section): self.PIPED_INSTANCE, self.SLEEP_AFTER_YOUTUBE_403, self.YOUTUBE_MUSIC_API_KEY, + self.YOUTUBE_MUSIC_CLEAN_DATA, self.ALL_YOUTUBE_URLS, self.SPONSOR_BLOCK ] diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index af49658..762ccb4 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -130,3 +130,5 @@ SLEEP_AFTER_YOUTUBE_403: float = CONNECTION_SECTION.SLEEP_AFTER_YOUTUBE_403.obje DEBUG = True if DEBUG: print("DEBUG ACTIVE") + +YOUTUBE_MUSIC_CLEAN_DATA: bool = CONNECTION_SECTION.YOUTUBE_MUSIC_CLEAN_DATA.object_from_value