Skip to content

Commit

Permalink
feat: refactor quark cookie acquisition
Browse files Browse the repository at this point in the history
  • Loading branch information
DDSRem committed Sep 21, 2024
1 parent 0554f06 commit f519000
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 280 deletions.
55 changes: 0 additions & 55 deletions .github/workflows/quark_cookie.yml

This file was deleted.

9 changes: 4 additions & 5 deletions all_in_one.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ function wait_xiaoya_start() {

function clear_qrcode_container() {

# shellcheck disable=SC2046
docker rm -f $(docker ps -a -q --filter ancestor=ddsderek/xiaoya-glue:quark_cookie) > /dev/null 2>&1
# shellcheck disable=SC2046
docker rm -f $(docker ps -a -q --filter ancestor=ddsderek/xiaoya-glue:python) > /dev/null 2>&1

Expand Down Expand Up @@ -401,7 +399,7 @@ function qrcode_quark_cookie() {
INFO "夸克 Cookie 扫码获取"
local local_ip
INFO "拉取镜像中..."
docker_pull ddsderek/xiaoya-glue:quark_cookie
docker_pull ddsderek/xiaoya-glue:python
if [[ "${OSNAME}" = "macos" ]]; then
local_ip=$(ifconfig "$(route -n get default | grep interface | awk -F ':' '{print$2}' | awk '{$1=$1};1')" | grep 'inet ' | awk '{print$2}')
else
Expand All @@ -415,9 +413,10 @@ function qrcode_quark_cookie() {
-v "${1}:/data" \
-e LANG=C.UTF-8 \
--net=host \
ddsderek/xiaoya-glue:quark_cookie
ddsderek/xiaoya-glue:python \
/quark_cookie/quark_cookie.py
INFO "清理镜像中..."
docker rmi ddsderek/xiaoya-glue:quark_cookie
docker rmi ddsderek/xiaoya-glue:python
INFO "操作全部完成!"
;;
*)
Expand Down
2 changes: 1 addition & 1 deletion glue_python/aliyunopentoken/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1>请打开阿里云盘扫描此二维码!</h1>
var poll = function() {
$.get('/status', function(data) {
if (data.status === 'success') {
alert('扫码成功,Cookie 已写入文件!');
alert('扫码成功,Token 已写入文件!');
shutdown();
} else if (data.status === 'failure') {
alert('扫码失败!');
Expand Down
2 changes: 1 addition & 1 deletion glue_python/aliyuntoken/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1>请打开阿里云盘扫描此二维码!</h1>
var poll = function() {
$.get('/status', function(data) {
if (data.status === 'success') {
alert('扫码成功,Cookie 已写入文件!');
alert('扫码成功,Token 已写入文件!');
shutdown();
} else if (data.status === 'failure') {
alert('扫码失败!');
Expand Down
6 changes: 6 additions & 0 deletions glue_python/quark_cookie/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Quark Cookie

- quark.cn
- uop.quark.cn
- su.quark.cn
- pan.quark.cn
101 changes: 101 additions & 0 deletions glue_python/quark_cookie/quark_cookie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/local/bin/python3

import json
import requests
import time
import logging
import os
import threading
import sys
import qrcode
import uuid
from flask import Flask, send_file, render_template, jsonify


app = Flask(__name__)
logging.basicConfig(level=logging.INFO)
last_status = 0
if sys.platform.startswith('win32'):
qrcode_dir = 'qrcode.png'
else:
qrcode_dir= '/quark_cookie/qrcode.png'


def cookiejar_to_string(cookiejar):
cookie_string = ""
for cookie in cookiejar:
cookie_string += cookie.name + "=" + cookie.value + "; "
return cookie_string.strip('; ')


def poll_qrcode_status(token):
global last_status
while True:
re = requests.get(f'https://uop.quark.cn/cas/ajax/getServiceTicketByQrcodeToken?client_id=532&v=1.2&token={token}&request_id={uuid.uuid4()}')
if re.status_code == 200:
re_data = json.loads(re.text)
if re_data['status'] == 2000000:
logging.info('扫码成功!')
service_ticket = re_data['data']['members']['service_ticket']
re = requests.get(f'https://pan.quark.cn/account/info?st={service_ticket}&lw=scan')
if re.status_code == 200:
quark_cookie = cookiejar_to_string(re.cookies)
if sys.platform.startswith('win32'):
with open('quark_cookie.txt', 'w') as f:
f.write(quark_cookie)
else:
with open('/data/quark_cookie.txt', 'w') as f:
f.write(quark_cookie)
logging.info('扫码成功,夸克 Cookie 已写入文件!')
last_status = 1
break
elif re_data['status'] == 50004002:
logging.error('二维码无效或已过期!')
break
elif re_data['status'] == 50004001:
logging.info('等待用户扫码...')
time.sleep(1)


@app.route("/")
def index():
return render_template('index.html')


@app.route('/image')
def serve_image():
return send_file(qrcode_dir, mimetype='image/png')


@app.route('/status')
def status():
if last_status == 1:
return jsonify({'status': 'success'})
elif last_status == 2:
return jsonify({'status': 'failure'})
else:
return jsonify({'status': 'unknown'})


@app.route('/shutdown_server', methods=['GET'])
def shutdown():
if os.path.isfile(qrcode_dir):
os.remove(qrcode_dir)
os._exit(0)


if __name__ == '__main__':
if os.path.isfile(qrcode_dir):
os.remove(qrcode_dir)
logging.info('二维码生成中...')
re = requests.get(f'https://uop.quark.cn/cas/ajax/getTokenForQrcodeLogin?client_id=532&v=1.2&request_id={uuid.uuid4()}')
if re.status_code == 200:
token = json.loads(re.text)['data']['members']['token']
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=5, border=4)
qr.add_data(f'https://su.quark.cn/4_eMHBJ?token={token}&client_id=532&ssb=weblogin&uc_param_str=&uc_biz_str=S%3Acustom%7COPT%3ASAREA%400%7COPT%3AIMMERSIVE%401%7COPT%3ABACK_BTN_STYLE%400')
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
img.save(qrcode_dir)
logging.info('二维码生成完成!')
threading.Thread(target=poll_qrcode_status, args=(token,)).start()
app.run(host='0.0.0.0', port=34256)
2 changes: 2 additions & 0 deletions glue_python/quark_cookie/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
qrcode
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<script src="{{ url_for('static', filename='jquery.min.js') }}"></script>
</head>
<body>
<h1>请打开夸克扫描此二维码</h1>
<h1>请打开夸克APP扫描此二维码</h1>
<img src="{{ url_for('serve_image') }}" alt="image">
<script>
var poll = function() {
Expand Down
6 changes: 0 additions & 6 deletions quark_cookie/.gitignore

This file was deleted.

24 changes: 0 additions & 24 deletions quark_cookie/Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion quark_cookie/README.md

This file was deleted.

Loading

0 comments on commit f519000

Please sign in to comment.