trying to bundle the changes

This commit is contained in:
Aria Moradi
2023-06-05 01:45:22 +03:30
parent 6934d344f0
commit e4a3dad4e8
2 changed files with 29 additions and 14 deletions

View File

@@ -26,8 +26,6 @@ main() {
set -- "${POSITIONAL_ARGS[@]}" set -- "${POSITIONAL_ARGS[@]}"
OS="$1" 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)" JAR="$(ls server/build/*.jar | tail -n1)"
RELEASE_NAME="$(echo "${JAR%.*}" | xargs basename)-$OS" RELEASE_NAME="$(echo "${JAR%.*}" | xargs basename)-$OS"
RELEASE_VERSION="$(tmp="${JAR%-*}"; echo "${tmp##*-}" | tr -d v)" 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" ELECTRON_URL="https://github.com/electron/electron/releases/download/$electron_version/$ELECTRON"
download_jre_and_electron download_jre_and_electron
PLAYWRIGHT_PLATFORM="win64" PYTHON=Winpython64-3.10.9.0dot.exe
setup_playwright 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" RELEASE="$RELEASE_NAME.zip"
make_windows_bundle make_windows_bundle
@@ -285,9 +284,23 @@ make_windows_package() {
"$RELEASE_NAME/jre.wxs" "$RELEASE_NAME/electron.wxs" -o "$RELEASE" "$RELEASE_NAME/jre.wxs" "$RELEASE_NAME/electron.wxs" -o "$RELEASE"
} }
setup_playwright() { setup_python() {
mkdir "$RELEASE_NAME/bin" mkdir "$RELEASE_NAME/"
curl -L "https://playwright.azureedge.net/builds/chromium/$PLAYWRIGHT_REVISION/chromium-$PLAYWRIGHT_PLATFORM.zip" -o "$RELEASE_NAME/bin/chromium.zip" 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 # Error handler

View File

@@ -22,6 +22,7 @@ import java.io.File
import java.io.IOException import java.io.IOException
import java.io.InputStreamReader import java.io.InputStreamReader
import java.io.PrintWriter import java.io.PrintWriter
import java.nio.file.Paths
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class CloudflareInterceptor : Interceptor { class CloudflareInterceptor : Interceptor {
@@ -88,8 +89,8 @@ object CloudflareBypasser {
val proxy = "socks5://${serverConfig.socksProxyHost}:${serverConfig.socksProxyPort}" val proxy = "socks5://${serverConfig.socksProxyHost}:${serverConfig.socksProxyPort}"
py.exec("options.add_argument('--proxy-server=$proxy')") py.exec("options.add_argument('--proxy-server=$proxy')")
} }
py.exec("driver = uc.Chrome(options=options)") // 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, driver_executable_path='${py.chromedriverPath.replace("\\","\\\\")}', version_main=111)")
// TODO: handle custom userAgent // TODO: handle custom userAgent
// val userAgent = originalRequest.header("User-Agent") // val userAgent = originalRequest.header("User-Agent")
@@ -155,8 +156,8 @@ object CloudflareBypasser {
py.exec("options = uc.ChromeOptions()") py.exec("options = uc.ChromeOptions()")
py.exec("options.add_argument('--headless')") py.exec("options.add_argument('--headless')")
py.exec("options.add_argument('--disable-gpu')") py.exec("options.add_argument('--disable-gpu')")
py.exec("driver = uc.Chrome(options=options)") // 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, driver_executable_path='${py.chromedriverPath.replace("\\","\\\\")}', version_main=111)")
py.exec("userAgent = driver.execute_script('return navigator.userAgent')") py.exec("userAgent = driver.execute_script('return navigator.userAgent')")
val userAgent = py.getValue("userAgent") val userAgent = py.getValue("userAgent")
@@ -236,8 +237,6 @@ private class CloudflareBypassException(message: String?) : Exception(message)
class PythonInterpreter class PythonInterpreter
private constructor(private val process: Process, val chromedriverPath: String) : Closeable { private constructor(private val process: Process, val chromedriverPath: String) : Closeable {
private val logger = KotlinLogging.logger {}
private val stdin = process.outputStream private val stdin = process.outputStream
private val stdout = process.inputStream private val stdout = process.inputStream
private val stderr = process.errorStream private val stderr = process.errorStream
@@ -303,6 +302,8 @@ private constructor(private val process: Process, val chromedriverPath: String)
destroy() destroy()
} }
companion object { companion object {
private val logger = KotlinLogging.logger {}
fun create(pythonPath: String, workingDir: String, pythonStartupFile: String, chromedriverPath: String): PythonInterpreter { fun create(pythonPath: String, workingDir: String, pythonStartupFile: String, chromedriverPath: String): PythonInterpreter {
val processBuilder = ProcessBuilder() val processBuilder = ProcessBuilder()
.command(pythonPath, "-i", "-q") .command(pythonPath, "-i", "-q")
@@ -317,7 +318,8 @@ private constructor(private val process: Process, val chromedriverPath: String)
} }
fun create(): PythonInterpreter { 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")) { val (pythonPath, chromedriverPath) = if (System.getProperty("os.name").startsWith("Windows")) {
arrayOf( arrayOf(