fix douban plugin

This commit is contained in:
jxxghp 2023-07-26 14:58:46 +08:00
parent 0f6674ec16
commit 9793c6e0a2
3 changed files with 167 additions and 85 deletions

View File

@ -21,6 +21,13 @@ class PluginDataOper(DbOper):
"""
if ObjectUtils.is_obj(value):
value = json.dumps(value)
plugin = PluginData.get_plugin_data_by_key(self._db, plugin_id, key)
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)

View File

@ -83,7 +83,7 @@ class TNodeSpider:
results = res.json().get('data', {}).get("torrents") or []
for result in results:
torrent = {
'indexer': self._indexerid,
'id': self._indexerid,
'title': result.get('title'),
'description': result.get('subtitle'),
'enclosure': self._downloadurl % (self._domain, result.get('id')),

View File

@ -239,8 +239,8 @@ class DoubanSync(_PluginBase):
拼装插件详情页面需要返回页面配置同时附带数据
"""
# 查询同步详情
history = self.get_data('history')
if not history:
historys = self.get_data('history')
if not historys:
return [
{
'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):
@ -289,6 +361,7 @@ class DoubanSync(_PluginBase):
return
# 解析数据
for result in results:
try:
dtype = result.get("title", "")[:2]
title = result.get("title", "")[2:]
if dtype not in ["想看"]:
@ -298,7 +371,7 @@ class DoubanSync(_PluginBase):
# 判断是否在天数范围
pubdate: Optional[datetime.datetime] = result.get("pubdate")
if pubdate:
if (datetime.datetime.now() - pubdate).days > self._days:
if (datetime.datetime.now(datetime.timezone.utc) - pubdate).days > float(self._days):
logger.info(f'已超过同步天数,标题:{title},发布时间:{pubdate}')
continue
douban_id = result.get("link", "").split("/")[-2]
@ -340,22 +413,14 @@ class DoubanSync(_PluginBase):
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")
})
continue
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} 下载完成')
history.append({
"action": 'download',
"media": mediainfo.to_dict(),
"time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
})
action = "download"
else:
# 未完成下载
logger.info(f'{mediainfo.title_year} 未下载未完整,添加订阅 ...')
@ -367,11 +432,21 @@ class DoubanSync(_PluginBase):
season=meta.begin_season,
exist_ok=True,
username="豆瓣想看")
action = "subscribe"
# 存储历史记录
history.append({
"action": 'subscribe',
"media": mediainfo.to_dict(),
"action": action,
"title": doubaninfo.get("title") or mediainfo.title,
"type": mediainfo.type.value,
"year": mediainfo.year,
"poster": mediainfo.poster_path,
"overview": mediainfo.overview,
"tmdbid": mediainfo.tmdb_id,
"doubanid": douban_id,
"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} 豆瓣想看同步完成")
# 保存历史记录
self.save_data('history', history)