v0.1.2: 검색 속도 개선, 인피니티 스크롤 최적화, 미니 플레이어 추가

This commit is contained in:
2026-01-24 22:22:02 +09:00
parent b27bf655f2
commit 901fcd0541
15 changed files with 893 additions and 37 deletions

View File

@@ -75,6 +75,16 @@ class ModuleBasic(PluginModuleBase):
arg["preset_list"] = self.get_preset_list()
arg["postprocessor_list"] = self.get_postprocessor_list()
elif sub in ["thumbnail", "sub", "search"]:
default_filename: Optional[str] = P.ModelSetting.get("default_filename")
arg["filename"] = (
default_filename
if default_filename
else self.get_default_filename()
)
# These templates don't have the module prefix in their name
return render_template(f"{P.package_name}_{sub}.html", arg=arg)
return render_template(f"{P.package_name}_{self.name}_{sub}.html", arg=arg)
def plugin_load(self) -> None:
@@ -271,6 +281,54 @@ class ModuleBasic(PluginModuleBase):
ret["ret"] = "warning"
ret["msg"] = "미리보기 URL을 가져올 수 없습니다."
elif sub == "search":
keyword: str = req.form["keyword"]
page: int = int(req.form.get("page", 1))
page_size: int = 20
# 캐시 키 및 만료 시간 (5분)
import time
cache_key = f"search:{keyword}"
cache_expiry = 300 # 5분
# 캐시에서 결과 확인
cached = getattr(self, '_search_cache', {}).get(cache_key)
current_time = time.time()
if cached and current_time - cached['time'] < cache_expiry:
all_results = cached['data']
else:
# 새 검색 수행 - 최대 100개 결과 가져오기
search_url = f"ytsearch100:{keyword}" if not keyword.startswith('http') else keyword
search_data = MyYoutubeDL.get_info_dict(
search_url,
proxy=P.ModelSetting.get("proxy"),
)
if search_data and 'entries' in search_data:
all_results = [r for r in search_data['entries'] if r] # None 제거
# 캐시에 저장
if not hasattr(self, '_search_cache'):
self._search_cache = {}
self._search_cache[cache_key] = {'data': all_results, 'time': current_time}
else:
all_results = []
if all_results:
# 현재 페이지에 해당하는 결과만 슬라이싱
start_idx = (page - 1) * page_size
results = all_results[start_idx:start_idx + page_size]
ret["data"] = results
# 더 이상 결과가 없으면 알림
if not results:
ret["ret"] = "info"
ret["msg"] = "모든 검색 결과를 불러왔습니다."
else:
ret["ret"] = "warning"
ret["msg"] = "검색 결과를 찾을 수 없습니다."
return jsonify(ret)
except Exception as error:
logger.error(f"AJAX 처리 중 예외 발생: {error}")