Skip to content

Commit

Permalink
No longer depend on js2py for downloading kakao stickers due to nuitk…
Browse files Browse the repository at this point in the history
…a issue
  • Loading branch information
laggykiller committed Jun 6, 2024
1 parent 5d389c1 commit dbb666f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion AppImageBuilder-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
4 changes: 2 additions & 2 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 34 additions & 12 deletions src/sticker_convert/downloaders/download_kakao.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from __future__ import annotations

import itertools
import re
import json
import zipfile
from io import BytesIO
from pathlib import Path
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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit dbb666f

Please sign in to comment.