Skip to content

Instantly share code, notes, and snippets.

@hguandl
Last active May 17, 2024 19:19
Show Gist options
  • Save hguandl/1d5baee93b9c7da1dfad7dc856028637 to your computer and use it in GitHub Desktop.
Save hguandl/1d5baee93b9c7da1dfad7dc856028637 to your computer and use it in GitHub Desktop.
Arknights Official QQ Emoji Downloader
#!/usr/bin/env python3
import requests
import json
import os
"""""""""""""""""""""""""""""""""""""""
Please enter your cookies below
after login in https://i.qq.com
"""
p_skey = ""
uin = ""
skey = ""
"""
Please enter your cookies above
"""""""""""""""""""""""""""""""""""""""
# Download path
OUTPUT_DIR = "ak_faces"
# Try times for login
MAX_TRY = 5
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}; uin={uin}; skey={skey}",
"accept": "application/json"
}
r = requests.get(f"https://open.vip.qq.com/open/getAuthorDetail?authorId=40424&g_tk={g_tk}", headers = headers)
try:
resp = json.loads(r.text)
data = resp.get("data")
return data.get("itemList")
except:
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:
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:
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)
@hguandl
Copy link
Author

hguandl commented Jun 3, 2022

死去的 gist 忽然开始攻击我.webp,周末我看一看要怎么改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment