added innertube context for config

This commit is contained in:
Hellow
2023-09-10 17:27:07 +02:00
parent a81a4a05a7
commit e73e29e2cc
7 changed files with 89 additions and 78 deletions

View File

@@ -57,9 +57,16 @@ class Attribute:
self.name = name
self.raw_data = {name: default_value}
self.value = default_value
self.value = None
self.description: Optional[str] = description
self.loaded_settings: dict = None
def initialize_from_config(self, loaded_settings: dict):
self.loaded_settings = loaded_settings
if not self.load_toml(self.raw_data):
logging.warning(f"Couldn't load the initial value of {self.name}: {self.raw_data[self.name]}")
def unparse_simple_value(self, value: any) -> any:
return value
@@ -81,28 +88,27 @@ class Attribute:
return callback(__object)
def load_toml(self, loaded_toml: dict, loaded_settings: dict) -> bool:
def load_toml(self, loaded_toml: dict) -> bool:
"""
returns true if succesfull
"""
if self.name not in loaded_toml:
LOGGER.warning(f"No setting by the name {self.name} found in the settings file.")
loaded_settings[self.name] = self.value
self.loaded_settings.__setitem__(self.name, self.value, True)
return
self.raw_data = loaded_toml[self.name]
_object = deepcopy(loaded_toml[self.name])
try:
self._recursive_parse_object(_object, self.parse_simple_value)
parsed_object = self._recursive_parse_object(_object, self.parse_simple_value)
except SettingValueError as settings_error:
logging.warning(settings_error)
return False
self.value = _object
loaded_settings[self.name] = self.value
self.value = parsed_object
self.loaded_settings.__setitem__(self.name, self.value, True)
return True

View File

@@ -16,12 +16,15 @@ class ConfigDict(dict):
def __getattribute__(self, __name: str) -> Any:
return super().__getattribute__(__name)
def __setitem__(self, __key: Any, __value: Any) -> None:
attribute: Attribute = self.config_reference.attribute_map[__key]
attribute.load_toml({attribute.name: __value})
self.config_reference.write()
def __setitem__(self, __key: Any, __value: Any, from_attribute: bool = False) -> None:
if not from_attribute:
attribute: Attribute = self.config_reference.attribute_map[__key]
attribute.load_toml({attribute.name: __value})
self.config_reference.write()
return super().__setitem__(__key, attribute.value)
__value = attribute.value
return super().__setitem__(__key, __value)
class Config:
@@ -29,15 +32,15 @@ class Config:
self.config_file: Path = config_file
self.component_list: Tuple[Union[Attribute, Description, EmptyLine]] = componet_list
self.loaded_settings: dict = {}
self.loaded_settings: ConfigDict = ConfigDict(self)
self.attribute_map = {}
for component in self.component_list:
if not isinstance(component, Attribute):
continue
component.initialize_from_config(self.loaded_settings)
self.attribute_map[component.name] = component
self.loaded_settings[component.name] = component.value
@property
def toml_string(self):
@@ -59,4 +62,4 @@ class Config:
for component in self.component_list:
if isinstance(component, Attribute):
component.load_toml(toml_data, self.loaded_settings)
component.load_toml(toml_data)

View File

@@ -30,7 +30,59 @@ Dw. if it is empty, Rachel will fetch it automatically for you <333
"https://www.youtu.be/"
], description="""This is used to detect, if an url is from youtube, or any alternativ frontend.
If any instance seems to be missing, run music kraken with the -f flag."""),
Attribute(name="use_sponsor_block", default_value=True, description="Use sponsor block to remove adds or simmilar from the youtube videos.")
Attribute(name="use_sponsor_block", default_value=True, description="Use sponsor block to remove adds or simmilar from the youtube videos."),
Attribute(name="youtube_music_innertube_context", default_value={
"client": {
"hl": "en",
"gl": "DE",
"remoteHost": "87.123.241.77",
"deviceMake": "",
"deviceModel": "",
"visitorData": "CgtiTUxaTHpoXzk1Zyia59WlBg%3D%3D",
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
"clientName": "WEB_REMIX",
"clientVersion": "1.20230710.01.00",
"osName": "X11",
"osVersion": "",
"originalUrl": "https://music.youtube.com/",
"platform": "DESKTOP",
"clientFormFactor": "UNKNOWN_FORM_FACTOR",
"configInfo": {
"appInstallData": "",
"coldConfigData": "",
"coldHashData": "",
"hotHashData": ""
},
"userInterfaceTheme": "USER_INTERFACE_THEME_DARK",
"timeZone": "Atlantic/Jan_Mayen",
"browserName": "Firefox",
"browserVersion": "115.0",
"acceptHeader": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"deviceExperimentId": "ChxOekkxTmpnek16UTRNVFl4TkRrek1ETTVOdz09EJrn1aUGGJrn1aUG",
"screenWidthPoints": 584,
"screenHeightPoints": 939,
"screenPixelDensity": 1,
"screenDensityFloat": 1,
"utcOffsetMinutes": 120,
"musicAppInfo": {
"pwaInstallabilityStatus": "PWA_INSTALLABILITY_STATUS_UNKNOWN",
"webDisplayMode": "WEB_DISPLAY_MODE_BROWSER",
"storeDigitalGoodsApiSupportStatus": {
"playStoreDigitalGoodsApiSupportStatus": "DIGITAL_GOODS_API_SUPPORT_STATUS_UNSUPPORTED"
}
}
},
"user": { "lockedSafetyMode": False },
"request": {
"useSsl": True,
"internalExperimentFlags": [],
"consistencyTokenJars": []
},
"adSignalsInfo": {
"params": []
}
}, description="Don't bother about this. It is something technical, but if you wanna change the innertube requests... go on.")
], LOCATIONS.get_config_file("youtube"))
@@ -43,3 +95,4 @@ class SettingsStructure(TypedDict):
youtube_music_clean_data: bool
youtube_url: List[ParseResult]
use_sponsor_block: bool
youtube_music_innertube_context: dict