fixed parsing

This commit is contained in:
Hellow2 2023-06-13 13:29:24 +02:00
parent 500f82d079
commit 65f7121837
3 changed files with 12 additions and 6 deletions

View File

@ -29,7 +29,8 @@ from ..utils.shared import YOUTUBE_LOGGER, INVIDIOUS_INSTANCE
def get_invidious_url(path: str = "", query: str = "", fragment: str = "") -> str: def get_invidious_url(path: str = "", query: str = "", fragment: str = "") -> str:
return urlunparse((INVIDIOUS_INSTANCE.scheme, INVIDIOUS_INSTANCE.netloc, path, query, fragment)) _ = ""
return urlunparse((INVIDIOUS_INSTANCE.scheme, INVIDIOUS_INSTANCE.netloc, path, query, fragment, _))
class YouTubeUrlType(Enum): class YouTubeUrlType(Enum):
@ -129,7 +130,7 @@ class YouTube(Page):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.connection: Connection = Connection( self.connection: Connection = Connection(
host=urlunparse(INVIDIOUS_INSTANCE), host=get_invidious_url(),
logger=self.LOGGER logger=self.LOGGER
) )
@ -147,12 +148,16 @@ class YouTube(Page):
return _url_type[parsed.url_type] return _url_type[parsed.url_type]
def general_search(self, search_query: str) -> List[DatabaseObject]: def general_search(self, search_query: str) -> List[DatabaseObject]:
return [Artist(name="works")] return [Artist(name="works")]
def label_search(self, label: Label) -> List[Label]: def label_search(self, label: Label) -> List[Label]:
return [] return []
def artist_search(self, artist: Artist) -> List[Artist]: def artist_search(self, artist: Artist) -> List[Artist]:
# https://yt.artemislena.eu/api/v1/search?q=Zombiez+-+Topic&page=1&date=none&type=channel&duration=none&sort=relevance
endpoint = get_invidious_url(path="/api/v1/search", query=f"q={artist.name.replace(' ', '+')}+-+Topic&page=1&date=none&type=channel&duration=none&sort=relevance")
print(endpoint)
return [] return []
def album_search(self, album: Album) -> List[Album]: def album_search(self, album: Album) -> List[Album]:

View File

@ -1,4 +1,4 @@
from urllib.parse import urlparse from urllib.parse import urlparse, ParseResult
import re import re
from .base_classes import Section, FloatAttribute, IntAttribute, BoolAttribute, ListAttribute, StringAttribute from .base_classes import Section, FloatAttribute, IntAttribute, BoolAttribute, ListAttribute, StringAttribute
@ -26,8 +26,9 @@ class UrlStringAttribute(StringAttribute):
rule="has to be a valid url" rule="has to be a valid url"
) )
def single_object_from_element(self, value: str): @property
return urlparse(value) def object_from_value(self) -> ParseResult:
return urlparse(self.value)
class ConnectionSection(Section): class ConnectionSection(Section):

View File

@ -91,7 +91,7 @@ if TOR:
'http': f'socks5h://127.0.0.1:{CONNECTION_SECTION.TOR_PORT.object_from_value}', 'http': f'socks5h://127.0.0.1:{CONNECTION_SECTION.TOR_PORT.object_from_value}',
'https': f'socks5h://127.0.0.1:{CONNECTION_SECTION.TOR_PORT.object_from_value}' 'https': f'socks5h://127.0.0.1:{CONNECTION_SECTION.TOR_PORT.object_from_value}'
} }
INVIDIOUS_INSTANCE: ParseResult = CONNECTION_SECTION.INVIDIOUS_INSTANCE.value INVIDIOUS_INSTANCE: ParseResult = CONNECTION_SECTION.INVIDIOUS_INSTANCE.object_from_value
# size of the chunks that are streamed # size of the chunks that are streamed
CHUNK_SIZE = CONNECTION_SECTION.CHUNK_SIZE.object_from_value CHUNK_SIZE = CONNECTION_SECTION.CHUNK_SIZE.object_from_value