added a collection of youtube and its frontend mirrors

This commit is contained in:
Hellow2 2023-06-19 14:54:09 +02:00
parent 0fb8a25094
commit 6a44cb827b
4 changed files with 38 additions and 3 deletions

View File

@ -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

View File

@ -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):

View File

@ -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
]

View File

@ -102,3 +102,5 @@ THREADED = False
ENABLE_RESULT_HISTORY: bool = MISC_SECTION.ENABLE_RESULT_HISTORY.object_from_value
HISTORY_LENGTH: int = MISC_SECTION.HISTORY_LENGTH.object_from_value
ALL_YOUTUBE_URLS: List[ParseResult] = CONNECTION_SECTION.ALL_YOUTUBE_URLS.object_from_value