From e4a3dad4e8cfdd24e6ae9680486be903d36c9df1 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Mon, 5 Jun 2023 01:45:22 +0330 Subject: [PATCH] trying to bundle the changes --- scripts/bundler.sh | 27 ++++++++++++++----- .../interceptor/CloudflareInterceptor.kt | 16 ++++++----- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/scripts/bundler.sh b/scripts/bundler.sh index 952f65c6..e731277d 100755 --- a/scripts/bundler.sh +++ b/scripts/bundler.sh @@ -26,8 +26,6 @@ main() { set -- "${POSITIONAL_ARGS[@]}" OS="$1" - PLAYWRIGHT_VERSION="$(cat gradle/libs.versions.toml | grep -oP "playwright = \"\K([0-9\.]*)(?=\")")" - PLAYWRIGHT_REVISION="$(curl --silent "https://raw.githubusercontent.com/microsoft/playwright/v$PLAYWRIGHT_VERSION/packages/playwright-core/browsers.json" 2>&1 | grep -ozP "\"name\": \"chromium\",\n *\"revision\": \"\K[0-9]*")" JAR="$(ls server/build/*.jar | tail -n1)" RELEASE_NAME="$(echo "${JAR%.*}" | xargs basename)-$OS" RELEASE_VERSION="$(tmp="${JAR%-*}"; echo "${tmp##*-}" | tr -d v)" @@ -127,8 +125,9 @@ main() { ELECTRON_URL="https://github.com/electron/electron/releases/download/$electron_version/$ELECTRON" download_jre_and_electron - PLAYWRIGHT_PLATFORM="win64" - setup_playwright + PYTHON=Winpython64-3.10.9.0dot.exe + PYTHON_URL=https://github.com/winpython/winpython/releases/download/5.3.20221233/Winpython64-3.10.9.0dot.exe + setup_undetected_chromedriver_and_python RELEASE="$RELEASE_NAME.zip" make_windows_bundle @@ -285,9 +284,23 @@ make_windows_package() { "$RELEASE_NAME/jre.wxs" "$RELEASE_NAME/electron.wxs" -o "$RELEASE" } -setup_playwright() { - mkdir "$RELEASE_NAME/bin" - curl -L "https://playwright.azureedge.net/builds/chromium/$PLAYWRIGHT_REVISION/chromium-$PLAYWRIGHT_PLATFORM.zip" -o "$RELEASE_NAME/bin/chromium.zip" +setup_python() { + mkdir "$RELEASE_NAME/" + curl -L "$PYTHON_URL" -o "$PYTHON" + 7z x $PYTHON + mv WPy64-31090/python-3.10.9.amd64 "$RELEASE_NAME/python" +} + +setup_undetected_chromedriver() { + curl -L "https://github.com/Suwayomi/undetected-chromedriver/archive/refs/heads/master.zip" -o undetected-chromedriver-master.zip + unzip undetected-chromedriver-master.zip + mv undetected-chromedriver-master "$RELEASE_NAME/undetected-chromedriver" +} + + +setup_undetected_chromedriver_and_python() { + setup_python + setup_undetected_chromedriver } # Error handler diff --git a/server/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt b/server/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt index 7672c8cb..c2bf2a8b 100644 --- a/server/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt +++ b/server/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt @@ -22,6 +22,7 @@ import java.io.File import java.io.IOException import java.io.InputStreamReader import java.io.PrintWriter +import java.nio.file.Paths import java.util.concurrent.TimeUnit class CloudflareInterceptor : Interceptor { @@ -88,8 +89,8 @@ object CloudflareBypasser { val proxy = "socks5://${serverConfig.socksProxyHost}:${serverConfig.socksProxyPort}" py.exec("options.add_argument('--proxy-server=$proxy')") } - py.exec("driver = uc.Chrome(options=options)") - py.exec("driver = uc.Chrome(options=options, driver_executable_path='${py.chromedriverPath.replace("\\","\\\\")}')") +// py.exec("driver = uc.Chrome(options=options)") + py.exec("driver = uc.Chrome(options=options, driver_executable_path='${py.chromedriverPath.replace("\\","\\\\")}', version_main=111)") // TODO: handle custom userAgent // val userAgent = originalRequest.header("User-Agent") @@ -155,8 +156,8 @@ object CloudflareBypasser { py.exec("options = uc.ChromeOptions()") py.exec("options.add_argument('--headless')") py.exec("options.add_argument('--disable-gpu')") - py.exec("driver = uc.Chrome(options=options)") -// py.exec("driver = uc.Chrome(options=options, driver_executable_path='${py.chromedriverPath.replace("\\","\\\\")}')") +// py.exec("driver = uc.Chrome(options=options)") + py.exec("driver = uc.Chrome(options=options, driver_executable_path='${py.chromedriverPath.replace("\\","\\\\")}', version_main=111)") py.exec("userAgent = driver.execute_script('return navigator.userAgent')") val userAgent = py.getValue("userAgent") @@ -236,8 +237,6 @@ private class CloudflareBypassException(message: String?) : Exception(message) class PythonInterpreter private constructor(private val process: Process, val chromedriverPath: String) : Closeable { - private val logger = KotlinLogging.logger {} - private val stdin = process.outputStream private val stdout = process.inputStream private val stderr = process.errorStream @@ -303,6 +302,8 @@ private constructor(private val process: Process, val chromedriverPath: String) destroy() } companion object { + private val logger = KotlinLogging.logger {} + fun create(pythonPath: String, workingDir: String, pythonStartupFile: String, chromedriverPath: String): PythonInterpreter { val processBuilder = ProcessBuilder() .command(pythonPath, "-i", "-q") @@ -317,7 +318,8 @@ private constructor(private val process: Process, val chromedriverPath: String) } fun create(): PythonInterpreter { - val uc = File(serverConfig.undetectedChromePath).absolutePath + val uc = Paths.get(serverConfig.undetectedChromePath).toAbsolutePath().toString() + logger.debug { "absolute path to undetected-chromedriver: $uc" } val (pythonPath, chromedriverPath) = if (System.getProperty("os.name").startsWith("Windows")) { arrayOf(