Unverified Commit d02fcdbb authored by dmMaze's avatar dmMaze Committed by GitHub
Browse files

Merge pull request #757 from bropines/dev

Fix lens and add gitignore experiments path
parents cd79aa29 c3dbec4b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ fonts/*
aria2c
python
git
modules/experiments
update_git.bat
launch_win_venv.bat
install_venv.bat
+28 −13
Original line number Diff line number Diff line
@@ -35,10 +35,24 @@ class LensCore:
        self.proxy = proxy
        self.cookie_jar = cookielib.CookieJar()

    def _send_request(self, url, headers, files):
    def _send_request(self, url, headers, files, params=None):
        try:
            client = httpx.Client(proxies=self.proxy) if self.proxy else httpx.Client()
            response = client.post(url, headers=headers, files=files)
            client_kwargs = {}
            if self.proxy:
                if isinstance(self.proxy, str):
                    client_kwargs['proxy'] = self.proxy
                elif isinstance(self.proxy, dict):
                    mounts = {}
                    if 'http://' in self.proxy:
                        mounts["http://"] = httpx.HTTPTransport(proxy=self.proxy['http://'])
                    if 'https://' in self.proxy:
                        mounts["https://"] = httpx.HTTPTransport(proxy=self.proxy['https://'])
                    if mounts:
                        client_kwargs['mounts'] = mounts
                else:
                    raise ValueError("Proxy must be a string or a dictionary")
            client = httpx.Client(**client_kwargs)
            response = client.post(url, headers=headers, files=files, params=params)
            if response.status_code == 303:
                raise Exception("Error 303: See Other. Potential misconfiguration in headers or file upload.")
            if response.status_code != 200:
@@ -56,7 +70,8 @@ class LensCore:
            'original_height': (None, str(dimensions[1])),
            'processed_image_dimensions': (None, f"{dimensions[0]},{dimensions[1]}")
        }
        response = self._send_request(self.LENS_ENDPOINT, headers, files)
        params = {'ep': 'ccm', 're': 'dcsp', 's': '4', 'st': str(time.time() * 1000), 'sideimagesearch': '1', 'vpw': str(dimensions[0]), 'vph': str(dimensions[1])}
        response = self._send_request(self.LENS_ENDPOINT, headers, files, params=params)
        if response.status_code != 200:
            raise Exception(f"Failed to upload image. Status code: {response.status_code}")

@@ -97,7 +112,7 @@ class LensAPI:
        if isinstance(data, list):
            for item in data:
                if isinstance(item, list):
                    for sub_item in item:
                    for sub_item in item: # Corrected loop variable name
                        if isinstance(sub_item, list) and len(sub_item) > 1 and isinstance(sub_item[0], str):
                            word = sub_item[0]
                            coords = sub_item[1]
@@ -261,7 +276,7 @@ class OCRLensAPI(OCRBase):
            try:
                params['delay'] = float(params['delay'])
            except (ValueError, TypeError):
                params['delay'] = 1.0  # Значение по умолчанию
                params['delay'] = 1.0  
        super().__init__(**params)
        self.api = LensAPI(proxy=self.proxy)
        self.last_request_time = 0
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ py7zr
multivolumefile
httpx[socks,brotli]
langdetect
translators
translators==5.9.5
json5
pywin32; sys_platform == 'win32'
winsdk; sys_platform == 'win32'