Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
更新bd影视
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdhnx committed Jan 11, 2024
1 parent 96e85ae commit ee2bdb7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 deletions.
6 changes: 3 additions & 3 deletions base/custom.conf
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@
"key":"hipy_t4_哔滴影视",
"name":"哔滴影视(hipy_t4)",
"type":4,
"api":"http://192.168.31.49:5707/api/v1/vod/哔滴影视",
"api":"http://192.168.31.49:5707/api/v1/vod/哔滴影视?api_ext={{host}}/txt/hipy/bdys.jar",
"searchable":1,
"quickSearch":0,
"filterable":1,
"ext":""
"ext":"{{host}}/txt/hipy/bdys.jar"
},
{
"key": "hipy_t3_哔滴影视",
Expand All @@ -117,7 +117,7 @@
"searchable": 1,
"quickSearch": 0,
"filterable": 1,
"ext": ""
"ext": "{{host}}/txt/hipy/bdys.jar"
},
{"key":"Test_jsapi","name":"Test_jsapi(drpy)","type":3,"api":"{{host}}/libs/drpy2.min.js","searchable":2,"quickSearch":0,"filterable":0,"ext":"{{host}}/js/jsapi.js","jar":"{{host}}/libs/jar/custom_jsapi.jar"},

Expand Down
2 changes: 1 addition & 1 deletion js/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.49beta22
3.9.49beta23
Binary file added txt/hipy/bdys.jar
Binary file not shown.
90 changes: 52 additions & 38 deletions txt/hipy/哔滴影视.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
except ImportError:
from t4.base.spider import BaseSpider

import json
from pathlib import Path
import base64
from cachetools import cached, TTLCache # 可以缓存curd的函数,指定里面的key

"""
配置示例:
Expand Down Expand Up @@ -46,6 +46,16 @@
"""


def envkey(self, url: str):
return url


# 全局变量
gParam = {
"inited": False,
}


class Spider(BaseSpider): # 元类 默认的元类 type

api: str = 'https://www.bdys03.com/api/v1'
Expand All @@ -58,58 +68,60 @@ def getDependence(self):
def getName(self):
return "哔滴影视"

@cached(cache=TTLCache(maxsize=3, ttl=3600), key=envkey)
def get_init_api(self, url):
try:
print('get_init_api请求URL:', url)
r = self.fetch(url)
ret = None
if r.status_code == 200:
self.log(f'url:{url},文件体积:{len(r.content)}')
ret = r.content
return ret
except Exception as e:
print(f'get_init_api请求URL发生错误:{e}')
return {}

def init_api_ext_file(self):
"""
这个函数用于初始化py文件对应的json文件,用于存筛选规则。
执行此函数会自动生成筛选文件
@return:
"""
ext_file = __file__.replace('.py', '.json')
print(f'ext_file:{ext_file}')
ext_file_dict = {
"分类1": [{"key": "letter", "name": "首字母", "value": [{"n": "A", "v": "A"}, {"n": "B", "v": "B"}]}],
"分类2": [{"key": "letter", "name": "首字母", "value": [{"n": "A", "v": "A"}, {"n": "B", "v": "B"}]},
{"key": "year", "name": "年份",
"value": [{"n": "2024", "v": "2024"}, {"n": "2023", "v": "2023"}]}],
}
with open(ext_file, mode='w+', encoding='utf-8') as f:
f.write(json.dumps(ext_file_dict, ensure_ascii=False))
pass

def init(self, extend=""):
"""
初始化加载extend,一般与py文件名同名的json文件作为扩展筛选
@param extend:
@return:
"""

def init_file(ext_file):
"""
根据与py对应的json文件去扩展规则的筛选条件
"""
ext_file = Path(ext_file).as_posix()
if os.path.exists(ext_file):
with open(ext_file, mode='r', encoding='utf-8') as f:
try:
ext_dict = json.loads(f.read())
self.config['filter'].update(ext_dict)
except Exception as e:
print(f'更新扩展筛选条件发生错误:{e}')

global gParam
ext = self.extend
print(f"============{extend}============")

if isinstance(ext, str) and ext:
if ext.startswith('./'):
ext_file = os.path.join(os.path.dirname(__file__), ext)
init_file(ext_file)
elif ext.startswith('http'):
try:
r = self.fetch(ext)
self.config['filter'].update(r.json())
except Exception as e:
print(f'更新扩展筛选条件发生错误:{e}')
elif not ext.startswith('./') and not ext.startswith('http'):
ext_file = os.path.join(os.path.dirname(__file__), './' + ext + '.json')
init_file(ext_file)
if ext.endswith('.jar'):
jar_path = os.path.join(os.path.dirname(__file__), './jars')
os.makedirs(jar_path, exist_ok=True)
jar_file = os.path.join(os.path.dirname(__file__), './jars/bdys.jar')
jar_file = Path(jar_file).as_posix()
need_down = False
msg = ''
if not gParam['inited'] and not os.path.exists(jar_file):
need_down = True
msg = f'未inited,且文件不存在。开始下载文件'
elif gParam['inited'] and not os.path.exists(jar_file):
need_down = True
msg = f'已inited,但文件不存在。开始下载文件'
# elif not gParam['inited'] and os.path.exists(jar_file):
# need_down = True
# msg = f'未inited,但文件已存在。重新下载文件'

if need_down:
self.log(msg)
content = self.get_init_api(ext)
with open(jar_file, mode='wb+') as f:
f.write(content)

# 装载模块,这里只要一个就够了
if isinstance(extend, list):
Expand All @@ -126,6 +138,8 @@ def init_file(ext_file):
self.token = str(self.class1.getToken())
self.headers.update({'token': self.token})

gParam['inited'] = True

def isVideoFormat(self, url):
pass

Expand Down

0 comments on commit ee2bdb7

Please sign in to comment.