From eef2e74c1bee9e10bc5e943ac5ddd072b90e78ec Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:24:14 +0200 Subject: [PATCH] cleant up messages --- src/music_kraken/cli/main_downloader.py | 9 ++++++--- src/music_kraken/connection/connection.py | 2 +- src/music_kraken/pages/youtube_music/_list_render.py | 2 ++ .../pages/youtube_music/_music_object_render.py | 3 ++- src/music_kraken/pages/youtube_music/youtube_music.py | 11 ----------- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/music_kraken/cli/main_downloader.py b/src/music_kraken/cli/main_downloader.py index 259e217..ba5ee5f 100644 --- a/src/music_kraken/cli/main_downloader.py +++ b/src/music_kraken/cli/main_downloader.py @@ -214,12 +214,15 @@ class Downloader: artist = None if not "a" in key_text else Artist(name=key_text["a"], dynamic=True) if song is not None: - song.album_collection.append(album) - song.main_artist_collection.append(artist) + if album is not None: + song.album_collection.append(album) + if artist is not None: + song.main_artist_collection.append(artist) return Query(raw_query=query, music_object=song) if album is not None: - album.artist_collection.append(artist) + if artist is not None: + album.artist_collection.append(artist) return Query(raw_query=query, music_object=album) if artist is not None: diff --git a/src/music_kraken/connection/connection.py b/src/music_kraken/connection/connection.py index edf27e9..9c94d53 100644 --- a/src/music_kraken/connection/connection.py +++ b/src/music_kraken/connection/connection.py @@ -76,7 +76,7 @@ class Connection: def _hearthbeat_loop(self, interval: float): def hearthbeat_wrapper(): self.session_is_occupied = True - self.LOGGER.info(f"I am living. (sending a hearthbeat)") + self.LOGGER.debug(f"I am living. (sending a hearthbeat)") self.hearthbeat() self.LOGGER.debug(f"finished the hearthbeat") self.session_is_occupied = False diff --git a/src/music_kraken/pages/youtube_music/_list_render.py b/src/music_kraken/pages/youtube_music/_list_render.py index 6021699..b01b20f 100644 --- a/src/music_kraken/pages/youtube_music/_list_render.py +++ b/src/music_kraken/pages/youtube_music/_list_render.py @@ -79,6 +79,8 @@ RENDERER_PARSERS = { "musicResponsiveListItemRenderer": music_responsive_list_item_renderer, "musicResponsiveListItemFlexColumnRenderer": music_responsive_list_item_flex_column_renderer, "musicShelfRenderer": music_card_shelf_renderer, + + "itemSectionRenderer": lambda _: [], } def parse_renderer(renderer: dict) -> List[DatabaseObject]: 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 ffca416..9fca473 100644 --- a/src/music_kraken/pages/youtube_music/_music_object_render.py +++ b/src/music_kraken/pages/youtube_music/_music_object_render.py @@ -25,6 +25,7 @@ class PageType(Enum): PLAYLIST = "MUSIC_PAGE_TYPE_PLAYLIST" SONG = "MUSIC_VIDEO_TYPE_ATV" VIDEO = "MUSIC_VIDEO_TYPE_UGC" + OFFICIAL_MUSIC_VIDEO = "MUSIC_VIDEO_TYPE_OMV" def parse_run_element(run_element: dict) -> Optional[DatabaseObject]: @@ -49,7 +50,7 @@ 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 element_type == PageType.SONG or (element_type == PageType.VIDEO and not YOUTUBE_MUSIC_CLEAN_DATA): + if element_type == PageType.SONG or (element_type == PageType.VIDEO and not YOUTUBE_MUSIC_CLEAN_DATA) or (element_type == PageType.OFFICIAL_MUSIC_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]) diff --git a/src/music_kraken/pages/youtube_music/youtube_music.py b/src/music_kraken/pages/youtube_music/youtube_music.py index c9de779..9ea17db 100644 --- a/src/music_kraken/pages/youtube_music/youtube_music.py +++ b/src/music_kraken/pages/youtube_music/youtube_music.py @@ -223,8 +223,6 @@ class YoutubeMusic(Page): def general_search(self, search_query: str) -> List[DatabaseObject]: search_query = search_query.strip() - self.LOGGER.info(f"general search for {search_query}") - print(self.credentials) urlescaped_query: str = quote(search_query.strip().replace(" ", "+")) @@ -259,7 +257,6 @@ class YoutubeMusic(Page): ) self.LOGGER.debug(str(r)) - # dump_to_file(f"{search_query}.json", r.content, is_json=True) renderer_list = r.json().get("contents", {}).get("tabbedSearchResultsRenderer", {}).get("tabs", [{}])[0].get("tabRenderer").get("content", {}).get("sectionListRenderer", {}).get("contents", []) @@ -270,7 +267,6 @@ class YoutubeMusic(Page): results = [] """ - TODO 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. """ @@ -278,13 +274,6 @@ class YoutubeMusic(Page): 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]: