Rollback previous changes around the presence of a default user-agent

- Remove default userAgent value
- Set a default mobileDevice
- Add back comments explaining that userAgent overrides other settings
- Add back logic around the computation of the userAgentSuffix instead
  of the userAgent
- Add new noMobileDevice argument to not set the default mobileDevice
This commit is contained in:
benoit74 2024-03-27 13:16:00 +00:00
parent 54732692ac
commit 3070fe9724
No known key found for this signature in database
GPG Key ID: B89606434FC7B530
2 changed files with 23 additions and 18 deletions

View File

@ -26,11 +26,6 @@ from zimscraperlib.uri import rebuild_uri
from zimit.__about__ import __version__
DEFAULT_USER_AGENT = (
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 "
"(KHTML, like Gecko) Version/17.0 Safari/605.1.15"
)
EXIT_CODE_WARC2ZIM_CHECK_FAILED = 2
EXIT_CODE_CRAWLER_LIMIT_HIT = 11
NORMAL_WARC2ZIM_EXIT_CODE = 100
@ -230,13 +225,21 @@ def run(raw_args):
help="Emulate mobile device by name from "
"https://github.com/puppeteer/puppeteer/blob/"
"main/packages/puppeteer-core/src/common/Device.ts",
default="Pixel 2",
)
parser.add_argument(
"--noMobileDevice",
help="Do not emulate a mobile device (use at your own risk, behavior is"
"uncertain)",
action="store_true",
default=False,
)
parser.add_argument(
"--userAgent",
help="Override default user-agent with specified value ; --userAgentSuffix is "
"still applied",
default=DEFAULT_USER_AGENT,
help="Override default user-agent with specified value ; --userAgentSuffix and "
"--adminEmail have no effect when this is set",
)
parser.add_argument(
@ -384,11 +387,9 @@ def run(raw_args):
url = zimit_args.url
user_agent = zimit_args.userAgent
if zimit_args.userAgentSuffix:
user_agent += f" {zimit_args.userAgentSuffix}"
user_agent_suffix = zimit_args.userAgentSuffix
if zimit_args.adminEmail:
user_agent += f" {zimit_args.adminEmail}"
user_agent_suffix += f" {zimit_args.adminEmail}"
if url:
url = get_cleaned_url(url)
@ -443,8 +444,12 @@ def run(raw_args):
cmd_args.append("--url")
cmd_args.append(url)
cmd_args.append("--userAgent")
cmd_args.append(user_agent)
cmd_args.append("--userAgentSuffix")
cmd_args.append(user_agent_suffix)
if not zimit_args.noMobileDevice:
cmd_args.append("--mobileDevice")
cmd_args.append(zimit_args.mobileDevice)
cmd_args.append("--cwd")
cmd_args.append(str(temp_root_dir))
@ -538,7 +543,7 @@ def get_node_cmd_line(args):
"collection",
"allowHashUrls",
"lang",
"mobileDevice",
"userAgent",
"useSitemap",
"behaviors",
"behaviorTimeout",

View File

@ -1,6 +1,6 @@
from zimit.zimit import DEFAULT_USER_AGENT
from zimit.zimit import NORMAL_WARC2ZIM_EXIT_CODE
# dummy test, just to have coverage report done
def test_default_user_agent():
assert DEFAULT_USER_AGENT
def test_something_exists():
assert NORMAL_WARC2ZIM_EXIT_CODE