From dbb666fdfbdfa590629d4149b317866f732be5b9 Mon Sep 17 00:00:00 2001 From: laggykiller Date: Thu, 6 Jun 2024 22:58:30 +0800 Subject: [PATCH] No longer depend on js2py for downloading kakao stickers due to nuitka issue --- AppImageBuilder-arm64.yml | 2 +- compile.py | 4 +- requirements.txt | 1 - .../downloaders/download_kakao.py | 46 ++++++++++++++----- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/AppImageBuilder-arm64.yml b/AppImageBuilder-arm64.yml index 48f916ed..8a241809 100644 --- a/AppImageBuilder-arm64.yml +++ b/AppImageBuilder-arm64.yml @@ -17,7 +17,7 @@ script: # Install pip packages - mkdir wheel - - pip download --python-version=311 --abi=cp311 --platform manylinux2014_aarch64 --only-binary=':all:' -d wheel -r requirements.txt --extra-index-url https://www.piwheels.org/simple + - pip download --python-version=311 --abi=cp311 --platform manylinux2014_aarch64 --only-binary=':all:' -d wheel -r requirements.txt - pip download --python-version=311 --abi=cp311 --platform manylinux2014_aarch64 --only-binary=':all:' -d wheel certifi opencv-python - find ./wheel/*.whl -exec bash -c 'mv $0 ${0/-cp*.whl/-py3-none-any.whl}' {} \; - pip install --ignore-installed --prefix=/usr --root=AppDir ./wheel/* diff --git a/compile.py b/compile.py index 028648aa..f4530cea 100755 --- a/compile.py +++ b/compile.py @@ -92,10 +92,10 @@ def osx_install_universal2_dep() -> None: Path("wheel_universal2").mkdir() osx_run_in_venv( - "python -m pip download --require-virtualenv -r requirements.txt --platform macosx_11_0_arm64 --only-binary=:all: -d wheel_arm --extra-index-url https://www.piwheels.org/simple" + "python -m pip download --require-virtualenv -r requirements.txt --platform macosx_11_0_arm64 --only-binary=:all: -d wheel_arm" ) osx_run_in_venv( - "python -m pip download --require-virtualenv -r requirements.txt --platform macosx_11_0_x86_64 --only-binary=:all: -d wheel_x64 --extra-index-url https://www.piwheels.org/simple" + "python -m pip download --require-virtualenv -r requirements.txt --platform macosx_11_0_x86_64 --only-binary=:all: -d wheel_x64" ) create_universal_wheels( diff --git a/requirements.txt b/requirements.txt index cc7be686..e635b2d2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,6 @@ av~=12.1.0 beautifulsoup4~=4.12.3 rookiepy~=0.5.1 imagequant~=1.1.1 -js2py~=0.74 memory-tempfile~=2.2.3 mergedeep~=1.3.4 numpy>=1.22.4 diff --git a/src/sticker_convert/downloaders/download_kakao.py b/src/sticker_convert/downloaders/download_kakao.py index 7c247214..add5ead3 100755 --- a/src/sticker_convert/downloaders/download_kakao.py +++ b/src/sticker_convert/downloaders/download_kakao.py @@ -2,6 +2,7 @@ from __future__ import annotations import itertools +import re import json import zipfile from io import BytesIO @@ -9,7 +10,6 @@ from typing import Any, List, Optional, Tuple, cast from urllib.parse import urlparse -import js2py # type: ignore import requests from bs4 import BeautifulSoup from bs4.element import Tag @@ -72,17 +72,39 @@ def get_info_from_share_link(url: str) -> Tuple[Optional[str], Optional[str]]: js = js[func_start_pos:] bracket_start_pos = js.find("{") func_end_pos = search_bracket(js[bracket_start_pos:]) + bracket_start_pos - js = js[: func_end_pos + 1] - web2app_start_pos = js.find("daumtools.web2app(") - js = js[:web2app_start_pos] + "return a;}" - get_item_code = js2py.eval_js(js) # type: ignore - kakao_scheme_link = cast( - str, - get_item_code( - "kakaotalk://store/emoticon/${i}?referer=share_link", item_code_fake - ), - ) - item_code = urlparse(kakao_scheme_link).path.split("/")[-1] + js = js[bracket_start_pos + 1: func_end_pos] + js = js.split(";")[0] + + minus_num_regex = re.search(r"\-(.*?)\^", js) + if not minus_num_regex: + return None, None + minus_num_str = minus_num_regex.group(1) + if not minus_num_str.isnumeric(): + return None, None + minus_num = int(minus_num_str) + + xor_num_regex = re.search(r"\^(.*?)\)", js) + if not xor_num_regex: + return None, None + xor_num_str = xor_num_regex.group(1) + if not xor_num_str.isnumeric(): + return None, None + xor_num = int(xor_num_str) + + item_code = str(int(item_code_fake) - minus_num ^ xor_num) + + # https://github.com/Nuitka/Nuitka/issues/385 + # js2py not working if compiled by nuitka + # web2app_start_pos = js.find("daumtools.web2app(") + # js = js[:web2app_start_pos] + "return a;}" + # get_item_code = js2py.eval_js(js) # type: ignore + # kakao_scheme_link = cast( + # str, + # get_item_code( + # "kakaotalk://store/emoticon/${i}?referer=share_link", item_code_fake + # ), + # ) + # item_code = urlparse(kakao_scheme_link).path.split("/")[-1] return pack_title, item_code