mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
fix: merge downloader tracker mappings
This commit is contained in:
@@ -15,6 +15,7 @@ class ModuleResultAggregation(StrEnum):
|
||||
LEGACY = "legacy"
|
||||
FIRST_NON_EMPTY = "first_non_empty"
|
||||
ORDERED_LIST_MERGE = "ordered_list_merge"
|
||||
ORDERED_MAPPING_MERGE = "ordered_mapping_merge"
|
||||
|
||||
|
||||
class ModuleResultShape(StrEnum):
|
||||
@@ -118,6 +119,7 @@ _METHOD_CONTRACTS = {
|
||||
"downloader_info": ModuleMethodContract(family="downloader", input_contract="DownloaderInfoRequest", result_contract="list[DownloaderInfo]", result_shape=ModuleResultShape.LIST, aggregation=ModuleResultAggregation.ORDERED_LIST_MERGE, required_parameters=("downloader",)),
|
||||
"list_torrents": ModuleMethodContract(family="downloader", input_contract="TorrentListRequest", result_contract="list[DownloaderTorrent]", result_shape=ModuleResultShape.LIST, aggregation=ModuleResultAggregation.ORDERED_LIST_MERGE, required_parameters=("status", "hashs", "downloader", "include_all_tags")),
|
||||
"torrent_files": ModuleMethodContract(family="downloader", input_contract="TorrentFilesRequest", result_contract="DownloaderFileCollection | None", required_parameters=("tid", "downloader")),
|
||||
"get_torrent_trackers": ModuleMethodContract(family="downloader", input_contract="TorrentTrackersRequest", result_contract="dict[str, list[str]] | None", result_shape=ModuleResultShape.MAPPING, aggregation=ModuleResultAggregation.ORDERED_MAPPING_MERGE, required_parameters=("hash_string", "downloader")),
|
||||
}
|
||||
|
||||
_PREFIX_CONTRACTS = (
|
||||
|
||||
@@ -383,6 +383,12 @@ class ModuleInvocationDispatcher:
|
||||
if isinstance(result, list)
|
||||
else _ProviderCallMode.STOP
|
||||
)
|
||||
if aggregation is ModuleResultAggregation.ORDERED_MAPPING_MERGE:
|
||||
return (
|
||||
_ProviderCallMode.ORIGINAL
|
||||
if isinstance(result, dict)
|
||||
else _ProviderCallMode.STOP
|
||||
)
|
||||
if allow_relay and ObjectUtils.check_signature(func, result):
|
||||
return _ProviderCallMode.RELAY
|
||||
if isinstance(result, list):
|
||||
@@ -396,10 +402,14 @@ class ModuleInvocationDispatcher:
|
||||
call_mode: _ProviderCallMode,
|
||||
) -> Any:
|
||||
"""合并单个 provider 结果,接力调用则用新结果替换旧结果。"""
|
||||
if call_mode is _ProviderCallMode.RELAY or not isinstance(result, list):
|
||||
if call_mode is _ProviderCallMode.RELAY:
|
||||
return provider_result
|
||||
if isinstance(provider_result, list):
|
||||
if isinstance(result, list) and isinstance(provider_result, list):
|
||||
result.extend(provider_result)
|
||||
elif isinstance(result, dict) and isinstance(provider_result, dict):
|
||||
result.update(provider_result)
|
||||
elif not isinstance(result, (list, dict)):
|
||||
return provider_result
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user