-
-
Save SrC2O4/9d9f8f50b8eff4f5ae880e67cd811b7e to your computer and use it in GitHub Desktop.
Arknights Official QQ Emoji Downloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import requests | |
import json | |
import os | |
from bs4 import BeautifulSoup | |
import re | |
""""""""""""""""""""""""""""""""""""""" | |
- English Instructions- | |
Please enter your cookies below | |
after login in https://i.qq.com | |
- 中文指南 - | |
登录 https://i.qq.com 后获取自己的cookies填入下面的四个对应的变量里 | |
获取cookies的方式请善用搜索引擎 | |
""" | |
p_skey = "" | |
uin = "" | |
skey = "" | |
pt4_token = "" | |
used_ujax = True | |
""" | |
Please enter your cookies above | |
""""""""""""""""""""""""""""""""""""""" | |
# Download path | |
OUTPUT_DIR = "ak_faces" | |
# Try times for login | |
MAX_TRY = 10 | |
def get_g_tk(key): | |
hash = 5381 | |
for i in key: | |
hash += (hash << 5) + ord(i) | |
return hash & 0xffffffff | |
def login_fetch(isUajax): | |
if isUajax: | |
g_tk = get_g_tk(p_skey) | |
else: | |
g_tk = get_g_tk(skey) | |
headers = { | |
"Cookie": f"p_skey={p_skey}; p_uin={uin}; uin={uin}; skey={skey}; pt4_token={pt4_token};", | |
"accept": "image/webp,image/apng,image/*,*/*;q=0.8", | |
"User-Agent": "QQ/8.8.68.7265 NetType/WIFI WebP/0.4.1 Pixel/1080 StatusBarHeight/54 SimpleUISwitch/0 QQTheme/1000 InMagicWin/0 StudyMode/0 CurrentMode/0 CurrentFontScale/1.0 GlobalDensityScale/1.0", | |
"X-Requested_With":"com.tencent.mobileqq" | |
} | |
r = requests.get(f"https://zb.vip.qq.com/v2/pages/beautyMall?supplyerid=1112171476", | |
headers=headers) | |
try: | |
resp = BeautifulSoup(r.text, "html.parser").body.find_all('script') | |
for script in resp: | |
if not script.contents: | |
continue | |
if "window.__INITIAL_ASYNCDATA__" not in script.contents[0]: | |
continue | |
data_raw = script.contents[0][29:] | |
data = json.loads(re.findall(r'({.*?});', data_raw)[0]) | |
return data['supplyerInfo']['rptOpenitem'] | |
return None | |
except Exception as ex: | |
print(ex) | |
return None | |
def get_face_list(max_try): | |
for i in range(max_try): | |
print(f"Attempt {i+1}... ", end="") | |
itemList = login_fetch(True) | |
if itemList is None: | |
used_ujax = False | |
itemList = login_fetch(False) | |
if itemList is None: | |
print("failed.") | |
else: | |
print("successed!") | |
return itemList | |
raise ValueError("Login failed. Please check your cookies.") | |
def download_face(item): | |
item_id = item.get("itemid") | |
emoji_resp = requests.get(f"https://gxh.vip.qq.com/qqshow/admindata/comdata/vipEmoji_item_{item_id}/xydata.js") | |
try: | |
emoji_json = emoji_resp.text[emoji_resp.text.find('{'):] | |
emoji_data = json.loads(emoji_json) | |
base_info = emoji_data.get("data").get("baseInfo")[0] | |
md5_info = emoji_data.get("data").get("md5Info") | |
# Handle a package | |
pack_name = base_info["name"] | |
pack_path = os.path.join(OUTPUT_DIR, pack_name) | |
if not os.path.exists(pack_path): | |
os.mkdir(pack_path) | |
# Handle an image in the package | |
for pic in md5_info: | |
pic_name = pic["name"] | |
pic_md5 = pic["md5"] | |
pic_url = f"https://gxh.vip.qq.com/club/item/parcel/item/{pic_md5[:2]}/{pic_md5}/300x300.png" | |
print(f"{pack_name} - {pic_name}: {pic_url}") | |
open(os.path.join(pack_path, f"{pic_name}.png"), "wb").write(requests.get(pic_url).content) | |
except: | |
print("Something is wrong") | |
pass | |
if __name__ == "__main__": | |
if not os.path.exists(OUTPUT_DIR): | |
os.mkdir(OUTPUT_DIR) | |
for emoji in get_face_list(MAX_TRY): | |
download_face(emoji) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
修改于2022-06-02
已经完全修好以应对角在QQ官方表情商场里换号
需要多填写一个cookies里的token
采用BeautifulSoup和正则提取新的列表