add 订阅管理命令
This commit is contained in:
@ -203,7 +203,7 @@ async def arr_movies(apikey: str, db: Session = Depends(get_db)) -> Any:
|
||||
result = []
|
||||
subscribes = Subscribe.list(db)
|
||||
for subscribe in subscribes:
|
||||
if subscribe.type != "电影":
|
||||
if subscribe.type != MediaType.MOVIE.value:
|
||||
continue
|
||||
result.append(RadarrMovie(
|
||||
id=subscribe.id,
|
||||
@ -465,7 +465,7 @@ async def arr_series(apikey: str, db: Session = Depends(get_db)) -> Any:
|
||||
result = []
|
||||
subscribes = Subscribe.list(db)
|
||||
for subscribe in subscribes:
|
||||
if subscribe.type != "电视剧":
|
||||
if subscribe.type != MediaType.TV.value:
|
||||
continue
|
||||
result.append(SonarrSeries(
|
||||
id=subscribe.id,
|
||||
|
@ -87,7 +87,7 @@ class DoubanSyncChain(ChainBase):
|
||||
logger.warn(f'{mediainfo.title_year} 未搜索到资源')
|
||||
continue
|
||||
# 自动下载
|
||||
downloads, lefts = self.downloadchain.batch_download(contexts=contexts, need_tvs=no_exists)
|
||||
downloads, lefts = self.downloadchain.batch_download(contexts=contexts, no_exists=no_exists)
|
||||
if downloads and not lefts:
|
||||
# 全部下载完成
|
||||
logger.info(f'{mediainfo.title_year} 下载完成')
|
||||
|
@ -5,7 +5,6 @@ from typing import List, Optional, Tuple, Set, Dict
|
||||
from app.chain import ChainBase
|
||||
from app.core.context import MediaInfo, TorrentInfo, Context
|
||||
from app.core.meta import MetaBase
|
||||
from app.core.metainfo import MetaInfo
|
||||
from app.helper.torrent import TorrentHelper
|
||||
from app.log import logger
|
||||
from app.schemas.context import ExistMediaInfo, NotExistMediaInfo
|
||||
|
@ -155,7 +155,7 @@ class SubscribeChain(ChainBase):
|
||||
logger.warn(f'{subscribe.keyword or subscribe.name} 未搜索到资源')
|
||||
continue
|
||||
# 自动下载
|
||||
downloads, lefts = self.downloadchain.batch_download(contexts=contexts, need_tvs=no_exists)
|
||||
downloads, lefts = self.downloadchain.batch_download(contexts=contexts, no_exists=no_exists)
|
||||
if downloads and not lefts:
|
||||
# 全部下载完成
|
||||
logger.info(f'{mediainfo.title_year} 下载完成,完成订阅')
|
||||
@ -268,7 +268,7 @@ class SubscribeChain(ChainBase):
|
||||
logger.info(f'{mediainfo.title_year} 匹配完成,共匹配到{len(_match_context)}个资源')
|
||||
if _match_context:
|
||||
# 批量择优下载
|
||||
downloads, lefts = self.downloadchain.batch_download(contexts=_match_context, need_tvs=no_exists)
|
||||
downloads, lefts = self.downloadchain.batch_download(contexts=_match_context, no_exists=no_exists)
|
||||
if downloads and not lefts:
|
||||
# 全部下载完成
|
||||
logger.info(f'{mediainfo.title_year} 下载完成,完成订阅')
|
||||
@ -289,6 +289,43 @@ class SubscribeChain(ChainBase):
|
||||
"lack_episode": len(left_episodes)
|
||||
})
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
查询订阅并发送消息
|
||||
"""
|
||||
subscribes = self.subscribes.list()
|
||||
if not subscribes:
|
||||
self.post_message(title='没有任何订阅!')
|
||||
return
|
||||
title = f"共有 {len(subscribes)} 个订阅,回复```/subscribe_delete [id]```删除订阅:"
|
||||
messages = []
|
||||
for subscribe in subscribes:
|
||||
if subscribe.type == MediaType.MOVIE.value:
|
||||
messages.append(f"{subscribe.id}. {subscribe.name}({subscribe.year})")
|
||||
else:
|
||||
messages.append(f"{subscribe.id}. {subscribe.name}({subscribe.year})第{subscribe.season}季")
|
||||
# 发送列表
|
||||
self.post_message(title=title, text='\n'.join(messages))
|
||||
|
||||
def delete(self, arg_str: str):
|
||||
"""
|
||||
删除订阅
|
||||
"""
|
||||
if not arg_str:
|
||||
return
|
||||
arg_str = arg_str.strip()
|
||||
if not arg_str.isdigit():
|
||||
return
|
||||
subscribe_id = int(arg_str)
|
||||
subscribe = self.subscribes.get(subscribe_id)
|
||||
if not subscribe:
|
||||
self.post_message(title=f"订阅编号 {subscribe_id} 不存在!")
|
||||
return
|
||||
# 删除订阅
|
||||
self.subscribes.delete(subscribe_id)
|
||||
# 重新发送消息
|
||||
self.list()
|
||||
|
||||
@staticmethod
|
||||
def __get_subscribe_no_exits(no_exists: Dict[int, Dict[int, NotExistMediaInfo]],
|
||||
tmdb_id: int,
|
||||
|
@ -148,7 +148,7 @@ class UserMessageChain(ChainBase):
|
||||
return
|
||||
# 批量下载
|
||||
downloads, lefts = self.downloadchain.batch_download(contexts=cache_list,
|
||||
need_tvs=no_exists,
|
||||
no_exists=no_exists,
|
||||
userid=userid)
|
||||
if downloads and not lefts:
|
||||
# 全部下载完成
|
||||
|
@ -63,6 +63,16 @@ class Command(metaclass=Singleton):
|
||||
'state': 'R',
|
||||
}
|
||||
},
|
||||
"/subscribes": {
|
||||
"func": SubscribeChain().list,
|
||||
"description": "查询订阅",
|
||||
"data": {}
|
||||
},
|
||||
"/subscribe_delete": {
|
||||
"func": SubscribeChain().delete,
|
||||
"description": "删除订阅",
|
||||
"data": {}
|
||||
},
|
||||
"/transfer": {
|
||||
"func": TransferChain().process,
|
||||
"description": "下载文件整理",
|
||||
@ -142,14 +152,17 @@ class Command(metaclass=Singleton):
|
||||
"""
|
||||
command = self.get(cmd)
|
||||
if command:
|
||||
logger.info(f"开始执行:{command.get('description')} ...")
|
||||
cmd_data = command['data'] if command.get('data') else {}
|
||||
if cmd_data:
|
||||
command['func'](**cmd_data)
|
||||
elif data_str:
|
||||
command['func'](data_str)
|
||||
else:
|
||||
command['func']()
|
||||
try:
|
||||
logger.info(f"开始执行:{command.get('description')} ...")
|
||||
cmd_data = command['data'] if command.get('data') else {}
|
||||
if cmd_data:
|
||||
command['func'](**cmd_data)
|
||||
elif data_str:
|
||||
command['func'](data_str)
|
||||
else:
|
||||
command['func']()
|
||||
except Exception as err:
|
||||
logger.error(f"执行命令 {cmd} 出错:{str(err)}")
|
||||
|
||||
@staticmethod
|
||||
def send_plugin_event(etype: EventType, data: dict) -> None:
|
||||
|
Reference in New Issue
Block a user