plugins: replace XPath f-strings with variables

This commit is contained in:
bastimeyer 2022-08-13 08:37:26 +02:00 committed by Forrest
parent 1ea5663971
commit 156b6602f4
4 changed files with 7 additions and 6 deletions

View File

@ -44,7 +44,7 @@ class DeutscheWelle(Plugin):
# find the video element of the selected channel ID first
# node-sets are always ordered by the document order, so these queries can't be merged into one
validate.all(
validate.xml_xpath(f".//video[../@data-channel-id='{channel}'][1]"),
validate.xml_xpath(".//video[../@data-channel-id=$channel][1]", channel=channel),
# validate.xml_element() can't be used here, because it discards parent nodes of the cloned return value
lambda res: res is not None,
validate.get(0),

View File

@ -146,7 +146,7 @@ class Experience:
def login_csrf(self):
return self.session.http.get(self.login_url, schema=validate.Schema(
validate.parse_html(),
validate.xml_xpath_string(f".//input[@name='{self.CSRF_NAME}'][1]/@value")
validate.xml_xpath_string(".//input[@name=$name][1]/@value", name=self.CSRF_NAME)
))
def login(self, email, password):

View File

@ -35,7 +35,8 @@ class MDStrm(Plugin):
pattern = fr"{search_string}\s*=\s*'([^']+)';"
_schema = validate.Schema(
validate.xml_xpath_string(
f".//script[@type='text/javascript'][contains(text(),'{search_string}')]/text()",
".//script[@type='text/javascript'][contains(text(),$search_string)]/text()",
search_string=search_string,
),
validate.none_or_all(
re.compile(pattern),

View File

@ -22,15 +22,15 @@ class UseeTV(Plugin):
for needle, errormsg in (
(
"This service is not available in your Country",
"\"This service is not available in your Country\"",
"The content is not available in your region",
),
(
"Silahkan login Menggunakan akun MyIndihome dan berlangganan minipack",
"\"Silahkan login Menggunakan akun MyIndihome dan berlangganan minipack\"",
"The content is not available without a subscription",
),
):
if validate.Schema(validate.xml_xpath(f""".//script[contains(text(), '"{needle}"')]""")).validate(root):
if validate.Schema(validate.xml_xpath(".//script[contains(text(),$needle)]", needle=needle)).validate(root):
log.error(errormsg)
return