fix: Handle Zendriver HTML-wrapped JSON responses in get_anime_info
- Extract JSON from <pre> tag when Zendriver returns HTML-wrapped response - Add guard to prevent TypeError when items_xpath is None after JSON parsing fails - Improves error logging for debugging failed API responses
This commit is contained in:
@@ -1160,8 +1160,19 @@ class LogicLinkkf(AnimeModuleBase):
|
|||||||
response_data = LogicLinkkf.get_html(url, timeout=10)
|
response_data = LogicLinkkf.get_html(url, timeout=10)
|
||||||
|
|
||||||
# JSON 응답 처리 (Top View 포함)
|
# JSON 응답 처리 (Top View 포함)
|
||||||
|
# Zendriver returns HTML-wrapped JSON: <html>...<pre>JSON</pre>...</html>
|
||||||
|
json_text = response_data
|
||||||
|
if response_data.strip().startswith('<html') or response_data.strip().startswith('<!'):
|
||||||
|
try:
|
||||||
|
tree_temp = html.fromstring(response_data)
|
||||||
|
pre_content = tree_temp.xpath('//pre/text()')
|
||||||
|
if pre_content:
|
||||||
|
json_text = pre_content[0]
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
json_data = json.loads(response_data)
|
json_data = json.loads(json_text)
|
||||||
# P.logger.debug(json_data)
|
# P.logger.debug(json_data)
|
||||||
|
|
||||||
# top_view 처리는 별도 로직 (구조가 다름)
|
# top_view 처리는 별도 로직 (구조가 다름)
|
||||||
@@ -1192,6 +1203,11 @@ class LogicLinkkf(AnimeModuleBase):
|
|||||||
except (json.JSONDecodeError, ValueError):
|
except (json.JSONDecodeError, ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# JSON API인 경우 items_xpath가 None이므로, 이 경우 HTML 파싱 스킵
|
||||||
|
if items_xpath is None:
|
||||||
|
P.logger.error("JSON parsing failed but items_xpath is None - invalid API response")
|
||||||
|
return {"ret": "error", "log": "Invalid API response (expected JSON)"}
|
||||||
|
|
||||||
tree = html.fromstring(response_data)
|
tree = html.fromstring(response_data)
|
||||||
tmp_items = tree.xpath(items_xpath)
|
tmp_items = tree.xpath(items_xpath)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user