feat: 针对海外用户进行的少量优化

This commit is contained in:
helloplhm-qwq 2023-11-17 23:25:37 +08:00
parent 1ef6675a5f
commit 33a7e8e8b6
No known key found for this signature in database
GPG Key ID: B7542212855B2C26
4 changed files with 22 additions and 4 deletions

View File

@ -22,6 +22,7 @@ import time
import pickle import pickle
from . import config from . import config
from . import utils from . import utils
from . import variable
def is_valid_utf8(text): def is_valid_utf8(text):
# 判断是否为有效的utf-8字符串 # 判断是否为有效的utf-8字符串
@ -90,6 +91,9 @@ def request(url, options = {}):
except: except:
options['headers'] = {} options['headers'] = {}
options['headers']['User-Agent'] = random.choice(ua_list) options['headers']['User-Agent'] = random.choice(ua_list)
# 检查是否在国内
if ((not variable.iscn) and (not options["headers"].get("X-Forwarded-For"))):
options["headers"]["X-Forwarded-For"] = variable.fakeip
# 获取请求主函数 # 获取请求主函数
try: try:
reqattr = getattr(requests, method.lower()) reqattr = getattr(requests, method.lower())
@ -197,3 +201,12 @@ async def asyncrequest(url, options={}):
return req return req
""" """
def checkcn():
req = request("https://mips.kugou.com/check/iscn?&format=json")
body = utils.jsobject(req.json())
variable.iscn = bool(body.flag)
if (not variable.iscn):
variable.fakeip = "1.0.2.114"
logger.info("您在非中国大陆服务器上启动了项目已自动开启ip伪装")
logger.warning("此方式无法解决咪咕音乐的链接获取问题,您可以配置代理,服务器地址可在下方链接中找到\nhttps://hidemy.io/cn/proxy-list/?country=CN#list")

View File

@ -134,3 +134,4 @@ class jsobject(dict):
return None return None
add_to_global_namespace('require', require) add_to_global_namespace('require', require)

View File

@ -11,9 +11,11 @@
import os import os
debug_mode = True debug_mode = False
log_length_limit = 400 log_length_limit = 400
running = True running = True
config = {} config = {}
workdir = os.getcwd() workdir = os.getcwd()
banList_suggest = 0 banList_suggest = 0
iscn = True
fake_ip = None

View File

@ -27,7 +27,9 @@ logger = log.log("main")
from common import utils from common import utils
from common import lxsecurity from common import lxsecurity
from common import Httpx
from apis import SongURL from apis import SongURL
Httpx.checkcn()
@app.route('/') @app.route('/')
def index(): def index():