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,6 +37,7 @@ 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)
|
||||||
@ -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,10 +274,16 @@ 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
|
||||||
|
|
||||||
|
@ -113,6 +113,12 @@ class ConnectionSection(Section):
|
|||||||
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",
|
||||||
description="This is used to detect, if an url is from youtube, or any alternativ frontend.\n"
|
description="This is used to detect, if an url is from youtube, or any alternativ frontend.\n"
|
||||||
@ -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