mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-18 00:54:26 -04:00
singlefile.py: Code to ensure options are deduplicated
This commit is contained in:
parent
8899fe0b92
commit
40659b5e9d
1 changed files with 22 additions and 2 deletions
|
@ -46,11 +46,31 @@ def save_singlefile(link: Link, out_dir: Optional[Path]=None, timeout: int=TIMEO
|
||||||
|
|
||||||
# SingleFile CLI Docs: https://github.com/gildas-lormeau/SingleFile/tree/master/cli
|
# SingleFile CLI Docs: https://github.com/gildas-lormeau/SingleFile/tree/master/cli
|
||||||
browser_args = '--browser-args={}'.format(json.dumps(browser_args[1:]))
|
browser_args = '--browser-args={}'.format(json.dumps(browser_args[1:]))
|
||||||
cmd = [
|
options = [
|
||||||
DEPENDENCIES['SINGLEFILE_BINARY']['path'],
|
|
||||||
*SINGLEFILE_ARGS,
|
*SINGLEFILE_ARGS,
|
||||||
'--browser-executable-path={}'.format(CHROME_BINARY),
|
'--browser-executable-path={}'.format(CHROME_BINARY),
|
||||||
browser_args,
|
browser_args,
|
||||||
|
]
|
||||||
|
|
||||||
|
# Deduplicate options (single-file doesn't like when you use the same option two times)
|
||||||
|
#
|
||||||
|
# NOTE: Options names that come first clobber conflicting names that come later
|
||||||
|
# My logic is SINGLEFILE_ARGS is the option that affects the singlefile command with most
|
||||||
|
# specificity, therefore the user sets it with a lot intent, therefore it should take precedence
|
||||||
|
# kind of like the ergonomic principle of lexical scope in programming languages.
|
||||||
|
seen_option_names = []
|
||||||
|
def test_seen(argument):
|
||||||
|
option_name = argument.split("=")[0]
|
||||||
|
if option_name in seen_option_names:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
seen_option_names.append(option_name)
|
||||||
|
return True
|
||||||
|
deduped_options = list(filter(test_seen, options))
|
||||||
|
|
||||||
|
cmd = [
|
||||||
|
DEPENDENCIES['SINGLEFILE_BINARY']['path'],
|
||||||
|
*deduped_options
|
||||||
link.url,
|
link.url,
|
||||||
output,
|
output,
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue