Initial commit: CapCutAPI - 轻量、灵活、易上手的剪映/CapCut API工具

This commit is contained in:
sun-guannan
2025-07-11 18:02:44 +08:00
commit f818b9306a
84 changed files with 27829 additions and 0 deletions

19
draft_cache.py Normal file
View File

@@ -0,0 +1,19 @@
from collections import OrderedDict
import pyJianYingDraft as draft
from typing import Dict
# 修改全局变量使用OrderedDict实现LRU缓存限制最大数量为10000
DRAFT_CACHE: Dict[str, 'draft.Script_file'] = OrderedDict() # 使用 Dict 进行类型提示
MAX_CACHE_SIZE = 10000
def update_cache(key: str, value: draft.Script_file) -> None:
"""更新LRU缓存"""
if key in DRAFT_CACHE:
# 如果键存在,删除旧的项
DRAFT_CACHE.pop(key)
elif len(DRAFT_CACHE) >= MAX_CACHE_SIZE:
print(f"{key}, 缓存已满,删除最久未使用的项")
# 如果缓存已满,删除最久未使用的项(第一个项)
DRAFT_CACHE.popitem(last=False)
# 添加新项到末尾(最近使用)
DRAFT_CACHE[key] = value