6 次代码提交 2002df68f6 ... b9bd01791e

作者 SHA1 备注 提交日期
  hjdhnx b9bd01791e 新增源 2 月之前
  hjdhnx 947b151aa1 更新为摘要算法储存extend 2 月之前
  hjdhnx 5b61f7aad2 1 2 月之前
  hjdhnx cd40858907 更新t4源储存机制。支持分发扩展 2 月之前
  hjdhnx 84e3fa3e4d Merge remote-tracking branch 'origin/master' 2 月之前
  hjdhnx 4b13f10827 1 2 月之前
共有 4 个文件被更改,包括 78 次插入13 次删除
  1. 2 1
      README.md
  2. 36 11
      app/apps/vod/vod_views.py
  3. 39 0
      app/t4/files/drpy_js/闪雷电.js
  4. 1 1
      app/t4/qjs_drpy/qjs_drpy_test.py

+ 2 - 1
README.md

@@ -30,7 +30,8 @@ bash -c "$(curl -fsSLk https://zy.catni.cn/release/latest/setup.sh)"
 [ws,jinja](https://www.jianshu.com/p/ca9b257a1a44)  
 [cachetools文档](https://cachetools.readthedocs.io/en/stable/#cachetools.Cache)  
 [alembic参考文档](https://zhuanlan.zhihu.com/p/306898869?utm_id=0)
-[playwright参考文档](https://playwright.dev/python/docs/api/class-playwright)
+[playwright参考文档](https://playwright.dev/python/docs/api/class-playwright)  
+[zyplayer参考](https://wwi.lanzoup.com/iPbFb23bpdaf)
 
 
 

+ 36 - 11
app/apps/vod/vod_views.py

@@ -26,6 +26,7 @@ from common import deps
 from core.logger import logger
 from core.constants import BASE_DIR
 from utils.path import get_api_path, get_file_text, get_file_modified_time, get_now
+from utils.tools import get_md5
 from dateutil.relativedelta import relativedelta
 from pathlib import Path
 import sys
@@ -38,6 +39,8 @@ api_url = ''
 API_STORE = {
 
 }
+# 扩展储存同api分发不同ext扩展的上限。超过这个上限清空储存
+API_DICT_LIMIT = 5
 
 
 # u: Users = Depends(deps.user_perm([f"{access_name}:get"]))
@@ -86,6 +89,10 @@ def vod_generate(*, api: str = "", request: Request,
     # 如果传了nocache就会清除缓存
     nocache = getParams('nocache')
 
+    api_ext = getParams('api_ext')  # t4初始化api的扩展参数
+    extend = getParams('extend')  # t4初始化配置里的ext参数
+    extend = extend or api_ext
+
     # 判断head请求但不是本地代理直接干掉
     # if req_method == 'head' and (t4_api + '&') not in whole_url:
     if req_method == 'head' and not is_proxy:
@@ -111,29 +118,51 @@ def vod_generate(*, api: str = "", request: Request,
         del API_STORE[api]
 
     try:
+        extend_store = get_md5(extend) if extend else extend
         api_path = get_api_path(api)
         api_time = get_file_modified_time(api_path)
         api_store_lists = list(API_STORE.keys())
         if api not in api_store_lists:
             # 没初始化过,需要初始化
             need_init = True
+            # 设为空字典
+            API_STORE[api] = {}
         else:
-            _api = API_STORE[api] or {'time': None}
-            _api_time = _api['time']
-            # 内存储存时间 < 文件修改时间 需要重新初始化
-            if not _api_time or _api_time < api_time or (_api_time + relativedelta(seconds=_seconds) < get_now()):
+            _api_dict = API_STORE[api] or {}
+            _apis = _api_dict.keys()
+            # 超过字典扩展分发储存限制自动清空并且要求重新初始化
+            if len(_apis) > API_DICT_LIMIT:
+                logger.info(f'源路径:{api_path}疑似被恶意加载扩展,超过扩展分发数量{API_DICT_LIMIT},现在清空储存器')
+                # 初始化过,但是扩展数量超过上限。防止恶意无限刷扩展,删了
                 need_init = True
+                del API_STORE[api]
+                # 设为空字典
+                API_STORE[api] = {}
+            else:
+                # 防止储存类型不是字典
+                if not isinstance(API_STORE[api], dict):
+                    # 设为空字典
+                    API_STORE[api] = {}
+
+                # _api = API_STORE[api] or {'time': None}
+                # 取拓展里的
+                _api = API_STORE[api].get(extend_store) or {'time': None}
+                _api_time = _api['time']
+                # 内存储存时间 < 文件修改时间 需要重新初始化
+                if not _api_time or _api_time < api_time or (_api_time + relativedelta(seconds=_seconds) < get_now()):
+                    need_init = True
 
         if need_init:
-            logger.info(f'需要初始化源:源路径:{api_path},源最后修改时间:{api_time}')
+            logger.info(f'需要初始化源:源路径:{api_path},扩展:{extend_store},源最后修改时间:{api_time}')
             if is_drpy:
                 vod = Drpy(api, t4_js_api, debug)
             else:
                 vod = Vod(api=api, query_params=request.query_params, t4_api=t4_api).module
             # 记录初始化时间|下次文件修改后判断储存的时间 < 文件修改时间又会重新初始化
-            API_STORE[api] = {'vod': vod, 'time': get_now()}
+            # API_STORE[api] = {'vod': vod, 'time': get_now()}
+            API_STORE[api][extend_store] = {'vod': vod, 'time': get_now()}
         else:
-            vod = API_STORE[api]['vod']
+            vod = API_STORE[api][extend_store]['vod']
 
     except Exception as e:
         return respErrorJson(error_code.ERROR_INTERNAL.set_msg(f"内部服务器错误:{e}"))
@@ -142,8 +171,6 @@ def vod_generate(*, api: str = "", request: Request,
     ids = getParams('ids')
     filters = getParams('f')  # t1 筛选 {'cid':'1'}
     ext = getParams('ext')  # t4筛选传入base64加密的json字符串
-    api_ext = getParams('api_ext')  # t4初始化api的扩展参数
-    extend = getParams('extend')  # t4初始化配置里的ext参数
     filterable = getParams('filter')  # t4能否筛选
     if req_method == 'post':  # t4 ext网络数据太长会自动post,此时强制可筛选
         filterable = True
@@ -161,8 +188,6 @@ def vod_generate(*, api: str = "", request: Request,
     ad_headers = getParams('headers')
     ad_name = getParams('name') or 'm3u8'
 
-    extend = extend or api_ext
-
     if is_drpy:
         vod.setDebug(debug)
 

+ 39 - 0
app/t4/files/drpy_js/闪雷电.js

@@ -0,0 +1,39 @@
+var rule = {
+    title: '闪雷电',
+    编码: 'gb2312',
+    host: 'http://120.224.7.90:808',
+    url: '/www/List.asp?classid=fyclass&searchword=&page=fypage',
+    filterable: 0,//是否启用分类筛选,
+    class_name: '电影&电视剧&综艺&动漫&音乐',
+    class_url: '5000&10&8&6&12',
+    searchUrl: '/www/List.asp?classid=30&searchword=**&page=fypage',
+    searchable: 2,
+    quickSearch: 0,
+    headers: {
+        'User-Agent': 'MOBILE_UA',
+    },
+    play_parse: true,
+    lazy: $js.toString(() => {
+        var html = 'http://120.224.7.90:808/PlayMov.asp?ClassId=' + input.split(",")[2] + '&video=2&exe=0&down=0&movNo=' + input.split(",")[3] + '&vgver=undefined&ClientIP=120.224.7.90'
+        var url = request(html).match(/push\('(.*?)'/)[1]
+        input = {
+            jx: 0,
+            url: url,
+            parse: 0
+        };
+    }),
+    limit: 6,
+    推荐: 'ul:eq(4)&&strong;img&&alt;img&&src;span:eq(1)&&Text;a&&href',
+    一级: 'ul:eq(5)&&strong;img&&alt;img&&src;span:eq(1)&&Text;a&&href',
+    二级: {
+        title: "ul:eq(2)&&li:eq(0)&&Text",
+        img: "img:eq(1)&&src",
+        desc: "ul:eq(2)&&li:eq(1)&&Text;ul:eq(2)&&li:eq(2)&&Text;ul:eq(2)&&li:eq(3)&&Text",
+        content: "body&&div:has(p)&&p:eq(3)&&Text",
+        tabs: "",
+        lists: 'body&&a[onclick^="senfe"]',
+        list_url: 'a&&onclick',
+        list_text: 'a&&Text'
+    },
+    搜索: '*',
+}

+ 1 - 1
app/t4/qjs_drpy/qjs_drpy_test.py

@@ -72,7 +72,7 @@ if __name__ == '__main__':
     # print(drpy.playerContent("优质", "https://yzzy.play-cdn21.com/20240329/13829_b63e7c01/index.m3u8", []))
     # print(drpy.searchContent("斗罗大陆", False, 1))
     # print(drpy.searchContent("玫瑰的故事", False, 1))
-    # print(drpy.searchContent("完美世界", False, 1))
+    # print(drpy.searchContent("鬼吹灯", False, 1))
     # print(drpy.detailContent("https://001.pm/index
     # print(drpy.detailContent("https://001.pm/index.php/vod/detail/id/118802.html"))
     # print(drpy.detailContent("https://www.1080.ee/voddetail/124404.html"))