mirror of
https://github.com/JulienMalka/snowfield.git
synced 2025-03-28 14:50:55 +01:00
Flaresolverr update step 1
This commit is contained in:
parent
dc4dac8ba3
commit
4734f6c261
3 changed files with 83 additions and 45 deletions
54
packages/flaresolverr/chromedriver_path.patch
Normal file
54
packages/flaresolverr/chromedriver_path.patch
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
diff --git a/src/utils.py b/src/utils.py
|
||||||
|
index 79cf6f6..fef4a68 100644
|
||||||
|
--- a/src/utils.py
|
||||||
|
+++ b/src/utils.py
|
||||||
|
@@ -154,47 +154,8 @@ def get_webdriver(proxy: dict = None) -> WebDriver:
|
||||||
|
else:
|
||||||
|
start_xvfb_display()
|
||||||
|
|
||||||
|
- # if we are inside the Docker container, we avoid downloading the driver
|
||||||
|
- driver_exe_path = None
|
||||||
|
- version_main = None
|
||||||
|
- if os.path.exists("/app/chromedriver"):
|
||||||
|
- # running inside Docker
|
||||||
|
- driver_exe_path = "/app/chromedriver"
|
||||||
|
- else:
|
||||||
|
- version_main = get_chrome_major_version()
|
||||||
|
- # Fix for Chrome 115
|
||||||
|
- # https://github.com/seleniumbase/SeleniumBase/pull/1967
|
||||||
|
- if int(version_main) > 114:
|
||||||
|
- version_main = 114
|
||||||
|
- if PATCHED_DRIVER_PATH is not None:
|
||||||
|
- driver_exe_path = PATCHED_DRIVER_PATH
|
||||||
|
-
|
||||||
|
- # detect chrome path
|
||||||
|
- browser_executable_path = get_chrome_exe_path()
|
||||||
|
-
|
||||||
|
- # downloads and patches the chromedriver
|
||||||
|
- # if we don't set driver_executable_path it downloads, patches, and deletes the driver each time
|
||||||
|
- driver = uc.Chrome(options=options, browser_executable_path=browser_executable_path,
|
||||||
|
- driver_executable_path=driver_exe_path, version_main=version_main,
|
||||||
|
- windows_headless=windows_headless, headless=windows_headless)
|
||||||
|
-
|
||||||
|
- # save the patched driver to avoid re-downloads
|
||||||
|
- if driver_exe_path is None:
|
||||||
|
- PATCHED_DRIVER_PATH = os.path.join(driver.patcher.data_path, driver.patcher.exe_name)
|
||||||
|
- if PATCHED_DRIVER_PATH != driver.patcher.executable_path:
|
||||||
|
- shutil.copy(driver.patcher.executable_path, PATCHED_DRIVER_PATH)
|
||||||
|
-
|
||||||
|
- # clean up proxy extension directory
|
||||||
|
- if proxy_extension_dir is not None:
|
||||||
|
- shutil.rmtree(proxy_extension_dir)
|
||||||
|
-
|
||||||
|
- # selenium vanilla
|
||||||
|
- # options = webdriver.ChromeOptions()
|
||||||
|
- # options.add_argument('--no-sandbox')
|
||||||
|
- # options.add_argument('--window-size=1920,1080')
|
||||||
|
- # options.add_argument('--disable-setuid-sandbox')
|
||||||
|
- # options.add_argument('--disable-dev-shm-usage')
|
||||||
|
- # driver = webdriver.Chrome(options=options)
|
||||||
|
+ driver = uc.Chrome(options=options, driver_executable_path="@chromedriver_path@",
|
||||||
|
+ windows_headless=windows_headless)
|
||||||
|
|
||||||
|
return driver
|
||||||
|
|
|
@ -1,46 +1,51 @@
|
||||||
{ pkgs, lib, stdenv, python3 }:
|
{ lib, stdenv, python3, chromium, xvfb-run, xorgserver, makeWrapper, chromedriver, fetchFromGitHub, substituteAll }:
|
||||||
with pkgs;
|
|
||||||
let
|
let
|
||||||
python_env = pkgs.python3.withPackages
|
python_env = python3.withPackages
|
||||||
(p: with p; [ bottle waitress selenium func-timeout requests websockets xvfbwrapper ]);
|
(p: with p; [ bottle waitress selenium func-timeout requests websockets xvfbwrapper webtest certifi prometheus-client ]);
|
||||||
|
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation
|
stdenv.mkDerivation rec {
|
||||||
rec {
|
|
||||||
|
|
||||||
pname = "flaresolverr";
|
pname = "flaresolverr";
|
||||||
version = "3.1.2";
|
version = "3.3.6";
|
||||||
|
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
owner = pname;
|
owner = pname;
|
||||||
repo = pname;
|
repo = pname;
|
||||||
rev = "v${version}";
|
rev = "v${version}";
|
||||||
sha256 = "sha256-36ILIyMTzm9pK9aakfZHfsHWy9xHtFez8QGZuIJ04vM=";
|
sha256 = "sha256-lSOw63yjFdi32N44r3A8Ggvexpov9CnaEP7fD7EBdKc=";
|
||||||
};
|
};
|
||||||
|
|
||||||
buildInputs = [ pkgs.makeWrapper ];
|
buildInputs = [ makeWrapper ];
|
||||||
nativeBuildInputs = [ chromedriver ];
|
nativeBuildInputs = [ chromedriver ];
|
||||||
patches = [ ./flaresolverr.patch ];
|
|
||||||
|
|
||||||
postPatch = ''
|
patches = [
|
||||||
substituteInPlace src/utils.py \
|
(substituteAll {
|
||||||
--replace "CHANGEME" "${pkgs.chromedriver}/bin/chromedriver"
|
src = ./chromedriver_path.patch;
|
||||||
'';
|
chromedriver_path = "${chromedriver}/bin/chromedriver";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
mkdir -p $out/share
|
mkdir -p $out/share
|
||||||
cp -r . $out/share
|
cp -r src $out/share/flaresolverr
|
||||||
|
cp package.json $out/share/flaresolverr
|
||||||
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
postFixup = ''
|
postFixup = ''
|
||||||
makeWrapper ${python_env}/bin/python $out/bin/flaresolverr \
|
makeWrapper ${python_env}/bin/python $out/bin/flaresolverr \
|
||||||
--prefix PATH : ${lib.makeBinPath [ pkgs.chromium pkgs.xvfb-run xorg.xorgserver pkgs.chromedriver ]} \
|
--prefix PATH : ${lib.makeBinPath [ chromium xvfb-run xorgserver chromedriver ]} \
|
||||||
--add-flags $out/share/src/flaresolverr.py \
|
--add-flags $out/share/flaresolverr/flaresolverr.py \
|
||||||
--chdir $out/share/
|
--chdir $out/share/flaresolverr
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta.platforms = [ "x86_64-linux" ];
|
meta = with lib; {
|
||||||
|
description = "Proxy server to bypass Cloudflare protection";
|
||||||
|
homepage = "https://github.com/FlareSolverr/FlareSolverr";
|
||||||
|
license = licenses.mit;
|
||||||
|
maintainers = with maintainers; [ julienmalka ];
|
||||||
|
# Flaresolverr will not run without chromedriver and xvfb-run
|
||||||
|
platforms = lib.intersectLists chromedriver.meta.platforms xvfb-run.meta.platforms;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
diff --git a/src/utils.py b/src/utils.py
|
|
||||||
index eee8868..4b0d226 100644
|
|
||||||
--- a/src/utils.py
|
|
||||||
+++ b/src/utils.py
|
|
||||||
@@ -80,14 +80,10 @@ def get_webdriver() -> WebDriver:
|
|
||||||
|
|
||||||
# downloads and patches the chromedriver
|
|
||||||
# if we don't set driver_executable_path it downloads, patches, and deletes the driver each time
|
|
||||||
- driver = uc.Chrome(options=options, browser_executable_path=browser_executable_path,
|
|
||||||
- driver_executable_path=driver_exe_path, version_main=version_main,
|
|
||||||
- windows_headless=windows_headless)
|
|
||||||
+ driver = uc.Chrome(options=options, driver_executable_path="CHANGEME", windows_headless=windows_headless)
|
|
||||||
|
|
||||||
# save the patched driver to avoid re-downloads
|
|
||||||
- if driver_exe_path is None:
|
|
||||||
- PATCHED_DRIVER_PATH = os.path.join(driver.patcher.data_path, driver.patcher.exe_name)
|
|
||||||
- shutil.copy(driver.patcher.executable_path, PATCHED_DRIVER_PATH)
|
|
||||||
+
|
|
||||||
|
|
||||||
# selenium vanilla
|
|
||||||
# options = webdriver.ChromeOptions()
|
|
Loading…
Add table
Reference in a new issue