fix douban plugin
This commit is contained in:
parent
0f6674ec16
commit
9793c6e0a2
@ -21,8 +21,15 @@ class PluginDataOper(DbOper):
|
|||||||
"""
|
"""
|
||||||
if ObjectUtils.is_obj(value):
|
if ObjectUtils.is_obj(value):
|
||||||
value = json.dumps(value)
|
value = json.dumps(value)
|
||||||
plugin = PluginData(plugin_id=plugin_id, key=key, value=value)
|
plugin = PluginData.get_plugin_data_by_key(self._db, plugin_id, key)
|
||||||
return plugin.create(self._db)
|
if plugin:
|
||||||
|
plugin.update(self._db, {
|
||||||
|
"value": value
|
||||||
|
})
|
||||||
|
return plugin
|
||||||
|
else:
|
||||||
|
plugin = PluginData(plugin_id=plugin_id, key=key, value=value)
|
||||||
|
return plugin.create(self._db)
|
||||||
|
|
||||||
def get_data(self, plugin_id: str, key: str) -> Any:
|
def get_data(self, plugin_id: str, key: str) -> Any:
|
||||||
"""
|
"""
|
||||||
|
@ -83,7 +83,7 @@ class TNodeSpider:
|
|||||||
results = res.json().get('data', {}).get("torrents") or []
|
results = res.json().get('data', {}).get("torrents") or []
|
||||||
for result in results:
|
for result in results:
|
||||||
torrent = {
|
torrent = {
|
||||||
'indexer': self._indexerid,
|
'id': self._indexerid,
|
||||||
'title': result.get('title'),
|
'title': result.get('title'),
|
||||||
'description': result.get('subtitle'),
|
'description': result.get('subtitle'),
|
||||||
'enclosure': self._downloadurl % (self._domain, result.get('id')),
|
'enclosure': self._downloadurl % (self._domain, result.get('id')),
|
||||||
|
@ -239,8 +239,8 @@ class DoubanSync(_PluginBase):
|
|||||||
拼装插件详情页面,需要返回页面配置,同时附带数据
|
拼装插件详情页面,需要返回页面配置,同时附带数据
|
||||||
"""
|
"""
|
||||||
# 查询同步详情
|
# 查询同步详情
|
||||||
history = self.get_data('history')
|
historys = self.get_data('history')
|
||||||
if not history:
|
if not historys:
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'component': 'div',
|
'component': 'div',
|
||||||
@ -250,8 +250,80 @@ class DoubanSync(_PluginBase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
return [
|
# 拼装页面
|
||||||
|
contents = []
|
||||||
|
for history in historys:
|
||||||
|
title = history.get("title")
|
||||||
|
poster = history.get("poster")
|
||||||
|
mtype = history.get("type")
|
||||||
|
time_str = history.get("time")
|
||||||
|
overview = history.get("overview")
|
||||||
|
contents.append(
|
||||||
|
{
|
||||||
|
'component': 'VCard',
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'div',
|
||||||
|
'props': {
|
||||||
|
'class': 'd-flex justify-space-start flex-nowrap flex-row',
|
||||||
|
},
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'div',
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VImg',
|
||||||
|
'props': {
|
||||||
|
'src': poster,
|
||||||
|
'height': 120,
|
||||||
|
'width': 80,
|
||||||
|
'aspect-ratio': '2/3',
|
||||||
|
'class': 'object-cover rounded shadow ring-gray-500',
|
||||||
|
'cover': True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'component': 'div',
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VCardSubtitle',
|
||||||
|
'props': {
|
||||||
|
'class': 'pa-2 font-bold break-words whitespace-break-spaces'
|
||||||
|
},
|
||||||
|
'text': title
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'component': 'VCardText',
|
||||||
|
'props': {
|
||||||
|
'class': 'pa-0 px-2'
|
||||||
|
},
|
||||||
|
'text': f'类型:{mtype}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'component': 'VCardText',
|
||||||
|
'props': {
|
||||||
|
'class': 'pa-0 px-2'
|
||||||
|
},
|
||||||
|
'text': f'时间:{time_str}'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
'component': 'div',
|
||||||
|
'props': {
|
||||||
|
'class': 'grid gap-3 grid-info-card',
|
||||||
|
},
|
||||||
|
'content': contents
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
def stop_service(self):
|
def stop_service(self):
|
||||||
@ -289,89 +361,92 @@ class DoubanSync(_PluginBase):
|
|||||||
return
|
return
|
||||||
# 解析数据
|
# 解析数据
|
||||||
for result in results:
|
for result in results:
|
||||||
dtype = result.get("title", "")[:2]
|
try:
|
||||||
title = result.get("title", "")[2:]
|
dtype = result.get("title", "")[:2]
|
||||||
if dtype not in ["想看"]:
|
title = result.get("title", "")[2:]
|
||||||
continue
|
if dtype not in ["想看"]:
|
||||||
if not result.get("link"):
|
|
||||||
continue
|
|
||||||
# 判断是否在天数范围
|
|
||||||
pubdate: Optional[datetime.datetime] = result.get("pubdate")
|
|
||||||
if pubdate:
|
|
||||||
if (datetime.datetime.now() - pubdate).days > self._days:
|
|
||||||
logger.info(f'已超过同步天数,标题:{title},发布时间:{pubdate}')
|
|
||||||
continue
|
continue
|
||||||
douban_id = result.get("link", "").split("/")[-2]
|
if not result.get("link"):
|
||||||
# 检查缓存
|
continue
|
||||||
if not douban_id or douban_id in caches:
|
# 判断是否在天数范围
|
||||||
continue
|
pubdate: Optional[datetime.datetime] = result.get("pubdate")
|
||||||
# 根据豆瓣ID获取豆瓣数据
|
if pubdate:
|
||||||
doubaninfo: Optional[dict] = self.chain.douban_info(doubanid=douban_id)
|
if (datetime.datetime.now(datetime.timezone.utc) - pubdate).days > float(self._days):
|
||||||
if not doubaninfo:
|
logger.info(f'已超过同步天数,标题:{title},发布时间:{pubdate}')
|
||||||
logger.warn(f'未获取到豆瓣信息,标题:{title},豆瓣ID:{douban_id}')
|
continue
|
||||||
continue
|
douban_id = result.get("link", "").split("/")[-2]
|
||||||
logger.info(f'获取到豆瓣信息,标题:{title},豆瓣ID:{douban_id}')
|
# 检查缓存
|
||||||
# 识别媒体信息
|
if not douban_id or douban_id in caches:
|
||||||
meta = MetaInfo(doubaninfo.get("original_title") or doubaninfo.get("title"))
|
continue
|
||||||
if doubaninfo.get("year"):
|
# 根据豆瓣ID获取豆瓣数据
|
||||||
meta.year = doubaninfo.get("year")
|
doubaninfo: Optional[dict] = self.chain.douban_info(doubanid=douban_id)
|
||||||
mediainfo: MediaInfo = self.chain.recognize_media(meta=meta)
|
if not doubaninfo:
|
||||||
if not mediainfo:
|
logger.warn(f'未获取到豆瓣信息,标题:{title},豆瓣ID:{douban_id}')
|
||||||
logger.warn(f'未识别到媒体信息,标题:{title},豆瓣ID:{douban_id}')
|
continue
|
||||||
continue
|
logger.info(f'获取到豆瓣信息,标题:{title},豆瓣ID:{douban_id}')
|
||||||
# 加入缓存
|
# 识别媒体信息
|
||||||
caches.append(douban_id)
|
meta = MetaInfo(doubaninfo.get("original_title") or doubaninfo.get("title"))
|
||||||
# 查询缺失的媒体信息
|
if doubaninfo.get("year"):
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
meta.year = doubaninfo.get("year")
|
||||||
if exist_flag:
|
mediainfo: MediaInfo = self.chain.recognize_media(meta=meta)
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
if not mediainfo:
|
||||||
continue
|
logger.warn(f'未识别到媒体信息,标题:{title},豆瓣ID:{douban_id}')
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中不存在,开始搜索 ...')
|
continue
|
||||||
# 搜索
|
# 加入缓存
|
||||||
contexts = self.searchchain.process(mediainfo=mediainfo,
|
caches.append(douban_id)
|
||||||
no_exists=no_exists)
|
# 查询缺失的媒体信息
|
||||||
if not contexts:
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
||||||
logger.warn(f'{mediainfo.title_year} 未搜索到资源')
|
if exist_flag:
|
||||||
# 添加订阅
|
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
||||||
self.subscribechain.add(title=mediainfo.title,
|
continue
|
||||||
year=mediainfo.year,
|
logger.info(f'{mediainfo.title_year} 媒体库中不存在,开始搜索 ...')
|
||||||
mtype=mediainfo.type,
|
# 搜索
|
||||||
tmdbid=mediainfo.tmdb_id,
|
contexts = self.searchchain.process(mediainfo=mediainfo,
|
||||||
season=meta.begin_season,
|
no_exists=no_exists)
|
||||||
exist_ok=True,
|
if not contexts:
|
||||||
username="豆瓣想看")
|
logger.warn(f'{mediainfo.title_year} 未搜索到资源')
|
||||||
|
# 添加订阅
|
||||||
|
self.subscribechain.add(title=mediainfo.title,
|
||||||
|
year=mediainfo.year,
|
||||||
|
mtype=mediainfo.type,
|
||||||
|
tmdbid=mediainfo.tmdb_id,
|
||||||
|
season=meta.begin_season,
|
||||||
|
exist_ok=True,
|
||||||
|
username="豆瓣想看")
|
||||||
|
action = "subscribe"
|
||||||
|
else:
|
||||||
|
# 自动下载
|
||||||
|
downloads, lefts = self.downloadchain.batch_download(contexts=contexts, no_exists=no_exists)
|
||||||
|
if downloads and not lefts:
|
||||||
|
# 全部下载完成
|
||||||
|
logger.info(f'{mediainfo.title_year} 下载完成')
|
||||||
|
action = "download"
|
||||||
|
else:
|
||||||
|
# 未完成下载
|
||||||
|
logger.info(f'{mediainfo.title_year} 未下载未完整,添加订阅 ...')
|
||||||
|
# 添加订阅
|
||||||
|
self.subscribechain.add(title=mediainfo.title,
|
||||||
|
year=mediainfo.year,
|
||||||
|
mtype=mediainfo.type,
|
||||||
|
tmdbid=mediainfo.tmdb_id,
|
||||||
|
season=meta.begin_season,
|
||||||
|
exist_ok=True,
|
||||||
|
username="豆瓣想看")
|
||||||
|
action = "subscribe"
|
||||||
|
# 存储历史记录
|
||||||
history.append({
|
history.append({
|
||||||
"action": 'subscribe',
|
"action": action,
|
||||||
"media": mediainfo.to_dict(),
|
"title": doubaninfo.get("title") or mediainfo.title,
|
||||||
"time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
"type": mediainfo.type.value,
|
||||||
})
|
"year": mediainfo.year,
|
||||||
continue
|
"poster": mediainfo.poster_path,
|
||||||
# 自动下载
|
"overview": mediainfo.overview,
|
||||||
downloads, lefts = self.downloadchain.batch_download(contexts=contexts, no_exists=no_exists)
|
"tmdbid": mediainfo.tmdb_id,
|
||||||
if downloads and not lefts:
|
"doubanid": douban_id,
|
||||||
# 全部下载完成
|
|
||||||
logger.info(f'{mediainfo.title_year} 下载完成')
|
|
||||||
history.append({
|
|
||||||
"action": 'download',
|
|
||||||
"media": mediainfo.to_dict(),
|
|
||||||
"time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
# 未完成下载
|
|
||||||
logger.info(f'{mediainfo.title_year} 未下载未完整,添加订阅 ...')
|
|
||||||
# 添加订阅
|
|
||||||
self.subscribechain.add(title=mediainfo.title,
|
|
||||||
year=mediainfo.year,
|
|
||||||
mtype=mediainfo.type,
|
|
||||||
tmdbid=mediainfo.tmdb_id,
|
|
||||||
season=meta.begin_season,
|
|
||||||
exist_ok=True,
|
|
||||||
username="豆瓣想看")
|
|
||||||
history.append({
|
|
||||||
"action": 'subscribe',
|
|
||||||
"media": mediainfo.to_dict(),
|
|
||||||
"time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
"time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
})
|
})
|
||||||
|
except Exception as err:
|
||||||
|
logger.error(f'同步用户 {user_id} 豆瓣想看数据出错:{err}')
|
||||||
logger.info(f"用户 {user_id} 豆瓣想看同步完成")
|
logger.info(f"用户 {user_id} 豆瓣想看同步完成")
|
||||||
# 保存历史记录
|
# 保存历史记录
|
||||||
self.save_data('history', history)
|
self.save_data('history', history)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user