with variables
This commit is contained in:
parent
662e7fe26e
commit
80e383465d
4 changed files with 42 additions and 5 deletions
|
|
@ -7,7 +7,7 @@ from ytdl_sub.config.plugin.preset_plugins import PresetPlugins
|
||||||
from ytdl_sub.config.preset_options import OutputOptions
|
from ytdl_sub.config.preset_options import OutputOptions
|
||||||
from ytdl_sub.config.validators.options import OptionsValidator
|
from ytdl_sub.config.validators.options import OptionsValidator
|
||||||
from ytdl_sub.downloaders.url.validators import MultiUrlValidator
|
from ytdl_sub.downloaders.url.validators import MultiUrlValidator
|
||||||
from ytdl_sub.validators.string_formatter_validators import validate_formatters
|
from ytdl_sub.validators.string_formatter_validators import validate_formatters, _validate_formatter
|
||||||
|
|
||||||
|
|
||||||
class VariableValidation:
|
class VariableValidation:
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,20 @@ class ScriptUtils:
|
||||||
if isinstance(arg, String):
|
if isinstance(arg, String):
|
||||||
if arg.native == "":
|
if arg.native == "":
|
||||||
return "" if top_level else "''"
|
return "" if top_level else "''"
|
||||||
return arg.native if top_level else f"'''{arg.native}'''"
|
|
||||||
|
contains_single_quote = "'" in arg.native
|
||||||
|
contains_double_quote = '"' in arg.native
|
||||||
|
|
||||||
|
if not contains_single_quote and not contains_double_quote:
|
||||||
|
quote = '"'
|
||||||
|
elif not contains_single_quote and contains_double_quote:
|
||||||
|
quote = "'"
|
||||||
|
elif contains_single_quote and not contains_double_quote:
|
||||||
|
quote = '"'
|
||||||
|
else:
|
||||||
|
quote = "'''"
|
||||||
|
|
||||||
|
return arg.native if top_level else f"{quote}{arg.native}{quote}"
|
||||||
|
|
||||||
if isinstance(arg, Integer):
|
if isinstance(arg, Integer):
|
||||||
out = f"%int({arg.native})"
|
out = f"%int({arg.native})"
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class TestInspect:
|
||||||
"info_json_name": "{episode_file_path}.{info_json_ext}",
|
"info_json_name": "{episode_file_path}.{info_json_ext}",
|
||||||
"keep_files_date_eval": "{episode_date_standardized}",
|
"keep_files_date_eval": "{episode_date_standardized}",
|
||||||
"maintain_download_archive": True,
|
"maintain_download_archive": True,
|
||||||
"output_directory": "/var/folders/rw/hl1xmkmj68zdl2kjx3l0dwzc0000gn/T/tmp9ly59oqn/Jake Trains",
|
"output_directory": f"{output_directory}/Jake Trains",
|
||||||
"preserve_mtime": False,
|
"preserve_mtime": False,
|
||||||
"thumbnail_name": "{thumbnail_file_name}",
|
"thumbnail_name": "{thumbnail_file_name}",
|
||||||
},
|
},
|
||||||
|
|
@ -124,7 +124,7 @@ class TestInspect:
|
||||||
"tv_show_content_rating": "{ subscription_indent_2 }",
|
"tv_show_content_rating": "{ subscription_indent_2 }",
|
||||||
"tv_show_content_rating_default": "TV-14",
|
"tv_show_content_rating_default": "TV-14",
|
||||||
"tv_show_date_range_type": '{ %if( %contains( tv_show_by_date_season_ordering, "release" ), "release_date", "upload_date" ) }',
|
"tv_show_date_range_type": '{ %if( %contains( tv_show_by_date_season_ordering, "release" ), "release_date", "upload_date" ) }',
|
||||||
"tv_show_directory": "/var/folders/rw/hl1xmkmj68zdl2kjx3l0dwzc0000gn/T/tmp9ly59oqn",
|
"tv_show_directory": output_directory,
|
||||||
"tv_show_fanart_file_name": "fanart.jpg",
|
"tv_show_fanart_file_name": "fanart.jpg",
|
||||||
"tv_show_genre": "{ subscription_indent_1 }",
|
"tv_show_genre": "{ subscription_indent_1 }",
|
||||||
"tv_show_genre_default": "ytdl-sub",
|
"tv_show_genre_default": "ytdl-sub",
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ class TestScriptUtils:
|
||||||
"string": "value",
|
"string": "value",
|
||||||
"quotes": "has '' and \"\"",
|
"quotes": "has '' and \"\"",
|
||||||
"triple-single-quote": "right here! '''''''''''''''''''''''''''''' ack '''''''",
|
"triple-single-quote": "right here! '''''''''''''''''''''''''''''' ack '''''''",
|
||||||
|
"has-double-quotes": 'i got "some double quotes" in here',
|
||||||
|
"has-single-quotes": "i got 'some single quotes' in here",
|
||||||
|
"has-both-quotes": "i got 'both quotes\" in here",
|
||||||
"int": 1,
|
"int": 1,
|
||||||
"bool": True,
|
"bool": True,
|
||||||
"list": [1, 2, 3],
|
"list": [1, 2, 3],
|
||||||
|
|
@ -60,7 +63,15 @@ class TestScriptUtils:
|
||||||
|
|
||||||
def test_to_syntax_tree(self):
|
def test_to_syntax_tree(self):
|
||||||
out = ScriptUtils.to_native_script(
|
out = ScriptUtils.to_native_script(
|
||||||
{"{var_a}": "{var_b}", "static_a": "string with {var_c} in it"}
|
{
|
||||||
|
"{var_a}": "{var_b}",
|
||||||
|
"static_a": "string with {var_c} in it",
|
||||||
|
"quotes": "has '' and \"\"",
|
||||||
|
"triple-single-quote": "right here! '''''''''''''''''''''''''''''' ack '''''''",
|
||||||
|
"has-double-quotes": 'i got "some double quotes" in here',
|
||||||
|
"has-single-quotes": "i got 'some single quotes' in here",
|
||||||
|
"has-both-quotes": "i got 'both quotes\" in here",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
assert parse(out) == SyntaxTree(
|
assert parse(out) == SyntaxTree(
|
||||||
ast=[
|
ast=[
|
||||||
|
|
@ -75,6 +86,19 @@ class TestScriptUtils:
|
||||||
BuiltInFunction(name="string", args=[String(value=" in it")]),
|
BuiltInFunction(name="string", args=[String(value=" in it")]),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
String(value="quotes"): String(value="has '' and \"\""),
|
||||||
|
String(value="triple-single-quote"): String(
|
||||||
|
value="right here! '''''''''''''''''''''''''''''' ack '''''''"
|
||||||
|
),
|
||||||
|
String(value="has-double-quotes"): String(
|
||||||
|
value='i got "some double quotes" in here'
|
||||||
|
),
|
||||||
|
String(value="has-single-quotes"): String(
|
||||||
|
value="i got 'some single quotes' in here"
|
||||||
|
),
|
||||||
|
String(value="has-both-quotes"): String(
|
||||||
|
value="i got 'both quotes\" in here"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue