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