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

View File

@@ -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)
# 如果事件修改了上下文数据,使用更新后的数据

View File

@@ -1,7 +1,8 @@
import copy
import json
import random
import time
import threading
import time
from datetime import datetime
from typing import Dict, List, Optional, Union, Tuple
@@ -399,7 +400,7 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
save_path=subscribe.save_path,
media_category=subscribe.media_category,
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,
media_category=subscribe.media_category,
downloader=subscribe.downloader,
source="Subscribe")
source=self.get_subscribe_source_keyword(subscribe)
)
# 判断是否要完成订阅
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo,
downloads=downloads, lefts=lefts)
@@ -1332,3 +1334,24 @@ class SubscribeChain(ChainBase, metaclass=Singleton):
if state in ["R", "P"]:
return "R,P"
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)}"

View File

@@ -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="是否已更新")