From 6a44cb827b9130138bb3721b5fb20e6b16a63aa2 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Mon, 19 Jun 2023 14:54:09 +0200 Subject: [PATCH] added a collection of youtube and its frontend mirrors --- src/music_kraken/cli/options/frontend.py | 5 ++-- src/music_kraken/utils/config/base_classes.py | 3 ++ src/music_kraken/utils/config/connection.py | 29 +++++++++++++++++++ src/music_kraken/utils/shared.py | 4 ++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/music_kraken/cli/options/frontend.py b/src/music_kraken/cli/options/frontend.py index 34395f4..809ebe8 100644 --- a/src/music_kraken/cli/options/frontend.py +++ b/src/music_kraken/cli/options/frontend.py @@ -4,7 +4,7 @@ from dataclasses import dataclass from collections import defaultdict from ...objects import Country -from ...utils import config, write +from ...utils import config, write, shared from ...connection import Connection @@ -34,6 +34,8 @@ class FrontendInstance: def add_instance(self, instance: Instance): self.all_instances.append(instance) + config.set_name_to_value("youtube_url", instance.uri) + for region in instance.regions: self.region_instances[region].append(instance) @@ -118,7 +120,6 @@ class Invidious(FrontendInstance): self.add_instance(instance) def fetch(self, silent: bool): - print("jhdflashfö") r = self.connection.get(self.endpoint) if r is None: return diff --git a/src/music_kraken/utils/config/base_classes.py b/src/music_kraken/utils/config/base_classes.py index f14ebb8..b5fcbce 100644 --- a/src/music_kraken/utils/config/base_classes.py +++ b/src/music_kraken/utils/config/base_classes.py @@ -144,6 +144,9 @@ class ListAttribute(Attribute): self.value = [] self.has_default_values = False + if value in self.value: + return + self.value.append(value) def __str__(self): diff --git a/src/music_kraken/utils/config/connection.py b/src/music_kraken/utils/config/connection.py index 8996f38..43fc782 100644 --- a/src/music_kraken/utils/config/connection.py +++ b/src/music_kraken/utils/config/connection.py @@ -31,6 +31,22 @@ class UrlStringAttribute(StringAttribute): return urlparse(self.value) +class UrlListAttribute(ListAttribute): + def validate(self, value: str): + v = value.strip() + url = re.match(URL_PATTERN, v) + if url is None: + raise SettingValueError( + setting_name=self.name, + setting_value=v, + rule="has to be a valid url" + ) + + def single_object_from_element(self, value: str): + return urlparse(value) + + + class ConnectionSection(Section): def __init__(self): self.PROXIES = ProxAttribute( @@ -85,6 +101,18 @@ class ConnectionSection(Section): value="https://pipedapi.kavin.rocks" ) + self.ALL_YOUTUBE_URLS = UrlListAttribute( + name="youtube_url", + description="This is used to detect, if an url is from youtube, or any alternativ frontend.\n" + "If any instance seems to be missing, run music kraken with the -f flag.", + value=[ + "https://www.youtube.com/", + "https://www.youtu.be/", + "https://redirect.invidious.io/", + "https://piped.kavin.rocks/" + ] + ) + self.SPONSOR_BLOCK = BoolAttribute( name="use_sponsor_block", value="true", @@ -98,6 +126,7 @@ class ConnectionSection(Section): self.SHOW_DOWNLOAD_ERRORS_THRESHOLD, self.INVIDIOUS_INSTANCE, self.PIPED_INSTANCE, + self.ALL_YOUTUBE_URLS, self.SPONSOR_BLOCK ] diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index addcca7..22a361e 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -101,4 +101,6 @@ ALBUM_TYPE_BLACKLIST: Set[AlbumType] = set(AUDIO_SECTION.ALBUM_TYPE_BLACKLIST.ob THREADED = False ENABLE_RESULT_HISTORY: bool = MISC_SECTION.ENABLE_RESULT_HISTORY.object_from_value -HISTORY_LENGTH: int = MISC_SECTION.HISTORY_LENGTH.object_from_value \ No newline at end of file +HISTORY_LENGTH: int = MISC_SECTION.HISTORY_LENGTH.object_from_value + +ALL_YOUTUBE_URLS: List[ParseResult] = CONNECTION_SECTION.ALL_YOUTUBE_URLS.object_from_value \ No newline at end of file