From 2c5189e4d053566e42d7d2cfdf17bc830aea64e6 Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Thu, 25 Aug 2022 16:49:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=9C=E7=A8=8B=E8=BD=BD?= =?UTF-8?q?=E5=85=A5=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 4 ++-- pycms.json | 6 +++--- utils/parser.py | 13 +++++++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index c8bdd48..458d0a5 100644 --- a/app.py +++ b/app.py @@ -45,13 +45,14 @@ def index(): # put application's code here @app.route('/vod') def vod(): rule = getParmas('rule') + ext = getParmas('ext') if not rule: return jsonify(error.failed('规则字段必填')) if not rule in rule_list: msg = f'仅支持以下规则:{",".join(rule_list)}' return jsonify(error.failed(msg)) - js_path = f'js/{rule}.js' + js_path = f'js/{rule}.js' if not ext.startswith('http') else ext ctx,js_code = parser.runJs(js_path) rule = ctx.eval('rule') cms = CMS(rule) @@ -63,7 +64,6 @@ def vod(): filter = getParmas('filter') t = getParmas('t') pg = getParmas('pg') - ext = getParmas('ext') ids = getParmas('ids') q = getParmas('q') diff --git a/pycms.json b/pycms.json index 48336e3..5f5df27 100644 --- a/pycms.json +++ b/pycms.json @@ -2,7 +2,7 @@ "key":"dr_yanaifei", "name":"鸭奈飞", "type":1, - "api":"http://192.168.10.99:9000/vod?rule=鸭奈飞", + "api":"http://192.168.10.99:9000/vod?rule=鸭奈飞&ext=https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/鸭奈飞.js", "searchable": 1, "quickSearch": 1, "filterable": 1 @@ -11,7 +11,7 @@ "key":"dr_lmys", "name":"蓝莓影视", "type":1, - "api":"http://192.168.10.99:9000/vod?rule=蓝莓影视", + "api":"http://192.168.10.99:9000/vod?rule=蓝莓影视&ext=https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/蓝莓影视.js", "searchable": 0, "quickSearch": 0, "filterable": 1 @@ -20,7 +20,7 @@ "key":"dr_555", "name":"555影视", "type":1, - "api":"http://192.168.10.99:9000/vod?rule=555影视", + "api":"http://192.168.10.99:9000/vod?rule=555影视&ext=https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/555影视.js", "searchable": 1, "quickSearch": 1, "filterable": 1 diff --git a/utils/parser.py b/utils/parser.py index 286dca1..b47f174 100644 --- a/utils/parser.py +++ b/utils/parser.py @@ -5,6 +5,8 @@ # Date : 2022/8/25 import os + +import requests from flask import make_response,jsonify from functools import partial # 这玩意儿能锁定一个函数的参数 import subprocess @@ -19,10 +21,13 @@ def runJs(jsPath): # base_path = os.path.dirname(os.path.abspath(__file__)) # 当前文件所在目录 # base_path = os.path.dirname(os.getcwd()) # 当前主程序所在工作目录 # base_path = os.path.dirname(os.path.abspath('.')) # 上级目录 - base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录 - js_path = os.path.join(base_path, jsPath) - with open(js_path, 'r', encoding='UTF-8') as fp: - js_code = fp.read() + if str(jsPath).startswith('http'): + jscode = requests.get(jsPath).text + else: + base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录 + js_path = os.path.join(base_path, jsPath) + with open(js_path, 'r', encoding='UTF-8') as fp: + js_code = fp.read() # print(js_code) loader = execjs.compile(js_code) return loader,js_code -- GitLab