Merge pull request #3516 from InfinityPacer/feature/subscribe

This commit is contained in:
jxxghp
2024-12-11 06:53:42 +08:00
committed by GitHub
3 changed files with 33 additions and 6 deletions
+6 -3
View File
@@ -345,7 +345,8 @@ class DownloadChain(ChainBase):
username=username, username=username,
channel=channel.value if channel else None, channel=channel.value if channel else None,
date=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), 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, "context": context,
"username": username, "username": username,
"downloader": _downloader, "downloader": _downloader,
"episodes": episodes "episodes": episodes,
"source": source
}) })
else: else:
# 下载失败 # 下载失败
@@ -489,7 +491,8 @@ class DownloadChain(ChainBase):
logger.debug(f"Initial contexts: {len(contexts)} items, Downloader: {downloader}") logger.debug(f"Initial contexts: {len(contexts)} items, Downloader: {downloader}")
event_data = ResourceSelectionEventData( event_data = ResourceSelectionEventData(
contexts=contexts, contexts=contexts,
downloader=downloader downloader=downloader,
origin=source
) )
event = eventmanager.send_event(ChainEventType.ResourceSelection, event_data) event = eventmanager.send_event(ChainEventType.ResourceSelection, event_data)
# 如果事件修改了上下文数据,使用更新后的数据 # 如果事件修改了上下文数据,使用更新后的数据
+26 -3
View File
@@ -1,7 +1,8 @@
import copy import copy
import json
import random import random
import time
import threading import threading
import time
from datetime import datetime from datetime import datetime
from typing import Dict, List, Optional, Union, Tuple from typing import Dict, List, Optional, Union, Tuple
@@ -399,7 +400,7 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
save_path=subscribe.save_path, save_path=subscribe.save_path,
media_category=subscribe.media_category, media_category=subscribe.media_category,
downloader=subscribe.downloader, downloader=subscribe.downloader,
source="Subscribe" source=self.get_subscribe_source_keyword(subscribe)
) )
# 判断是否应完成订阅 # 判断是否应完成订阅
@@ -791,7 +792,8 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
save_path=subscribe.save_path, save_path=subscribe.save_path,
media_category=subscribe.media_category, media_category=subscribe.media_category,
downloader=subscribe.downloader, downloader=subscribe.downloader,
source="Subscribe") source=self.get_subscribe_source_keyword(subscribe)
)
# 判断是否要完成订阅 # 判断是否要完成订阅
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo,
downloads=downloads, lefts=lefts) downloads=downloads, lefts=lefts)
@@ -1332,3 +1334,24 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
if state in ["R", "P"]: if state in ["R", "P"]:
return "R,P" return "R,P"
return state return state
@staticmethod
def get_subscribe_source_keyword(subscribe: Subscribe) -> str:
"""
构造用于订阅来源的关键字字符串
:param subscribe: Subscribe 对象
:return: 格式化的订阅来源关键字字符串,格式为 "Subscribe|{...}"
"""
source_keyword = {
'id': subscribe.id,
'name': subscribe.name,
'year': subscribe.year,
'type': subscribe.type,
'season': subscribe.season,
'tmdbid': subscribe.tmdbid,
'imdbid': subscribe.imdbid,
'tvdbid': subscribe.tvdbid,
'doubanid': subscribe.doubanid,
'bangumiid': subscribe.bangumiid
}
return f"Subscribe|{json.dumps(source_keyword, ensure_ascii=False)}"
+1
View File
@@ -165,6 +165,7 @@ class ResourceSelectionEventData(BaseModel):
# 输入参数 # 输入参数
contexts: Any = Field(None, description="待选择的资源上下文列表") contexts: Any = Field(None, description="待选择的资源上下文列表")
downloader: Optional[str] = Field(None, description="下载器") downloader: Optional[str] = Field(None, description="下载器")
origin: Optional[str] = Field(None, description="来源")
# 输出参数 # 输出参数
updated: bool = Field(False, description="是否已更新") updated: bool = Field(False, description="是否已更新")