fix dboper
This commit is contained in:
@ -6,8 +6,8 @@ from lxml import etree
|
||||
|
||||
from app.chain import ChainBase
|
||||
from app.core.config import settings
|
||||
from app.db.siteicons import SiteIcons
|
||||
from app.db.sites import Sites
|
||||
from app.db.siteicon_oper import SiteIconOper
|
||||
from app.db.site_oper import SiteOper
|
||||
from app.helper.cookiecloud import CookieCloudHelper
|
||||
from app.helper.sites import SitesHelper
|
||||
from app.log import logger
|
||||
@ -21,8 +21,8 @@ class CookieCloudChain(ChainBase):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.sites = Sites()
|
||||
self.siteicons = SiteIcons()
|
||||
self.siteoper = SiteOper()
|
||||
self.siteiconoper = SiteIconOper()
|
||||
self.siteshelper = SitesHelper()
|
||||
self.cookiecloud = CookieCloudHelper(
|
||||
server=settings.COOKIECLOUD_HOST,
|
||||
@ -45,16 +45,16 @@ class CookieCloudChain(ChainBase):
|
||||
for domain, cookie in cookies.items():
|
||||
# 获取站点信息
|
||||
indexer = self.siteshelper.get_indexer(domain)
|
||||
if self.sites.exists(domain):
|
||||
if self.siteoper.exists(domain):
|
||||
# 更新站点Cookie
|
||||
self.sites.update_cookie(domain=domain, cookies=cookie)
|
||||
self.siteoper.update_cookie(domain=domain, cookies=cookie)
|
||||
_update_count += 1
|
||||
elif indexer:
|
||||
# 新增站点
|
||||
self.sites.add(name=indexer.get("name"),
|
||||
url=indexer.get("domain"),
|
||||
domain=domain,
|
||||
cookie=cookie)
|
||||
self.siteoper.add(name=indexer.get("name"),
|
||||
url=indexer.get("domain"),
|
||||
domain=domain,
|
||||
cookie=cookie)
|
||||
_add_count += 1
|
||||
# 保存站点图标
|
||||
if indexer:
|
||||
@ -62,10 +62,10 @@ class CookieCloudChain(ChainBase):
|
||||
cookie=cookie,
|
||||
ua=settings.USER_AGENT)
|
||||
if icon_url:
|
||||
self.siteicons.update_icon(name=indexer.get("name"),
|
||||
domain=domain,
|
||||
icon_url=icon_url,
|
||||
icon_base64=icon_base64)
|
||||
self.siteiconoper.update_icon(name=indexer.get("name"),
|
||||
domain=domain,
|
||||
icon_url=icon_url,
|
||||
icon_base64=icon_base64)
|
||||
# 处理完成
|
||||
ret_msg = f"更新了{_update_count}个站点,新增了{_add_count}个站点"
|
||||
logger.info(f"CookieCloud同步成功:{ret_msg}")
|
||||
|
@ -1,5 +1,5 @@
|
||||
from app.chain import ChainBase
|
||||
from app.db.sites import Sites
|
||||
from app.db.site_oper import SiteOper
|
||||
|
||||
|
||||
class SiteManageChain(ChainBase):
|
||||
@ -7,17 +7,17 @@ class SiteManageChain(ChainBase):
|
||||
站点远程管理处理链
|
||||
"""
|
||||
|
||||
_sites: Sites = None
|
||||
_sites: SiteOper = None
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._sites = Sites()
|
||||
self._siteoper = SiteOper()
|
||||
|
||||
def process(self):
|
||||
"""
|
||||
查询所有站点,发送消息
|
||||
"""
|
||||
site_list = self._sites.list()
|
||||
site_list = self._siteoper.list()
|
||||
if not site_list:
|
||||
self.post_message(title="没有维护任何站点信息!")
|
||||
title = f"共有 {len(site_list)} 个站点,回复 `/site_disable` `[id]` 禁用站点,回复 `/site_enable` `[id]` 启用站点:"
|
||||
@ -44,12 +44,12 @@ class SiteManageChain(ChainBase):
|
||||
if not arg_str.isdigit():
|
||||
return
|
||||
site_id = int(arg_str)
|
||||
site = self._sites.get(site_id)
|
||||
site = self._siteoper.get(site_id)
|
||||
if not site:
|
||||
self.post_message(title=f"站点编号 {site_id} 不存在!")
|
||||
return
|
||||
# 禁用站点
|
||||
self._sites.update(site_id, {
|
||||
self._siteoper.update(site_id, {
|
||||
"is_active": False
|
||||
})
|
||||
# 重新发送消息
|
||||
@ -65,12 +65,12 @@ class SiteManageChain(ChainBase):
|
||||
if not arg_str.isdigit():
|
||||
return
|
||||
site_id = int(arg_str)
|
||||
site = self._sites.get(site_id)
|
||||
site = self._siteoper.get(site_id)
|
||||
if not site:
|
||||
self.post_message(title=f"站点编号 {site_id} 不存在!")
|
||||
return
|
||||
# 禁用站点
|
||||
self._sites.update(site_id, {
|
||||
self._siteoper.update(site_id, {
|
||||
"is_active": True
|
||||
})
|
||||
# 重新发送消息
|
||||
|
@ -6,7 +6,7 @@ from app.chain.search import SearchChain
|
||||
from app.core.metainfo import MetaInfo
|
||||
from app.core.context import TorrentInfo, Context, MediaInfo
|
||||
from app.core.config import settings
|
||||
from app.db.subscribes import Subscribes
|
||||
from app.db.subscribe_oper import SubscribeOper
|
||||
from app.helper.sites import SitesHelper
|
||||
from app.log import logger
|
||||
from app.schemas.context import NotExistMediaInfo
|
||||
@ -26,7 +26,7 @@ class SubscribeChain(ChainBase):
|
||||
super().__init__()
|
||||
self.downloadchain = DownloadChain()
|
||||
self.searchchain = SearchChain()
|
||||
self.subscribes = Subscribes()
|
||||
self.subscribehelper = SubscribeOper()
|
||||
self.siteshelper = SitesHelper()
|
||||
|
||||
def process(self, title: str, year: str,
|
||||
@ -89,7 +89,7 @@ class SubscribeChain(ChainBase):
|
||||
'lack_episode': kwargs.get('total_episode')
|
||||
})
|
||||
# 添加订阅
|
||||
sid, err_msg = self.subscribes.add(mediainfo, season=season, **kwargs)
|
||||
sid, err_msg = self.subscribehelper.add(mediainfo, season=season, **kwargs)
|
||||
if not sid:
|
||||
logger.error(f'{mediainfo.title_year} {err_msg}')
|
||||
# 发回原用户
|
||||
@ -115,15 +115,15 @@ class SubscribeChain(ChainBase):
|
||||
:return: 更新订阅状态为R或删除订阅
|
||||
"""
|
||||
if sid:
|
||||
subscribes = [self.subscribes.get(sid)]
|
||||
subscribes = [self.subscribehelper.get(sid)]
|
||||
else:
|
||||
subscribes = self.subscribes.list(state)
|
||||
subscribes = self.subscribehelper.list(state)
|
||||
# 遍历订阅
|
||||
for subscribe in subscribes:
|
||||
logger.info(f'开始搜索订阅,标题:{subscribe.name} ...')
|
||||
# 如果状态为N则更新为R
|
||||
if subscribe.state == 'N':
|
||||
self.subscribes.update(subscribe.id, {'state': 'R'})
|
||||
self.subscribehelper.update(subscribe.id, {'state': 'R'})
|
||||
# 生成元数据
|
||||
meta = MetaInfo(subscribe.name)
|
||||
meta.year = subscribe.year
|
||||
@ -138,7 +138,7 @@ class SubscribeChain(ChainBase):
|
||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
||||
if exist_flag:
|
||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在,完成订阅')
|
||||
self.subscribes.delete(subscribe.id)
|
||||
self.subscribehelper.delete(subscribe.id)
|
||||
# 发送通知
|
||||
self.post_message(title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
||||
image=mediainfo.get_message_image())
|
||||
@ -165,7 +165,7 @@ class SubscribeChain(ChainBase):
|
||||
if downloads and not lefts:
|
||||
# 全部下载完成
|
||||
logger.info(f'{mediainfo.title_year} 下载完成,完成订阅')
|
||||
self.subscribes.delete(subscribe.id)
|
||||
self.subscribehelper.delete(subscribe.id)
|
||||
# 发送通知
|
||||
self.post_message(title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
||||
image=mediainfo.get_message_image())
|
||||
@ -224,7 +224,7 @@ class SubscribeChain(ChainBase):
|
||||
从缓存中匹配订阅,并自动下载
|
||||
"""
|
||||
# 所有订阅
|
||||
subscribes = self.subscribes.list('R')
|
||||
subscribes = self.subscribehelper.list('R')
|
||||
# 遍历订阅
|
||||
for subscribe in subscribes:
|
||||
logger.info(f'开始匹配订阅,标题:{subscribe.name} ...')
|
||||
@ -242,7 +242,7 @@ class SubscribeChain(ChainBase):
|
||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
||||
if exist_flag:
|
||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在,完成订阅')
|
||||
self.subscribes.delete(subscribe.id)
|
||||
self.subscribehelper.delete(subscribe.id)
|
||||
# 发送通知
|
||||
self.post_message(title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
||||
image=mediainfo.get_message_image())
|
||||
@ -278,7 +278,7 @@ class SubscribeChain(ChainBase):
|
||||
if downloads and not lefts:
|
||||
# 全部下载完成
|
||||
logger.info(f'{mediainfo.title_year} 下载完成,完成订阅')
|
||||
self.subscribes.delete(subscribe.id)
|
||||
self.subscribehelper.delete(subscribe.id)
|
||||
# 发送通知
|
||||
self.post_message(title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
||||
image=mediainfo.get_message_image())
|
||||
@ -291,7 +291,7 @@ class SubscribeChain(ChainBase):
|
||||
left_episodes = season_info.get('episodes')
|
||||
logger.info(f'{mediainfo.title_year} 季 {season} 未下载完整,'
|
||||
f'更新缺失集数为{len(left_episodes)} ...')
|
||||
self.subscribes.update(subscribe.id, {
|
||||
self.subscribehelper.update(subscribe.id, {
|
||||
"lack_episode": len(left_episodes)
|
||||
})
|
||||
|
||||
@ -299,7 +299,7 @@ class SubscribeChain(ChainBase):
|
||||
"""
|
||||
查询订阅并发送消息
|
||||
"""
|
||||
subscribes = self.subscribes.list()
|
||||
subscribes = self.subscribehelper.list()
|
||||
if not subscribes:
|
||||
self.post_message(title='没有任何订阅!')
|
||||
return
|
||||
@ -328,12 +328,12 @@ class SubscribeChain(ChainBase):
|
||||
if not arg_str.isdigit():
|
||||
return
|
||||
subscribe_id = int(arg_str)
|
||||
subscribe = self.subscribes.get(subscribe_id)
|
||||
subscribe = self.subscribehelper.get(subscribe_id)
|
||||
if not subscribe:
|
||||
self.post_message(title=f"订阅编号 {subscribe_id} 不存在!")
|
||||
return
|
||||
# 删除订阅
|
||||
self.subscribes.delete(subscribe_id)
|
||||
self.subscribehelper.delete(subscribe_id)
|
||||
# 重新发送消息
|
||||
self.list()
|
||||
|
||||
|
Reference in New Issue
Block a user