diff --git a/src/music_kraken/utils/config/connection.py b/src/music_kraken/utils/config/connection.py index 086d927..2bd5824 100644 --- a/src/music_kraken/utils/config/connection.py +++ b/src/music_kraken/utils/config/connection.py @@ -1,4 +1,9 @@ +from urllib.parse import urlparse +import re + from .base_classes import Section, FloatAttribute, IntAttribute, BoolAttribute, ListAttribute +from ..regex import URL_PATTERN +from ..exception.config import SettingValueError class ProxAttribute(ListAttribute): @@ -9,6 +14,21 @@ class ProxAttribute(ListAttribute): 'ftp': value } +class UrlListAttribute(ListAttribute): + def validate(self, value: str): + v = value.strip() + url = re.match(URL_PATTERN, v) + if v != url: + 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): @@ -42,6 +62,25 @@ class ConnectionSection(Section): "all the error messages are shown.", value="0.3" ) + + # INVIDIOUS INSTANCES LIST + self.INVIDIOUS_INSTANCE_LIST = UrlListAttribute( + name="invidious_instances", + description="This is a List, where you can define the invidious instances,\n" + "the youtube downloader should use.\n" + "Here is a list of active ones: https://docs.invidious.io/instances/\n" + "Instances that use cloudflare or have source code changes could cause issues.\n" + "Hidden instances (.onion) will only work, when setting 'tor=true'.", + value=[ + "https://yt.artemislena.eu/", + "https://watch.thekitty.zone/", + "https://y.com.sb/" + ] + ) + # INVIDIOUS PROXY + self.INVIDIOUS_PROXY_VIDEOS = BoolAttribute( + name="invidious_proxy_video", + ) self.attribute_list = [ self.USE_TOR, diff --git a/src/music_kraken/utils/regex.py b/src/music_kraken/utils/regex.py new file mode 100644 index 0000000..1290de5 --- /dev/null +++ b/src/music_kraken/utils/regex.py @@ -0,0 +1,2 @@ +URL_PATTERN = 'https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+' +