From 33a7e8e8b69ea0790566594dc7b8f079add7ee5d Mon Sep 17 00:00:00 2001 From: helloplhm-qwq Date: Fri, 17 Nov 2023 23:25:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=92=88=E5=AF=B9=E6=B5=B7=E5=A4=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BF=9B=E8=A1=8C=E7=9A=84=E5=B0=91=E9=87=8F?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/Httpx.py | 15 ++++++++++++++- common/utils.py | 3 ++- common/variable.py | 6 ++++-- main.py | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/common/Httpx.py b/common/Httpx.py index 7b82f00..08d2501 100644 --- a/common/Httpx.py +++ b/common/Httpx.py @@ -22,6 +22,7 @@ import time import pickle from . import config from . import utils +from . import variable def is_valid_utf8(text): # 判断是否为有效的utf-8字符串 @@ -90,6 +91,9 @@ def request(url, options = {}): except: options['headers'] = {} 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: reqattr = getattr(requests, method.lower()) @@ -196,4 +200,13 @@ async def asyncrequest(url, options={}): # Return the response return req -""" \ No newline at end of file +""" + +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") diff --git a/common/utils.py b/common/utils.py index e803ef9..f83e8ee 100644 --- a/common/utils.py +++ b/common/utils.py @@ -133,4 +133,5 @@ class jsobject(dict): def __getattr__(self, UNUSED): return None -add_to_global_namespace('require', require) \ No newline at end of file +add_to_global_namespace('require', require) + diff --git a/common/variable.py b/common/variable.py index 65dc0ec..acedf77 100644 --- a/common/variable.py +++ b/common/variable.py @@ -11,9 +11,11 @@ import os -debug_mode = True +debug_mode = False log_length_limit = 400 running = True config = {} workdir = os.getcwd() -banList_suggest = 0 \ No newline at end of file +banList_suggest = 0 +iscn = True +fake_ip = None \ No newline at end of file diff --git a/main.py b/main.py index ea3321e..b42f8ac 100644 --- a/main.py +++ b/main.py @@ -27,7 +27,9 @@ logger = log.log("main") from common import utils from common import lxsecurity +from common import Httpx from apis import SongURL +Httpx.checkcn() @app.route('/') def index():