diff --git a/base/custom.conf b/base/custom.conf new file mode 100644 index 0000000000000000000000000000000000000000..de90780bb2924570fd11902e969a4718c1985a00 --- /dev/null +++ b/base/custom.conf @@ -0,0 +1,18 @@ +# 这是一个自定义的额外用户爬虫配置 +# 自动附加到config/mode 对应的在线源里 +# 可以使用Python的 # 单行注释 + +{ + "sites":[ + { + "key":"t4", + "name":"T4", + "type":4, + "api":"https://t4.secan.icu/vod?sites=all&ali_token=xxxxxxxxx&timeout=10", +# "api":"http://[ip]:[port]/vod?sites=all&ali_token=3xx9cfxxxx509bxx&timeout=5", + "searchable":1, + "quickSearch":1, + "filterable":0 + } + ] +} \ No newline at end of file diff --git a/controllers/home.py b/controllers/home.py index 3ed6e58916ea4dc38af4841471b73478a2060921..708b35690f2daf66abe782f9a543622779e3fc6d 100644 --- a/controllers/home.py +++ b/controllers/home.py @@ -10,7 +10,7 @@ from flask import Blueprint,abort,render_template,url_for,redirect,make_response from controllers.service import storage_service from controllers.classes import getClasses,getClassInfo from utils.web import getParmas -from utils.files import getPics +from utils.files import getPics,custom_merge from js.rules import getRules from base.R import R from utils.system import cfg,getHost,is_linux @@ -18,6 +18,7 @@ from utils import parser from utils.log import logger from utils.files import getAlist,get_live_url from utils.update import getLocalVer +from utils.encode import parseText from js.rules import getJxs import random @@ -125,6 +126,17 @@ def get_liveslib(): @home.route('/config/') def config_render(mode): # print(dict(app.config)) + customFile = 'base/custom.conf' + if not os.path.exists(customFile): + with open(customFile,'w+',encoding='utf-8') as f: + f.write('{}') + customConfig = False + try: + with open(customFile,'r',encoding='utf-8') as f: + customConfig = parseText(f.read()) + except Exception as e: + logger.info(f'用户自定义配置加载失败:{e}') + if mode == 1: jyw_ip = getHost(mode) logger.info(jyw_ip) @@ -136,7 +148,11 @@ def config_render(mode): live_url = get_live_url(new_conf,mode) # html = render_template('config.txt',rules=getRules('js'),host=host,mode=mode,jxs=jxs,base64Encode=base64Encode,config=new_conf) html = render_template('config.txt',rules=getRules('js'),host=host,mode=mode,jxs=jxs,alists=alists,alists_str=alists_str,live_url=live_url,config=new_conf) - response = make_response(html) + merged_config = custom_merge(parseText(html),customConfig) + # print(merged_config) + # response = make_response(html) + response = make_response(json.dumps(merged_config,ensure_ascii=False,indent=1)) + # response = make_response(str(merged_config)) response.headers['Content-Type'] = 'application/json; charset=utf-8' return response diff --git a/js/version.txt b/js/version.txt index 132d9f7707dbb148709d0dd5d269bb4e25987024..df4bdc7e53c41178aecb0c2823d6e17da8bdd6f3 100644 --- a/js/version.txt +++ b/js/version.txt @@ -1 +1 @@ -3.2.8 \ No newline at end of file +3.2.9 \ No newline at end of file diff --git a/readme.md b/readme.md index 5ef03ba388537295ddb27cda8f1015ebcea6aac2..b1f57d02971c539f213919adca8252a265c7d167 100644 --- a/readme.md +++ b/readme.md @@ -46,6 +46,8 @@ [dockerfile教程](https://blog.csdn.net/qq_46158060/article/details/125718218) [获取本地设备信息](https://blog.csdn.net/cui_yonghua/article/details/125508991) [获取本地设备信息](https://m.jb51.net/article/140716.htm) +###### 2022/09/08 +- [X] 1.升级到3.2.9,支持自动合并自定义用户配置(内置t4测试源) ###### 2022/09/07 - [X] 1.优化后台管理登录界面,升级更新脚本 - [X] 2.增加了镜像合并脚本(三合一直接拉 hjdhnx/drpy 即可) diff --git a/utils/encode.py b/utils/encode.py index 1fef0c86fd46258c9fae9cd9b98f84c8336a670d..40137e982469d2031f706fc9e1bca8d0c6c828f0 100644 --- a/utils/encode.py +++ b/utils/encode.py @@ -17,6 +17,7 @@ import requests.utils from time import sleep import os from utils.web import UC_UA,PC_UA +from ast import literal_eval def getPreJs(): base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目 @@ -222,4 +223,8 @@ def buildUrl(url,obj=None): url += '&' url = (url + prs).replace('"','').replace("'",'') # print(url) - return url \ No newline at end of file + return url + +def parseText(text:str): + text = text.replace('false','False').replace('true','True').replace('null','None') + return literal_eval(text) \ No newline at end of file diff --git a/utils/files.py b/utils/files.py index a027bf576d95b070273d53677cea564eb1c3e4e3..2c19967e0e08f8c2f2ed255589bf4ad1802dc27c 100644 --- a/utils/files.py +++ b/utils/files.py @@ -51,4 +51,29 @@ def getAlist(): }) alists.append(obj) print(f'共计{len(alists)}条alist记录') - return alists \ No newline at end of file + return alists + +def custom_merge(original:dict,custom:dict): + """ + 合并用户配置 + :param original: 原始配置 + :param custom: 自定义配置 + :return: + """ + if not custom or len(custom.keys()) < 1: + return original + new_keys = custom.keys() + updateObj = {} + extend_obj = {} + for key in ['wallpaper','spider','homepage']: + if key in new_keys: + updateObj[key] = custom[key] + + for key in ['drives','sites','flags','lives','ads']: + if key in new_keys: + extend_obj[key] = custom[key] + + original.update(updateObj) + for key in extend_obj.keys(): + original[key].extend(extend_obj[key]) + return original \ No newline at end of file