mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-08 00:46:57 +08:00
feat(subscribe): add support for update movie downloaded note
This commit is contained in:
+118
-121
@@ -288,59 +288,11 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
|
|||||||
f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid},doubanid:{subscribe.doubanid}')
|
f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid},doubanid:{subscribe.doubanid}')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 非洗版状态
|
# 如果媒体已存在或已下载完毕,跳过当前订阅处理
|
||||||
if not subscribe.best_version:
|
exist_flag, no_exists = self.check_and_handle_existing_media(subscribe=subscribe, meta=meta,
|
||||||
# 每季总集数
|
|
||||||
totals = {}
|
|
||||||
if subscribe.season and subscribe.total_episode:
|
|
||||||
totals = {
|
|
||||||
subscribe.season: subscribe.total_episode
|
|
||||||
}
|
|
||||||
# 查询媒体库缺失的媒体信息
|
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(
|
|
||||||
meta=meta,
|
|
||||||
mediainfo=mediainfo,
|
mediainfo=mediainfo,
|
||||||
totals=totals
|
mediakey=mediakey)
|
||||||
)
|
|
||||||
else:
|
|
||||||
# 洗版状态
|
|
||||||
exist_flag = False
|
|
||||||
if meta.type == MediaType.TV:
|
|
||||||
no_exists = {
|
|
||||||
mediakey: {
|
|
||||||
subscribe.season: NotExistMediaInfo(
|
|
||||||
season=subscribe.season,
|
|
||||||
episodes=[],
|
|
||||||
total_episode=subscribe.total_episode,
|
|
||||||
start_episode=subscribe.start_episode or 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
no_exists = {}
|
|
||||||
|
|
||||||
# 已存在
|
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
|
||||||
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, force=True)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# 电视剧订阅处理缺失集
|
|
||||||
if meta.type == MediaType.TV:
|
|
||||||
# 实际缺失集与订阅开始结束集范围进行整合,同时剔除已下载的集数
|
|
||||||
exist_flag, no_exists = self.__get_subscribe_no_exits(
|
|
||||||
subscribe_name=f'{subscribe.name} {meta.season}',
|
|
||||||
no_exists=no_exists,
|
|
||||||
mediakey=mediakey,
|
|
||||||
begin_season=meta.begin_season,
|
|
||||||
total_episode=subscribe.total_episode,
|
|
||||||
start_episode=subscribe.start_episode,
|
|
||||||
downloaded_episodes=self.__get_downloaded_episodes(subscribe)
|
|
||||||
)
|
|
||||||
# 已存在
|
|
||||||
if exist_flag:
|
|
||||||
logger.info(f'{mediainfo.title_year} 已全部下载')
|
|
||||||
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo,
|
|
||||||
force=True)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 站点范围
|
# 站点范围
|
||||||
@@ -466,8 +418,7 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
|
|||||||
# 是否完成订阅
|
# 是否完成订阅
|
||||||
if not subscribe.best_version:
|
if not subscribe.best_version:
|
||||||
# 订阅存在待定策略,不管是否已完成,均需更新订阅信息
|
# 订阅存在待定策略,不管是否已完成,均需更新订阅信息
|
||||||
if meta.type == MediaType.TV:
|
# 更新订阅已下载信息
|
||||||
# 电视剧更新已下载集数
|
|
||||||
self.__update_subscribe_note(subscribe=subscribe, downloads=downloads)
|
self.__update_subscribe_note(subscribe=subscribe, downloads=downloads)
|
||||||
# 更新订阅剩余集数和时间
|
# 更新订阅剩余集数和时间
|
||||||
self.__update_lack_episodes(lefts=lefts, subscribe=subscribe, mediainfo=mediainfo,
|
self.__update_lack_episodes(lefts=lefts, subscribe=subscribe, mediainfo=mediainfo,
|
||||||
@@ -586,58 +537,12 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
|
|||||||
logger.warn(
|
logger.warn(
|
||||||
f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid},doubanid:{subscribe.doubanid}')
|
f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid},doubanid:{subscribe.doubanid}')
|
||||||
continue
|
continue
|
||||||
# 非洗版
|
|
||||||
if not subscribe.best_version:
|
# 如果媒体已存在或已下载完毕,跳过当前订阅处理
|
||||||
# 每季总集数
|
exist_flag, no_exists = self.check_and_handle_existing_media(subscribe=subscribe, meta=meta,
|
||||||
totals = {}
|
|
||||||
if subscribe.season and subscribe.total_episode:
|
|
||||||
totals = {
|
|
||||||
subscribe.season: subscribe.total_episode
|
|
||||||
}
|
|
||||||
# 查询缺失的媒体信息
|
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(
|
|
||||||
meta=meta,
|
|
||||||
mediainfo=mediainfo,
|
mediainfo=mediainfo,
|
||||||
totals=totals
|
mediakey=mediakey)
|
||||||
)
|
|
||||||
else:
|
|
||||||
# 洗版
|
|
||||||
exist_flag = False
|
|
||||||
if meta.type == MediaType.TV:
|
|
||||||
no_exists = {
|
|
||||||
mediakey: {
|
|
||||||
subscribe.season: NotExistMediaInfo(
|
|
||||||
season=subscribe.season,
|
|
||||||
episodes=[],
|
|
||||||
total_episode=subscribe.total_episode,
|
|
||||||
start_episode=subscribe.start_episode or 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
no_exists = {}
|
|
||||||
|
|
||||||
# 已存在
|
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
|
||||||
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, force=True)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# 电视剧订阅
|
|
||||||
if meta.type == MediaType.TV:
|
|
||||||
# 整合实际缺失集与订阅开始集结束集,同时剔除已下载的集数
|
|
||||||
exist_flag, no_exists = self.__get_subscribe_no_exits(
|
|
||||||
subscribe_name=f'{subscribe.name} {meta.season}',
|
|
||||||
no_exists=no_exists,
|
|
||||||
mediakey=mediakey,
|
|
||||||
begin_season=meta.begin_season,
|
|
||||||
total_episode=subscribe.total_episode,
|
|
||||||
start_episode=subscribe.start_episode,
|
|
||||||
downloaded_episodes=self.__get_downloaded_episodes(subscribe)
|
|
||||||
)
|
|
||||||
# 已存在
|
|
||||||
if exist_flag:
|
|
||||||
logger.info(f'{mediainfo.title_year} 已全部下载')
|
|
||||||
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, force=True)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 遍历缓存种子
|
# 遍历缓存种子
|
||||||
@@ -874,7 +779,7 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
|
|||||||
|
|
||||||
def __update_subscribe_note(self, subscribe: Subscribe, downloads: List[Context]):
|
def __update_subscribe_note(self, subscribe: Subscribe, downloads: List[Context]):
|
||||||
"""
|
"""
|
||||||
更新已下载集数到note字段
|
更新已下载信息到note字段
|
||||||
"""
|
"""
|
||||||
# 查询现有Note
|
# 查询现有Note
|
||||||
if not downloads:
|
if not downloads:
|
||||||
@@ -885,44 +790,58 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
|
|||||||
for context in downloads:
|
for context in downloads:
|
||||||
meta = context.meta_info
|
meta = context.meta_info
|
||||||
mediainfo = context.media_info
|
mediainfo = context.media_info
|
||||||
if mediainfo.type != MediaType.TV:
|
|
||||||
continue
|
|
||||||
if subscribe.tmdbid and mediainfo.tmdb_id \
|
if subscribe.tmdbid and mediainfo.tmdb_id \
|
||||||
and mediainfo.tmdb_id != subscribe.tmdbid:
|
and mediainfo.tmdb_id != subscribe.tmdbid:
|
||||||
continue
|
continue
|
||||||
if subscribe.doubanid and mediainfo.douban_id \
|
if subscribe.doubanid and mediainfo.douban_id \
|
||||||
and mediainfo.douban_id != subscribe.doubanid:
|
and mediainfo.douban_id != subscribe.doubanid:
|
||||||
continue
|
continue
|
||||||
episodes = meta.episode_list
|
items = []
|
||||||
if not episodes:
|
if mediainfo.type == MediaType.TV:
|
||||||
|
# 电视剧有集数,使用 episode_list
|
||||||
|
items = meta.episode_list
|
||||||
|
elif mediainfo.type == MediaType.MOVIE:
|
||||||
|
# 电影只有一个条目,设置为 [1]
|
||||||
|
items = [1]
|
||||||
|
if not items:
|
||||||
continue
|
continue
|
||||||
# 合并已下载集
|
# 合并已下载的集数或电影项(去重)
|
||||||
note = list(set(note).union(set(episodes)))
|
note = list(set(note).union(set(items)))
|
||||||
# 更新订阅
|
# 更新订阅
|
||||||
|
if note:
|
||||||
self.subscribeoper.update(subscribe.id, {
|
self.subscribeoper.update(subscribe.id, {
|
||||||
"note": note
|
"note": note
|
||||||
})
|
})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_downloaded_episodes(subscribe: Subscribe) -> List[int]:
|
def __get_downloaded(subscribe: Subscribe) -> List[int]:
|
||||||
"""
|
"""
|
||||||
获取已下载过的集数
|
获取已下载过的集数或电影
|
||||||
"""
|
"""
|
||||||
if not subscribe.note:
|
note = subscribe.note or []
|
||||||
|
if not note:
|
||||||
return []
|
return []
|
||||||
if subscribe.type != MediaType.TV.value:
|
# 针对 TV 类型,返回已下载的集数
|
||||||
|
if subscribe.type == MediaType.TV.value:
|
||||||
|
logger.info(f'订阅 {subscribe.name} 第{subscribe.season}季 已下载集数:{note}')
|
||||||
|
return note
|
||||||
|
# 针对 Movie 类型,直接返回已下载的电影
|
||||||
|
if subscribe.type == MediaType.MOVIE.value:
|
||||||
|
logger.info(f'订阅 {subscribe.name} 已下载内容:{note}')
|
||||||
|
return note
|
||||||
return []
|
return []
|
||||||
episodes = subscribe.note or []
|
|
||||||
logger.info(f'订阅 {subscribe.name} 第{subscribe.season}季 已下载集数:{episodes}')
|
|
||||||
return episodes
|
|
||||||
|
|
||||||
def __update_lack_episodes(self, lefts: Dict[Union[int, str], Dict[int, NotExistMediaInfo]],
|
def __update_lack_episodes(self, lefts: Dict[Union[int, str], Dict[int, NotExistMediaInfo]],
|
||||||
subscribe: Subscribe,
|
subscribe: Subscribe,
|
||||||
mediainfo: MediaInfo,
|
mediainfo: MediaInfo,
|
||||||
update_date: bool = False):
|
update_date: bool = False):
|
||||||
"""
|
"""
|
||||||
更新订阅剩余集数
|
更新订阅剩余集数及时间
|
||||||
"""
|
"""
|
||||||
|
update_data = {}
|
||||||
|
if update_date:
|
||||||
|
update_data["last_update"] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
if subscribe.type == MediaType.TV.value:
|
||||||
if not lefts:
|
if not lefts:
|
||||||
# 如果 lefts 为空,表示没有缺失集数,直接设置 lack_episode 为 0
|
# 如果 lefts 为空,表示没有缺失集数,直接设置 lack_episode 为 0
|
||||||
lack_episode = 0
|
lack_episode = 0
|
||||||
@@ -942,10 +861,9 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
|
|||||||
lack_episode = len(left_episodes)
|
lack_episode = len(left_episodes)
|
||||||
logger.info(f"{mediainfo.title_year} 季 {season} 更新缺失集数为{lack_episode} ...")
|
logger.info(f"{mediainfo.title_year} 季 {season} 更新缺失集数为{lack_episode} ...")
|
||||||
break
|
break
|
||||||
# 更新数据库
|
|
||||||
update_data = {"lack_episode": lack_episode}
|
update_data = {"lack_episode": lack_episode}
|
||||||
if update_date:
|
# 更新数据库
|
||||||
update_data["last_update"] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
if update_data:
|
||||||
self.subscribeoper.update(subscribe.id, update_data)
|
self.subscribeoper.update(subscribe.id, update_data)
|
||||||
|
|
||||||
def __finish_subscribe(self, subscribe: Subscribe, mediainfo: MediaInfo,
|
def __finish_subscribe(self, subscribe: Subscribe, mediainfo: MediaInfo,
|
||||||
@@ -1342,6 +1260,85 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
|
|||||||
subscribe_info.episodes = episodes
|
subscribe_info.episodes = episodes
|
||||||
return subscribe_info
|
return subscribe_info
|
||||||
|
|
||||||
|
def check_and_handle_existing_media(self, subscribe: Subscribe, meta: MetaInfo,
|
||||||
|
mediainfo: MediaInfo, mediakey: str):
|
||||||
|
"""
|
||||||
|
检查媒体是否已经存在,并根据情况执行相应的操作
|
||||||
|
1. 查询缺失的媒体信息
|
||||||
|
2. 判断是否已经下载完毕
|
||||||
|
3. 根据媒体类型(电视剧或电影)执行不同的处理
|
||||||
|
|
||||||
|
:param subscribe: 订阅信息对象
|
||||||
|
:param meta: 媒体元数据
|
||||||
|
:param mediainfo: 媒体信息
|
||||||
|
:param mediakey: 媒体标识符
|
||||||
|
:return:
|
||||||
|
- exist_flag (bool): 布尔值,表示媒体是否已经完全下载或已存在
|
||||||
|
- no_exists (dict): 缺失的媒体信息,包含缺失的集数或其他相关信息
|
||||||
|
"""
|
||||||
|
# 非洗版
|
||||||
|
if not subscribe.best_version:
|
||||||
|
# 每季总集数
|
||||||
|
totals = {}
|
||||||
|
if subscribe.season and subscribe.total_episode:
|
||||||
|
totals = {
|
||||||
|
subscribe.season: subscribe.total_episode
|
||||||
|
}
|
||||||
|
# 查询媒体库缺失的媒体信息
|
||||||
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(
|
||||||
|
meta=meta,
|
||||||
|
mediainfo=mediainfo,
|
||||||
|
totals=totals
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# 洗版
|
||||||
|
exist_flag = False
|
||||||
|
if meta.type == MediaType.TV:
|
||||||
|
# 对于电视剧,构造缺失的媒体信息
|
||||||
|
no_exists = {
|
||||||
|
mediakey: {
|
||||||
|
subscribe.season: NotExistMediaInfo(
|
||||||
|
season=subscribe.season,
|
||||||
|
episodes=[],
|
||||||
|
total_episode=subscribe.total_episode,
|
||||||
|
start_episode=subscribe.start_episode or 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
no_exists = {}
|
||||||
|
|
||||||
|
# 如果媒体已存在,执行订阅完成操作
|
||||||
|
if exist_flag:
|
||||||
|
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
||||||
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, force=True)
|
||||||
|
return True, no_exists
|
||||||
|
|
||||||
|
# 获取已下载的集数或电影
|
||||||
|
downloaded = self.__get_downloaded(subscribe)
|
||||||
|
if meta.type == MediaType.TV:
|
||||||
|
# 对于电视剧类型,整合缺失集数并剔除已下载的集数
|
||||||
|
exist_flag, no_exists = self.__get_subscribe_no_exits(
|
||||||
|
subscribe_name=f'{subscribe.name} {meta.season}',
|
||||||
|
no_exists=no_exists,
|
||||||
|
mediakey=mediakey,
|
||||||
|
begin_season=meta.begin_season,
|
||||||
|
total_episode=subscribe.total_episode,
|
||||||
|
start_episode=subscribe.start_episode,
|
||||||
|
downloaded_episodes=downloaded
|
||||||
|
)
|
||||||
|
elif meta.type == MediaType.MOVIE:
|
||||||
|
# 对于电影类型,直接根据是否已下载判断
|
||||||
|
exist_flag = bool(downloaded)
|
||||||
|
|
||||||
|
# 如果已下载完毕,执行订阅完成操作
|
||||||
|
if exist_flag:
|
||||||
|
logger.info(f'{mediainfo.title_year} 已全部下载')
|
||||||
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, force=True)
|
||||||
|
return True, no_exists
|
||||||
|
|
||||||
|
# 返回结果,表示媒体未完全下载或存在
|
||||||
|
return False, no_exists
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_states_for_search(state: str) -> str:
|
def get_states_for_search(state: str) -> str:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user