feat 订阅洗版

This commit is contained in:
jxxghp
2023-07-27 17:24:27 +08:00
parent 6b9140827f
commit 85b5117545

View File

@ -195,6 +195,9 @@ 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
# 非洗版状态
if not subscribe.best_version:
# 查询缺失的媒体信息 # 查询缺失的媒体信息
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo) exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
if exist_flag: if exist_flag:
@ -221,6 +224,18 @@ class SubscribeChain(ChainBase):
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 = {}
# 站点范围 # 站点范围
if subscribe.sites: if subscribe.sites:
sites = json.loads(subscribe.sites) sites = json.loads(subscribe.sites)
@ -233,6 +248,7 @@ 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
@ -252,35 +268,43 @@ 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 not subscribe.best_version:
# 如果是电视剧过滤掉已经下载的集数 # 如果是电视剧过滤掉已经下载的集数
if torrent_mediainfo.type == MediaType.TV: if torrent_mediainfo.type == MediaType.TV:
if self.__check_subscribe_note(subscribe, torrent_meta.episode_list): if self.__check_subscribe_note(subscribe, torrent_meta.episode_list):
logger.info(f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 已下载过') logger.info(f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 已下载过')
continue 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} 没有符合过滤条件的资源')
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数 # 非洗版未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
if meta.type == MediaType.TV and not subscribe.best_version:
self.__upate_lack_episodes(lefts=no_exists, subscribe=subscribe, mediainfo=mediainfo) 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 update_date = True if downloads else False
self.__upate_lack_episodes(lefts=lefts, subscribe=subscribe, self.__upate_lack_episodes(lefts=lefts, subscribe=subscribe,
@ -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,6 +451,8 @@ 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 not subscribe.best_version:
# 电视剧订阅 # 电视剧订阅
if meta.type == MediaType.TV: if meta.type == MediaType.TV:
# 使用订阅的总集数和开始集数替换no_exists # 使用订阅的总集数和开始集数替换no_exists
@ -413,6 +469,18 @@ class SubscribeChain(ChainBase):
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 not subscribe.best_version:
# 不是缺失的剧集不要 # 不是缺失的剧集不要
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:
# 是否有交集 # 是否有交集
if not set(no_exists_info.episodes).intersection(set(torrent_meta.episode_list)): if no_exists_info.episodes and \
logger.info(f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 未包含缺失的剧集') 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 continue
# 过滤掉已经下载的集数 # 过滤掉已经下载的集数
if self.__check_subscribe_note(subscribe, torrent_meta.episode_list): if self.__check_subscribe_note(subscribe, torrent_meta.episode_list):
logger.info(f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 已下载过') logger.info(f'{torrent_info.title} 对应剧集 {torrent_meta.episodes} 已下载过')
continue continue
else:
# 洗版时,非整季不要
if meta.type == MediaType.TV:
if torrent_meta.episode_list:
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季')
continue
# 包含 # 包含
if subscribe.include: if subscribe.include:
if not re.search(r"%s" % subscribe.include, if not re.search(r"%s" % subscribe.include,
@ -476,23 +557,21 @@ 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:
if meta.type == MediaType.TV and not subscribe.best_version:
update_date = True if downloads else False update_date = True if downloads else False
# 未完成下载,计算剩余集数 # 未完成下载,计算剩余集数
self.__upate_lack_episodes(lefts=lefts, subscribe=subscribe, self.__upate_lack_episodes(lefts=lefts, subscribe=subscribe,
mediainfo=mediainfo, update_date=update_date) 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)