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)
@SrC2O4
Copy link

SrC2O4 commented Jun 14, 2021

您好,不知道您是否还在更新这个脚本。自从某天qq官方将表情包挪位后需要在请求作者信息的43行后加入一个wildcard参数
r = requests.get(f"https://open.vip.qq.com/open/getAuthorDetail?authorId=40424&g_tk={g_tk}&p_tk={p_tk}", headers = headers)
p_tk在cookies里叫pt4_token,可以额外设置多一个variable或者直接替换{p_tk}的内容

希望您能加上这一个参数,脚本就能正常运行了。
曾经的舟版用户Maximr和SrSO4敬上

@SrC2O4
Copy link

SrC2O4 commented Jun 2, 2022

您好,没想到一年后还会来评论lol
yj官方已经在qq表情商城里换号(不明原因),而且似乎qq表情商城也换了结构,新的表情列表只能通过BeautifulSoup暴力爬取+正则提取
由于改动较多我新建了一个fork,如有需要的话请来review一下?

@Soarniner
Copy link

您好,没想到一年后还会来评论lol yj官方已经在qq表情商城里换号(不明原因),而且似乎qq表情商城也换了结构,新的表情列表只能通过BeautifulSoup暴力爬取+正则提取 由于改动较多我新建了一个fork,如有需要的话请来review一下?

是dalao orz,去年那个我没跑成功,当时我还在Discord方舟中文服务器碰到dalao了,dalao还问我有没有跑成功,由于环境还没搭建好就暂时没回复/(ㄒoㄒ)/~~。后来发现有问题的时候已经隔了太久了就不好意思回复dalao了~( TロT)σ

@Soarniner
Copy link

Attempt 1... failed.
Attempt 2... failed.
Attempt 3... failed.
Attempt 4... failed.
Attempt 5... failed.
Attempt 6... failed.
Attempt 7... failed.
Attempt 8... failed.
Attempt 9... failed.
Attempt 10... failed.
Traceback (most recent call last):
File "D:\Notebook\Pictures\ak_face\ak_face_downloader.py", line 125, in
for emoji in get_face_list(MAX_TRY):
File "D:\Notebook\Pictures\ak_face\ak_face_downloader.py", line 89, in get_face_list
raise ValueError("Login failed. Please check your cookies.")
ValueError: Login failed. Please check your cookies.

依然是登不上去(T_T),检查了好几遍cookies应该是对的,难道是浏览器问题?去年我是在macOS上试的,这次我是在Windows上试也不行

@Soarniner
Copy link

试了下,换了Edge和IE也不行(T_T)

@SrC2O4
Copy link

SrC2O4 commented Jun 3, 2022

Attempt 1... failed. Attempt 2... failed. Attempt 3... failed. Attempt 4... failed. Attempt 5... failed. Attempt 6... failed. Attempt 7... failed. Attempt 8... failed. Attempt 9... failed. Attempt 10... failed. Traceback (most recent call last): File "D:\Notebook\Pictures\ak_face\ak_face_downloader.py", line 125, in for emoji in get_face_list(MAX_TRY): File "D:\Notebook\Pictures\ak_face\ak_face_downloader.py", line 89, in get_face_list raise ValueError("Login failed. Please check your cookies.") ValueError: Login failed. Please check your cookies.

依然是登不上去(T_T),检查了好几遍cookies应该是对的,难道是浏览器问题?去年我是在macOS上试的,这次我是在Windows上试也不行

你用的是我修正过的脚本吗……?
我自己用ide跑是没有问题的,你试试把脚本下载在电脑本地运行试试?
如果不是的话检查一下自己的dependency有没有装好?我额外使用了beautifulsoup

@Soarniner
Copy link

Attempt 1... failed. Attempt 2... failed. Attempt 3... failed. Attempt 4... failed. Attempt 5... failed. Attempt 6... failed. Attempt 7... failed. Attempt 8... failed. Attempt 9... failed. Attempt 10... failed. Traceback (most recent call last): File "D:\Notebook\Pictures\ak_face\ak_face_downloader.py", line 125, in for emoji in get_face_list(MAX_TRY): File "D:\Notebook\Pictures\ak_face\ak_face_downloader.py", line 89, in get_face_list raise ValueError("Login failed. Please check your cookies.") ValueError: Login failed. Please check your cookies.
依然是登不上去(T_T),检查了好几遍cookies应该是对的,难道是浏览器问题?去年我是在macOS上试的,这次我是在Windows上试也不行

你用的是我修正过的脚本吗……? 我自己用ide跑是没有问题的,你试试把脚本下载在电脑本地运行试试? 如果不是的话检查一下自己的dependency有没有装好?我额外使用了beautifulsoup

是的
我就是在电脑本地运行的,环境什么的应该没问题,Python版本是3.9,依赖应该也没问题,因为是刚刚pip install进来的。我还尝试在我的Windows Server服务器上跑了一次,换了个号,也是登不上去。

@SrC2O4
Copy link

SrC2O4 commented Jun 3, 2022

**Soarniner ** commented 1 hour ago

你既然知道我discord号不如直接dm我细说?(不是很想spam这里的评论区
得睡啦,醒了之后有时间看
btw给我发信息记得关于cookies的地方一定要遮盖(

@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