feat 订阅洗版
This commit is contained in:
@ -195,32 +195,47 @@ class SubscribeChain(ChainBase):
|
|||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
|
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
|
||||||
continue
|
continue
|
||||||
# 查询缺失的媒体信息
|
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
|
||||||
if exist_flag:
|
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在,完成订阅')
|
|
||||||
self.subscribehelper.delete(subscribe.id)
|
|
||||||
# 发送通知
|
|
||||||
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
|
||||||
title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
|
||||||
image=mediainfo.get_message_image()))
|
|
||||||
continue
|
|
||||||
# 电视剧订阅
|
|
||||||
if meta.type == MediaType.TV:
|
|
||||||
# 使用订阅的总集数和开始集数替换no_exists
|
|
||||||
no_exists = self.__get_subscribe_no_exits(
|
|
||||||
no_exists=no_exists,
|
|
||||||
tmdb_id=mediainfo.tmdb_id,
|
|
||||||
begin_season=meta.begin_season,
|
|
||||||
total_episode=subscribe.total_episode,
|
|
||||||
start_episode=subscribe.start_episode,
|
|
||||||
|
|
||||||
)
|
# 非洗版状态
|
||||||
# 打印缺失集信息
|
if not subscribe.best_version:
|
||||||
if no_exists and no_exists.get(subscribe.tmdbid):
|
# 查询缺失的媒体信息
|
||||||
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
||||||
if no_exists_info:
|
if exist_flag:
|
||||||
logger.info(f'订阅 {mediainfo.title_year}{meta.season} 缺失集:{no_exists_info.episodes}')
|
logger.info(f'{mediainfo.title_year} 媒体库中已存在,完成订阅')
|
||||||
|
self.subscribehelper.delete(subscribe.id)
|
||||||
|
# 发送通知
|
||||||
|
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
||||||
|
title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
||||||
|
image=mediainfo.get_message_image()))
|
||||||
|
continue
|
||||||
|
# 电视剧订阅
|
||||||
|
if meta.type == MediaType.TV:
|
||||||
|
# 使用订阅的总集数和开始集数替换no_exists
|
||||||
|
no_exists = self.__get_subscribe_no_exits(
|
||||||
|
no_exists=no_exists,
|
||||||
|
tmdb_id=mediainfo.tmdb_id,
|
||||||
|
begin_season=meta.begin_season,
|
||||||
|
total_episode=subscribe.total_episode,
|
||||||
|
start_episode=subscribe.start_episode,
|
||||||
|
|
||||||
|
)
|
||||||
|
# 打印缺失集信息
|
||||||
|
if no_exists and no_exists.get(subscribe.tmdbid):
|
||||||
|
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
||||||
|
if no_exists_info:
|
||||||
|
logger.info(f'订阅 {mediainfo.title_year}{meta.season} 缺失集:{no_exists_info.episodes}')
|
||||||
|
else:
|
||||||
|
# 洗版状态
|
||||||
|
if meta.type == MediaType.TV:
|
||||||
|
no_exists = {
|
||||||
|
subscribe.season: NotExistMediaInfo(
|
||||||
|
season=subscribe.season,
|
||||||
|
episodes=[],
|
||||||
|
total_episodes=subscribe.total_episode,
|
||||||
|
start_episode=subscribe.start_episode or 1)
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
no_exists = {}
|
||||||
# 站点范围
|
# 站点范围
|
||||||
if subscribe.sites:
|
if subscribe.sites:
|
||||||
sites = json.loads(subscribe.sites)
|
sites = json.loads(subscribe.sites)
|
||||||
@ -233,8 +248,9 @@ class SubscribeChain(ChainBase):
|
|||||||
sites=sites)
|
sites=sites)
|
||||||
if not contexts:
|
if not contexts:
|
||||||
logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源')
|
logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源')
|
||||||
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
if meta.type == MediaType.TV:
|
||||||
self.__upate_lack_episodes(lefts=no_exists, subscribe=subscribe, mediainfo=mediainfo)
|
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
||||||
|
self.__upate_lack_episodes(lefts=no_exists, subscribe=subscribe, mediainfo=mediainfo)
|
||||||
continue
|
continue
|
||||||
# 过滤
|
# 过滤
|
||||||
matched_contexts = []
|
matched_contexts = []
|
||||||
@ -252,39 +268,47 @@ class SubscribeChain(ChainBase):
|
|||||||
if re.search(r"%s" % subscribe.exclude,
|
if re.search(r"%s" % subscribe.exclude,
|
||||||
f"{torrent_info.title} {torrent_info.description}", re.I):
|
f"{torrent_info.title} {torrent_info.description}", re.I):
|
||||||
continue
|
continue
|
||||||
# 如果是电视剧过滤掉已经下载的集数
|
# 非洗版
|
||||||
if torrent_mediainfo.type == MediaType.TV:
|
if not subscribe.best_version:
|
||||||
if self.__check_subscribe_note(subscribe, torrent_meta.episode_list):
|
# 如果是电视剧过滤掉已经下载的集数
|
||||||
logger.info(f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 已下载过')
|
if torrent_mediainfo.type == MediaType.TV:
|
||||||
continue
|
if self.__check_subscribe_note(subscribe, torrent_meta.episode_list):
|
||||||
|
logger.info(f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 已下载过')
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
# 洗版时,非整季不要
|
||||||
|
if torrent_mediainfo.type == MediaType.TV:
|
||||||
|
if torrent_meta.episode_list:
|
||||||
|
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季')
|
||||||
|
continue
|
||||||
matched_contexts.append(context)
|
matched_contexts.append(context)
|
||||||
if not matched_contexts:
|
if not matched_contexts:
|
||||||
logger.warn(f'订阅 {subscribe.name} 没有符合过滤条件的资源')
|
logger.warn(f'订阅 {subscribe.name} 没有符合过滤条件的资源')
|
||||||
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
# 非洗版未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
||||||
self.__upate_lack_episodes(lefts=no_exists, subscribe=subscribe, mediainfo=mediainfo)
|
if meta.type == MediaType.TV and not subscribe.best_version:
|
||||||
|
self.__upate_lack_episodes(lefts=no_exists, subscribe=subscribe, mediainfo=mediainfo)
|
||||||
continue
|
continue
|
||||||
# 自动下载
|
# 自动下载
|
||||||
downloads, lefts = self.downloadchain.batch_download(contexts=matched_contexts,
|
downloads, lefts = self.downloadchain.batch_download(contexts=matched_contexts,
|
||||||
no_exists=no_exists)
|
no_exists=no_exists)
|
||||||
# 更新已经下载的集数
|
# 更新已经下载的集数
|
||||||
if downloads:
|
if downloads \
|
||||||
self.__update_subscribe_note(subscribe, downloads)
|
and meta.type == MediaType.TV \
|
||||||
|
and not subscribe.best_version:
|
||||||
|
self.__update_subscribe_note(subscribe=subscribe, downloads=downloads)
|
||||||
|
|
||||||
if downloads and not lefts:
|
if downloads and not lefts:
|
||||||
# 全部下载完成
|
# 判断是否应完成订阅
|
||||||
logger.info(f'{mediainfo.title_year} 下载完成,完成订阅')
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta,
|
||||||
self.subscribehelper.delete(subscribe.id)
|
mediainfo=mediainfo, downloads=downloads)
|
||||||
# 发送通知
|
|
||||||
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
|
||||||
title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
|
||||||
image=mediainfo.get_message_image()))
|
|
||||||
else:
|
else:
|
||||||
# 未完成下载
|
# 未完成下载
|
||||||
logger.info(f'{mediainfo.title_year} 未下载未完整,继续订阅 ...')
|
logger.info(f'{mediainfo.title_year} 未下载未完整,继续订阅 ...')
|
||||||
# 更新订阅剩余集数和时间
|
if meta.type == MediaType.TV and not subscribe.best_version:
|
||||||
update_date = True if downloads else False
|
# 更新订阅剩余集数和时间
|
||||||
self.__upate_lack_episodes(lefts=lefts, subscribe=subscribe,
|
update_date = True if downloads else False
|
||||||
mediainfo=mediainfo, update_date=update_date)
|
self.__upate_lack_episodes(lefts=lefts, subscribe=subscribe,
|
||||||
|
mediainfo=mediainfo, update_date=update_date)
|
||||||
# 手动触发时发送系统消息
|
# 手动触发时发送系统消息
|
||||||
if manual:
|
if manual:
|
||||||
if sid:
|
if sid:
|
||||||
@ -292,6 +316,36 @@ class SubscribeChain(ChainBase):
|
|||||||
else:
|
else:
|
||||||
self.message.put(f'所有订阅搜索完成!')
|
self.message.put(f'所有订阅搜索完成!')
|
||||||
|
|
||||||
|
def finish_subscribe_or_not(self, subscribe: Subscribe, meta: MetaInfo,
|
||||||
|
mediainfo: MediaInfo, downloads: List[Context]):
|
||||||
|
"""
|
||||||
|
判断是否应完成订阅
|
||||||
|
"""
|
||||||
|
if not subscribe.best_version:
|
||||||
|
# 全部下载完成
|
||||||
|
logger.info(f'{mediainfo.title_year} 下载完成,完成订阅')
|
||||||
|
self.subscribehelper.delete(subscribe.id)
|
||||||
|
# 发送通知
|
||||||
|
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
||||||
|
title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
||||||
|
image=mediainfo.get_message_image()))
|
||||||
|
else:
|
||||||
|
# 当前下载资源的优先级
|
||||||
|
priority = max([item.torrent_info.pri_order for item in downloads])
|
||||||
|
if priority == 100:
|
||||||
|
logger.info(f'{mediainfo.title_year} 洗版完成,删除订阅')
|
||||||
|
self.subscribehelper.delete(subscribe.id)
|
||||||
|
# 发送通知
|
||||||
|
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
||||||
|
title=f'{mediainfo.title_year}{meta.season} 已洗版完成',
|
||||||
|
image=mediainfo.get_message_image()))
|
||||||
|
else:
|
||||||
|
# 正在洗版,更新资源优先级
|
||||||
|
logger.info(f'{mediainfo.title_year} 正在洗版,更新资源优先级')
|
||||||
|
self.subscribehelper.update(subscribe.id, {
|
||||||
|
"current_priority": priority
|
||||||
|
})
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
"""
|
"""
|
||||||
刷新站点最新资源
|
刷新站点最新资源
|
||||||
@ -397,22 +451,36 @@ class SubscribeChain(ChainBase):
|
|||||||
title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
||||||
image=mediainfo.get_message_image()))
|
image=mediainfo.get_message_image()))
|
||||||
continue
|
continue
|
||||||
# 电视剧订阅
|
# 非洗版
|
||||||
if meta.type == MediaType.TV:
|
if not subscribe.best_version:
|
||||||
# 使用订阅的总集数和开始集数替换no_exists
|
# 电视剧订阅
|
||||||
no_exists = self.__get_subscribe_no_exits(
|
if meta.type == MediaType.TV:
|
||||||
no_exists=no_exists,
|
# 使用订阅的总集数和开始集数替换no_exists
|
||||||
tmdb_id=mediainfo.tmdb_id,
|
no_exists = self.__get_subscribe_no_exits(
|
||||||
begin_season=meta.begin_season,
|
no_exists=no_exists,
|
||||||
total_episode=subscribe.total_episode,
|
tmdb_id=mediainfo.tmdb_id,
|
||||||
start_episode=subscribe.start_episode,
|
begin_season=meta.begin_season,
|
||||||
|
total_episode=subscribe.total_episode,
|
||||||
|
start_episode=subscribe.start_episode,
|
||||||
|
|
||||||
)
|
)
|
||||||
# 打印缺失集信息
|
# 打印缺失集信息
|
||||||
if no_exists and no_exists.get(subscribe.tmdbid):
|
if no_exists and no_exists.get(subscribe.tmdbid):
|
||||||
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
||||||
if no_exists_info:
|
if no_exists_info:
|
||||||
logger.info(f'订阅 {mediainfo.title_year}{meta.season} 缺失集:{no_exists_info.episodes}')
|
logger.info(f'订阅 {mediainfo.title_year}{meta.season} 缺失集:{no_exists_info.episodes}')
|
||||||
|
else:
|
||||||
|
# 洗版
|
||||||
|
if meta.type == MediaType.TV:
|
||||||
|
no_exists = {
|
||||||
|
subscribe.season: NotExistMediaInfo(
|
||||||
|
season=subscribe.season,
|
||||||
|
episodes=[],
|
||||||
|
total_episodes=subscribe.total_episode,
|
||||||
|
start_episode=subscribe.start_episode or 1)
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
no_exists = {}
|
||||||
# 遍历缓存种子
|
# 遍历缓存种子
|
||||||
_match_context = []
|
_match_context = []
|
||||||
for domain, contexts in torrents_cache.items():
|
for domain, contexts in torrents_cache.items():
|
||||||
@ -444,19 +512,32 @@ class SubscribeChain(ChainBase):
|
|||||||
elif meta.begin_season != 1:
|
elif meta.begin_season != 1:
|
||||||
logger.info(f'{torrent_info.title} 季不匹配')
|
logger.info(f'{torrent_info.title} 季不匹配')
|
||||||
continue
|
continue
|
||||||
# 不是缺失的剧集不要
|
# 非洗版
|
||||||
if no_exists and no_exists.get(subscribe.tmdbid):
|
if not subscribe.best_version:
|
||||||
# 缺失集
|
# 不是缺失的剧集不要
|
||||||
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
if no_exists and no_exists.get(subscribe.tmdbid):
|
||||||
if no_exists_info:
|
# 缺失集
|
||||||
# 是否有交集
|
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
||||||
if not set(no_exists_info.episodes).intersection(set(torrent_meta.episode_list)):
|
if no_exists_info:
|
||||||
logger.info(f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 未包含缺失的剧集')
|
# 是否有交集
|
||||||
|
if no_exists_info.episodes and \
|
||||||
|
torrent_meta.episode_list and \
|
||||||
|
not set(no_exists_info.episodes).intersection(
|
||||||
|
set(torrent_meta.episode_list)
|
||||||
|
):
|
||||||
|
logger.info(
|
||||||
|
f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 未包含缺失的剧集')
|
||||||
|
continue
|
||||||
|
# 过滤掉已经下载的集数
|
||||||
|
if self.__check_subscribe_note(subscribe, torrent_meta.episode_list):
|
||||||
|
logger.info(f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 已下载过')
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
# 洗版时,非整季不要
|
||||||
|
if meta.type == MediaType.TV:
|
||||||
|
if torrent_meta.episode_list:
|
||||||
|
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季')
|
||||||
continue
|
continue
|
||||||
# 过滤掉已经下载的集数
|
|
||||||
if self.__check_subscribe_note(subscribe, torrent_meta.episode_list):
|
|
||||||
logger.info(f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 已下载过')
|
|
||||||
continue
|
|
||||||
# 包含
|
# 包含
|
||||||
if subscribe.include:
|
if subscribe.include:
|
||||||
if not re.search(r"%s" % subscribe.include,
|
if not re.search(r"%s" % subscribe.include,
|
||||||
@ -476,25 +557,23 @@ class SubscribeChain(ChainBase):
|
|||||||
# 批量择优下载
|
# 批量择优下载
|
||||||
downloads, lefts = self.downloadchain.batch_download(contexts=_match_context, no_exists=no_exists)
|
downloads, lefts = self.downloadchain.batch_download(contexts=_match_context, no_exists=no_exists)
|
||||||
# 更新已经下载的集数
|
# 更新已经下载的集数
|
||||||
if downloads:
|
if downloads and meta.type == MediaType.TV:
|
||||||
self.__update_subscribe_note(subscribe, downloads)
|
self.__update_subscribe_note(subscribe=subscribe, downloads=downloads)
|
||||||
|
|
||||||
if downloads and not lefts:
|
if downloads and not lefts:
|
||||||
# 全部下载完成
|
# 判断是否要完成订阅
|
||||||
logger.info(f'{mediainfo.title_year} 下载完成,完成订阅')
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta,
|
||||||
self.subscribehelper.delete(subscribe.id)
|
mediainfo=mediainfo, downloads=downloads)
|
||||||
# 发送通知
|
|
||||||
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
|
||||||
title=f'{mediainfo.title_year}{meta.season} 已完成订阅',
|
|
||||||
image=mediainfo.get_message_image()))
|
|
||||||
else:
|
else:
|
||||||
update_date = True if downloads else False
|
if meta.type == MediaType.TV and not subscribe.best_version:
|
||||||
# 未完成下载,计算剩余集数
|
update_date = True if downloads else False
|
||||||
self.__upate_lack_episodes(lefts=lefts, subscribe=subscribe,
|
# 未完成下载,计算剩余集数
|
||||||
mediainfo=mediainfo, update_date=update_date)
|
self.__upate_lack_episodes(lefts=lefts, subscribe=subscribe,
|
||||||
|
mediainfo=mediainfo, update_date=update_date)
|
||||||
else:
|
else:
|
||||||
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
if meta.type == MediaType.TV:
|
||||||
self.__upate_lack_episodes(lefts=no_exists, subscribe=subscribe, mediainfo=mediainfo)
|
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
||||||
|
self.__upate_lack_episodes(lefts=no_exists, subscribe=subscribe, mediainfo=mediainfo)
|
||||||
|
|
||||||
def __update_subscribe_note(self, subscribe: Subscribe, downloads: List[Context]):
|
def __update_subscribe_note(self, subscribe: Subscribe, downloads: List[Context]):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user