added connection settings
This commit is contained in:
parent
4516e40268
commit
4f12dcbc78
@ -5,7 +5,7 @@ from bs4 import BeautifulSoup
|
|||||||
import pycountry
|
import pycountry
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from ..utils.shared import ENCYCLOPAEDIA_METALLUM_LOGGER
|
from ..utils.shared import ENCYCLOPAEDIA_METALLUM_LOGGER, proxies
|
||||||
from ..utils import string_processing
|
from ..utils import string_processing
|
||||||
from .abstract import Page
|
from .abstract import Page
|
||||||
from ..objects import (
|
from ..objects import (
|
||||||
@ -25,6 +25,7 @@ from ..objects import (
|
|||||||
|
|
||||||
class EncyclopaediaMetallum(Page):
|
class EncyclopaediaMetallum(Page):
|
||||||
API_SESSION: requests.Session = requests.Session()
|
API_SESSION: requests.Session = requests.Session()
|
||||||
|
API_SESSION.proxies = proxies
|
||||||
API_SESSION.headers = {
|
API_SESSION.headers = {
|
||||||
"Host": "www.metal-archives.com",
|
"Host": "www.metal-archives.com",
|
||||||
"Connection": "keep-alive"
|
"Connection": "keep-alive"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from .logging import LOGGING_SECTION
|
from .logging import LOGGING_SECTION
|
||||||
from .audio import AUDIO_SECTION
|
from .audio import AUDIO_SECTION
|
||||||
|
from .connection import CONNECTION_SECTION
|
||||||
|
|
||||||
from .config import read, write, config
|
from .config import read, write, config
|
||||||
|
|
||||||
|
@ -87,9 +87,25 @@ class IntAttribute(SingleAttribute):
|
|||||||
return int(self.value)
|
return int(self.value)
|
||||||
|
|
||||||
|
|
||||||
|
class BoolAttribute(SingleAttribute):
|
||||||
|
def validate(self, value: str):
|
||||||
|
if value.lower().strip() not in {"true", "false"}:
|
||||||
|
raise SettingValueError(
|
||||||
|
setting_name=self.name,
|
||||||
|
setting_value=value,
|
||||||
|
rule="has to be a bool (true/false)"
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def object_from_value(self) -> bool:
|
||||||
|
return self.value.lower().strip() in {"yes", "y", "t", "true"}
|
||||||
|
|
||||||
|
|
||||||
class FloatAttribute(SingleAttribute):
|
class FloatAttribute(SingleAttribute):
|
||||||
def validate(self, value: str):
|
def validate(self, value: str):
|
||||||
if not value.isnumeric():
|
try:
|
||||||
|
float(value)
|
||||||
|
except ValueError:
|
||||||
raise SettingValueError(
|
raise SettingValueError(
|
||||||
setting_name=self.name,
|
setting_name=self.name,
|
||||||
setting_value=value,
|
setting_value=value,
|
||||||
|
@ -7,6 +7,7 @@ from ..path_manager import LOCATIONS
|
|||||||
from .base_classes import Description, Attribute, Section, EmptyLine, COMMENT_PREFIX
|
from .base_classes import Description, Attribute, Section, EmptyLine, COMMENT_PREFIX
|
||||||
from .audio import AUDIO_SECTION
|
from .audio import AUDIO_SECTION
|
||||||
from .logging import LOGGING_SECTION
|
from .logging import LOGGING_SECTION
|
||||||
|
from .connection import CONNECTION_SECTION
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -19,6 +20,8 @@ class Config:
|
|||||||
"If you, for some reason wanna fill your drive real quickly, I mean enjoy HIFI music,\n"
|
"If you, for some reason wanna fill your drive real quickly, I mean enjoy HIFI music,\n"
|
||||||
"feel free to tinker with the Bitrate or smth. :)"),
|
"feel free to tinker with the Bitrate or smth. :)"),
|
||||||
AUDIO_SECTION,
|
AUDIO_SECTION,
|
||||||
|
Description("Modify how Music-Kraken connects to the internet:"),
|
||||||
|
CONNECTION_SECTION,
|
||||||
Description("For all your Logging needs.\n"
|
Description("For all your Logging needs.\n"
|
||||||
"If you found a bug, and wan't to report it, please set the Logging level to 0,\n"
|
"If you found a bug, and wan't to report it, please set the Logging level to 0,\n"
|
||||||
"reproduce the bug, and attach the logfile in the bugreport. ^w^"),
|
"reproduce the bug, and attach the logfile in the bugreport. ^w^"),
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
import logging
|
||||||
|
from typing import Callable
|
||||||
|
|
||||||
|
from .base_classes import SingleAttribute, StringAttribute, Section, FloatAttribute, Description, IntAttribute, EmptyLine, BoolAttribute
|
||||||
|
|
||||||
|
|
||||||
|
class ConnectionSection(Section):
|
||||||
|
def __init__(self):
|
||||||
|
self.USE_TOR = BoolAttribute(
|
||||||
|
name="tor",
|
||||||
|
description="Route ALL traffic through Tor.\nNo guarantee though!",
|
||||||
|
value="false"
|
||||||
|
)
|
||||||
|
self.CHUNK_SIZE = IntAttribute(
|
||||||
|
name="chunk_size",
|
||||||
|
description="Size of the chunks that are streamed.",
|
||||||
|
value="1024"
|
||||||
|
)
|
||||||
|
self.SHOW_DOWNLOAD_ERRORS_THRESHOLD = FloatAttribute(
|
||||||
|
name="show_download_errors_threshold",
|
||||||
|
description="If the percentage of failed downloads goes over this threshold,\n"
|
||||||
|
"all the error messages are shown.",
|
||||||
|
value="0.3"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.attribute_list = [
|
||||||
|
self.USE_TOR,
|
||||||
|
self.CHUNK_SIZE,
|
||||||
|
self.SHOW_DOWNLOAD_ERRORS_THRESHOLD
|
||||||
|
]
|
||||||
|
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
|
||||||
|
CONNECTION_SECTION = ConnectionSection()
|
@ -4,7 +4,7 @@ from pathlib import Path
|
|||||||
from typing import List, Set, Tuple
|
from typing import List, Set, Tuple
|
||||||
|
|
||||||
from .path_manager import LOCATIONS
|
from .path_manager import LOCATIONS
|
||||||
from .config import LOGGING_SECTION, AUDIO_SECTION
|
from .config import LOGGING_SECTION, AUDIO_SECTION, CONNECTION_SECTION
|
||||||
|
|
||||||
# modifies the garbage collector to speed up the program
|
# modifies the garbage collector to speed up the program
|
||||||
# https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/
|
# https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/
|
||||||
@ -87,16 +87,16 @@ DEFAULT_VALUES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TOR: bool = False
|
TOR: bool = CONNECTION_SECTION.USE_TOR.object_from_value
|
||||||
proxies = {
|
proxies = {
|
||||||
'http': 'socks5h://127.0.0.1:9150',
|
'http': 'socks5h://127.0.0.1:9150',
|
||||||
'https': 'socks5h://127.0.0.1:9150'
|
'https': 'socks5h://127.0.0.1:9150'
|
||||||
} if TOR else {}
|
} if TOR else {}
|
||||||
|
|
||||||
# size of the chunks that are streamed
|
# size of the chunks that are streamed
|
||||||
CHUNK_SIZE = 1024
|
CHUNK_SIZE = CONNECTION_SECTION.CHUNK_SIZE.object_from_value
|
||||||
# this is a percentage describing the percentage of failed downloads,
|
# this is a percentage describing the percentage of failed downloads,
|
||||||
# relative to the total downloads.
|
# relative to the total downloads.
|
||||||
# If the percentage goes over this threshold DownloadResult returns the download errors
|
# If the percentage goes over this threshold DownloadResult returns the download errors
|
||||||
# in the __str__ method
|
# in the __str__ method
|
||||||
SHOW_DOWNLOAD_ERRORS_THRESHOLD = 0.3
|
SHOW_DOWNLOAD_ERRORS_THRESHOLD = CONNECTION_SECTION.SHOW_DOWNLOAD_ERRORS_THRESHOLD.object_from_value
|
||||||
|
Loading…
Reference in New Issue
Block a user