A complete gutting of the internals of ytdl-sub to support functions in our variable syntax, in addition to being able to access a yt-dlp entry's .info.json fields using functions. Functionally, ytdl-sub should still look and behave the same from a user-perspective. With so many lines of code changed (+8927, -2708), no doubt there will be new issues. Please make a GH issue or reach out on Discord if your config/subscriptions break in any way/shape/form. Details on how to use function support will come soon in the form of proper documentation in our readthedocs.
63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
from ytdl_sub.script.script import Script
|
|
from ytdl_sub.script.script_output import ScriptOutput
|
|
from ytdl_sub.script.types.map import Map
|
|
from ytdl_sub.script.types.resolvable import String
|
|
|
|
|
|
class TestScript:
|
|
def test_pre_resolved(self):
|
|
assert Script(
|
|
{
|
|
"%custom_func": "return {[$0, $1]}",
|
|
"aa": "a",
|
|
"bb": "b",
|
|
"cc": "{%custom_func(aa, bb)}",
|
|
}
|
|
).resolve(resolved={"bb": String("bb_override")}) == ScriptOutput(
|
|
{
|
|
"aa": String("a"),
|
|
"bb": String("bb_override"),
|
|
"cc": String('return ["a", "bb_override"]'),
|
|
}
|
|
)
|
|
|
|
def test_partial_resolve(self):
|
|
assert Script(
|
|
{
|
|
"%custom_func": "return {[$0, $1]}",
|
|
"aa": "a",
|
|
"bb": "b",
|
|
"cc": "{%custom_func(aa, bb)}",
|
|
}
|
|
).resolve(unresolvable={"bb"}) == ScriptOutput({"aa": String("a")})
|
|
|
|
def test_partial_update_script(self):
|
|
# to be resolved later
|
|
entry_map = Map({String("title"): String("the title")})
|
|
|
|
script = Script(
|
|
{
|
|
"entry": "{%throw('entry has not been populated yet')}",
|
|
"title": "{%map_get(entry, 'title')}",
|
|
"override": "hi",
|
|
"resolved_override": "{override} mom",
|
|
}
|
|
)
|
|
|
|
script.resolve(unresolvable={"entry"}, update=True)
|
|
assert script.get("override") == String("hi")
|
|
assert script.get("resolved_override") == String("hi mom")
|
|
|
|
script.add(
|
|
{
|
|
"new_variable_titlecase": "{%titlecase(new_variable_upper)}",
|
|
"new_variable": "{resolved_override} {title}",
|
|
"new_variable_upper": "{%upper(new_variable)}",
|
|
}
|
|
).resolve(resolved={"entry": entry_map}, update=True)
|
|
|
|
assert script.get("title") == String("the title")
|
|
assert script.get("new_variable") == String("hi mom the title")
|
|
assert script.get("new_variable_upper") == String("HI MOM THE TITLE")
|
|
assert script.get("new_variable_titlecase") == String("Hi Mom The Title")
|
|
assert script.get("entry") == entry_map
|