提交 2c5189e4 编写于 作者: H hjdhnx

支持远程载入规则

上级 8b55047d
......@@ -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')
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册