mirror of
https://github.com/seanbetts/steam-hardware-watch.git
synced 2026-10-06 01:00:18 +02:00
Unblock Komodo hardware watch checks
This commit is contained in:
1 parent
e5e1c6e7db
commit
b269b90007
6 files changed
+53
-15
No files matched your search
@@ -55,12 +55,15 @@ maybe_set_cdp_endpoint() {
|
||||
|
||||
load_local_env
|
||||
|
||||
KOMODO_USER_AGENT="${KOMODO_USER_AGENT:-Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36}"
|
||||
export KOMODO_USER_AGENT
|
||||
|
||||
fetch_json() {
|
||||
name="$1"
|
||||
url="$2"
|
||||
allow_fallback="${3:-1}"
|
||||
tmp="$OUT_DIR/$name.json.tmp"
|
||||
if curl -A 'Mozilla/5.0' --retry 1 --retry-delay 1 --max-time 12 -fsSL "$url" > "$tmp" 2>/dev/null \
|
||||
if curl -A "$KOMODO_USER_AGENT" --retry 1 --retry-delay 1 --max-time 12 -fsSL "$url" > "$tmp" 2>/dev/null \
|
||||
&& jq empty "$tmp" >/dev/null 2>&1; then
|
||||
mv "$tmp" "$OUT_DIR/$name.json"
|
||||
return 0
|
||||
|
||||
@@ -23,6 +23,11 @@ function launchOptions(headless) {
|
||||
return options;
|
||||
}
|
||||
|
||||
function userAgent() {
|
||||
return process.env.KOMODO_USER_AGENT ||
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36";
|
||||
}
|
||||
|
||||
function findKomodoPage(context, origin) {
|
||||
const pages = context.pages();
|
||||
return pages.find((candidate) => candidate.url().startsWith(origin)) || pages[0] || null;
|
||||
@@ -66,7 +71,7 @@ async function main() {
|
||||
} else if (profileDir) {
|
||||
context = await chromium.launchPersistentContext(profileDir, {
|
||||
...launchOptions(headless),
|
||||
userAgent: "Mozilla/5.0",
|
||||
userAgent: userAgent(),
|
||||
});
|
||||
shouldCloseContext = true;
|
||||
page = context.pages()[0] || await context.newPage();
|
||||
@@ -74,7 +79,7 @@ async function main() {
|
||||
browser = await chromium.launch(launchOptions(headless));
|
||||
shouldCloseBrowser = true;
|
||||
context = await browser.newContext({
|
||||
userAgent: "Mozilla/5.0",
|
||||
userAgent: userAgent(),
|
||||
storageState: storageState || undefined,
|
||||
extraHTTPHeaders: referer ? { Referer: referer } : undefined,
|
||||
});
|
||||
|
||||
@@ -25,6 +25,11 @@ function launchOptions(headless) {
|
||||
return options;
|
||||
}
|
||||
|
||||
function userAgent() {
|
||||
return process.env.KOMODO_USER_AGENT ||
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36";
|
||||
}
|
||||
|
||||
function findKomodoPage(context, origin) {
|
||||
const pages = context.pages();
|
||||
return pages.find((candidate) => candidate.url().startsWith(origin)) || pages[0] || null;
|
||||
@@ -68,7 +73,7 @@ async function main() {
|
||||
} else if (profileDir) {
|
||||
context = await chromium.launchPersistentContext(profileDir, {
|
||||
...launchOptions(headless),
|
||||
userAgent: "Mozilla/5.0",
|
||||
userAgent: userAgent(),
|
||||
});
|
||||
shouldCloseContext = true;
|
||||
page = context.pages()[0] || await context.newPage();
|
||||
@@ -76,7 +81,7 @@ async function main() {
|
||||
browser = await chromium.launch(launchOptions(headless));
|
||||
shouldCloseBrowser = true;
|
||||
context = await browser.newContext({
|
||||
userAgent: "Mozilla/5.0",
|
||||
userAgent: userAgent(),
|
||||
storageState: storageState || undefined,
|
||||
extraHTTPHeaders: referer ? { Referer: referer } : undefined,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
@@ -20,6 +21,12 @@ VISUAL_EXTS = {
|
||||
".m4v",
|
||||
}
|
||||
|
||||
DEFAULT_USER_AGENT = (
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/123.0.0.0 Safari/537.36"
|
||||
)
|
||||
|
||||
|
||||
def is_visual_url(url: str) -> bool:
|
||||
path = urlparse(url).path.lower()
|
||||
@@ -167,7 +174,10 @@ def is_valid_download(url: str, content_type: str, data: bytes):
|
||||
|
||||
def download(url: str, dest: Path):
|
||||
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
headers={"User-Agent": os.environ.get("KOMODO_USER_AGENT", DEFAULT_USER_AGENT)},
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=15) as response:
|
||||
data = response.read()
|
||||
status = getattr(response, "status", 200)
|
||||
|
||||
Reference in new issue
Block a user