finished implementing general search
This commit is contained in:
parent
a5b76648f5
commit
406dc3d1e2
@ -1,7 +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 ...utils.shared import YOUTUBE_MUSIC_LOGGER as LOGGER, YOUTUBE_MUSIC_CLEAN_DATA
|
||||||
from ...objects import Source, DatabaseObject
|
from ...objects import Source, DatabaseObject
|
||||||
from ..abstract import Page
|
from ..abstract import Page
|
||||||
from ...objects import (
|
from ...objects import (
|
||||||
@ -23,7 +23,8 @@ class PageType(Enum):
|
|||||||
ALBUM = "MUSIC_PAGE_TYPE_ALBUM"
|
ALBUM = "MUSIC_PAGE_TYPE_ALBUM"
|
||||||
CHANNEL = "MUSIC_PAGE_TYPE_USER_CHANNEL"
|
CHANNEL = "MUSIC_PAGE_TYPE_USER_CHANNEL"
|
||||||
PLAYLIST = "MUSIC_PAGE_TYPE_PLAYLIST"
|
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]:
|
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", {})
|
navigation_endpoint = _temp_nav.get("watchEndpoint" if is_video else "browseEndpoint", {})
|
||||||
|
|
||||||
element_type = PageType.SONG
|
element_type = PageType.SONG
|
||||||
|
page_type_string = navigation_endpoint.get("watchEndpointMusicSupportedConfigs", {}).get("watchEndpointMusicConfig", {}).get("musicVideoType", "")
|
||||||
if not is_video:
|
if not is_video:
|
||||||
page_type_string = 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_type = PageType(page_type_string)
|
||||||
|
|
||||||
element_id = navigation_endpoint.get("videoId" if is_video else "browseId")
|
element_id = navigation_endpoint.get("videoId" if is_video else "browseId")
|
||||||
element_text = run_element.get("text")
|
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.")
|
LOGGER.warning("Couldn't find either the id or text of a Youtube music element.")
|
||||||
return
|
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}")
|
source = Source(SOURCE_PAGE, f"https://music.youtube.com/watch?v={element_id}")
|
||||||
return Song(title=element_text, source_list=[source])
|
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}")
|
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:
|
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}")
|
source = Source(SOURCE_PAGE, f"https://music.youtube.com/playlist?list={element_id}")
|
||||||
return Album(title=element_text, source_list=[source])
|
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]:
|
def parse_run_list(run_list: List[dict]) -> List[DatabaseObject]:
|
||||||
|
@ -274,11 +274,17 @@ class YoutubeMusic(Page):
|
|||||||
cant use fixed indices, because if something has no entries, the list dissappears
|
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.
|
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[1]))
|
||||||
results.extend(parse_renderer(renderer_list[2]))
|
results.extend(parse_renderer(renderer_list[2]))
|
||||||
results.extend(parse_renderer(renderer_list[4]))
|
results.extend(parse_renderer(renderer_list[4]))
|
||||||
results.extend(parse_renderer(renderer_list[6]))
|
results.extend(parse_renderer(renderer_list[6]))
|
||||||
|
"""
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def label_search(self, label: Label) -> List[Label]:
|
def label_search(self, label: Label) -> List[Label]:
|
||||||
|
@ -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)",
|
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"
|
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(
|
self.ALL_YOUTUBE_URLS = UrlListAttribute(
|
||||||
name="youtube_url",
|
name="youtube_url",
|
||||||
@ -140,6 +146,7 @@ class ConnectionSection(Section):
|
|||||||
self.PIPED_INSTANCE,
|
self.PIPED_INSTANCE,
|
||||||
self.SLEEP_AFTER_YOUTUBE_403,
|
self.SLEEP_AFTER_YOUTUBE_403,
|
||||||
self.YOUTUBE_MUSIC_API_KEY,
|
self.YOUTUBE_MUSIC_API_KEY,
|
||||||
|
self.YOUTUBE_MUSIC_CLEAN_DATA,
|
||||||
self.ALL_YOUTUBE_URLS,
|
self.ALL_YOUTUBE_URLS,
|
||||||
self.SPONSOR_BLOCK
|
self.SPONSOR_BLOCK
|
||||||
]
|
]
|
||||||
|
@ -130,3 +130,5 @@ SLEEP_AFTER_YOUTUBE_403: float = CONNECTION_SECTION.SLEEP_AFTER_YOUTUBE_403.obje
|
|||||||
DEBUG = True
|
DEBUG = True
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print("DEBUG ACTIVE")
|
print("DEBUG ACTIVE")
|
||||||
|
|
||||||
|
YOUTUBE_MUSIC_CLEAN_DATA: bool = CONNECTION_SECTION.YOUTUBE_MUSIC_CLEAN_DATA.object_from_value
|
||||||
|
Loading…
Reference in New Issue
Block a user