diff --git a/app/chain/download.py b/app/chain/download.py index 7066d5ad..9bb01b1f 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -345,7 +345,8 @@ class DownloadChain(ChainBase): username=username, channel=channel.value if channel else None, date=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), - media_category=media_category + media_category=media_category, + note={"source": source} ) # 登记下载文件 @@ -383,7 +384,8 @@ class DownloadChain(ChainBase): "context": context, "username": username, "downloader": _downloader, - "episodes": episodes + "episodes": episodes, + "source": source }) else: # 下载失败 @@ -489,7 +491,8 @@ class DownloadChain(ChainBase): logger.debug(f"Initial contexts: {len(contexts)} items, Downloader: {downloader}") event_data = ResourceSelectionEventData( contexts=contexts, - downloader=downloader + downloader=downloader, + origin=source ) event = eventmanager.send_event(ChainEventType.ResourceSelection, event_data) # 如果事件修改了上下文数据,使用更新后的数据 diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 6067ebb8..d234d25e 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -391,6 +391,15 @@ class SubscribeChain(ChainBase, metaclass=Singleton): continue # 自动下载 + source_keyword = { + 'id': subscribe.id, + 'name': subscribe.name, + 'year': subscribe.year, + 'type': subscribe.type, + 'season': subscribe.season, + 'tmdbid': subscribe.tmdbid + } + source = f"Subscribe|{source_keyword}" downloads, lefts = self.downloadchain.batch_download( contexts=matched_contexts, no_exists=no_exists, @@ -399,7 +408,7 @@ class SubscribeChain(ChainBase, metaclass=Singleton): save_path=subscribe.save_path, media_category=subscribe.media_category, downloader=subscribe.downloader, - source="Subscribe" + source=source ) # 判断是否应完成订阅 @@ -784,6 +793,15 @@ class SubscribeChain(ChainBase, metaclass=Singleton): # 开始批量择优下载 logger.info(f'{mediainfo.title_year} 匹配完成,共匹配到{len(_match_context)}个资源') + source_keyword = { + 'id': subscribe.id, + 'name': subscribe.name, + 'year': subscribe.year, + 'type': subscribe.type, + 'season': subscribe.season, + 'tmdbid': subscribe.tmdbid + } + source = f"Subscribe|{source_keyword}" downloads, lefts = self.downloadchain.batch_download(contexts=_match_context, no_exists=no_exists, userid=subscribe.username, @@ -791,7 +809,7 @@ class SubscribeChain(ChainBase, metaclass=Singleton): save_path=subscribe.save_path, media_category=subscribe.media_category, downloader=subscribe.downloader, - source="Subscribe") + source=source) # 判断是否要完成订阅 self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, downloads=downloads, lefts=lefts) diff --git a/app/schemas/event.py b/app/schemas/event.py index 08e78420..b36e9025 100644 --- a/app/schemas/event.py +++ b/app/schemas/event.py @@ -165,6 +165,7 @@ class ResourceSelectionEventData(BaseModel): # 输入参数 contexts: Any = Field(None, description="待选择的资源上下文列表") downloader: Optional[str] = Field(None, description="下载器") + origin: Optional[str] = Field(None, description="来源") # 输出参数 updated: bool = Field(False, description="是否已更新")