jscmp4 commited on
Commit
6f4c268
·
verified ·
1 Parent(s): 887f802

Update eh_logic.py

Browse files
Files changed (1) hide show
  1. eh_logic.py +89 -1
eh_logic.py CHANGED
@@ -166,4 +166,92 @@ def run_eh_download(eh_url, cookies_str, quality, progress=gr.Progress()):
166
  return
167
 
168
  progress(1.0, desc="全部完成!")
169
- yield [final_pdf_path], f"✅ 处理完成!\n文件名: {final_pdf_name}", "完成"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  return
167
 
168
  progress(1.0, desc="全部完成!")
169
+ yield [final_pdf_path], f"✅ 处理完成!\n文件名: {final_pdf_name}", "完成"
170
+
171
+
172
+
173
+
174
+ def debug_eh_info(eh_url, cookies_str):
175
+ """
176
+ 专门用于调试的函数:
177
+ 运行 gallery-dl --dump-json 并返回原始的 stdout/stderr 输出
178
+ """
179
+ import json # 确保引入 json
180
+
181
+ debug_report = []
182
+ debug_report.append(f"🔍 [Debug] 开始分析链接: {eh_url}")
183
+
184
+ # 1. 准备环境
185
+ eh_base_dir = os.path.join(BASE_DIR, "eh_debug_temp")
186
+ os.makedirs(eh_base_dir, exist_ok=True)
187
+
188
+ cookie_file_path = os.path.join(BASE_DIR, "eh_cookies.txt")
189
+ with open(cookie_file_path, "w", encoding="utf-8") as f:
190
+ f.write(cookies_str)
191
+
192
+ debug_report.append(f"🍪 [Debug] Cookies 已写入: {cookie_file_path}")
193
+
194
+ # 2. 构建探测命令
195
+ # 我们去掉所有复杂的参数,只保留最核心的 dump-json
196
+ cmd = [
197
+ "gallery-dl",
198
+ "--cookies", cookie_file_path,
199
+ "--user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
200
+ "--dump-json",
201
+ "--range", "1", # 只看第一张,速度快
202
+ "--verbose", # 开启啰嗦模式,看报错
203
+ eh_url
204
+ ]
205
+
206
+ cmd_str = " ".join(cmd)
207
+ debug_report.append(f"💻 [Debug] 执行命令:\n{cmd_str}\n")
208
+ debug_report.append("-" * 30)
209
+
210
+ # 3. 执行并捕获一切
211
+ try:
212
+ process = subprocess.run(
213
+ cmd,
214
+ capture_output=True,
215
+ text=True,
216
+ encoding='utf-8',
217
+ errors='ignore' # 忽略乱码
218
+ )
219
+
220
+ # 4. 输出运行结果
221
+ debug_report.append(f"🏷️ [Return Code]: {process.returncode} (0代表成功,非0代表失败)")
222
+
223
+ debug_report.append("\n🔴 [STDERR] (错误日志/调试信息):")
224
+ debug_report.append(process.stderr if process.stderr else "(无内容)")
225
+
226
+ debug_report.append("\n🟢 [STDOUT] (标准输出/期望的JSON):")
227
+ stdout_content = process.stdout if process.stdout else "(无内容)"
228
+ debug_report.append(stdout_content)
229
+
230
+ # 5. 尝试现场解析
231
+ debug_report.append("-" * 30)
232
+ debug_report.append("🧐 [Debug] 尝试解析 JSON:")
233
+
234
+ found_json = False
235
+ for line in stdout_content.splitlines():
236
+ if line.strip().startswith("{"):
237
+ try:
238
+ data = json.loads(line)
239
+ title = data.get('title') or data.get('gallery_title')
240
+ debug_report.append(f"✅ 成功提取到标题: {title}")
241
+ found_json = True
242
+ break
243
+ except Exception as e:
244
+ debug_report.append(f"❌ JSON 解析失败: {e}")
245
+
246
+ if not found_json:
247
+ debug_report.append("❌ 在输出中未发现有效的 JSON 数据。")
248
+ if "403" in process.stderr:
249
+ debug_report.append("👉 极其可能是 403 Forbidden。请检查 Cookies 是否过期,或 IP 被封。")
250
+ elif "sadpanda" in process.stderr.lower():
251
+ debug_report.append("👉 极其可能是 Sad Panda。Cookies 不包含 exhentai 权限。")
252
+
253
+ except Exception as e:
254
+ debug_report.append(f"💥 [Critical Error] Python 执行出错: {e}")
255
+
256
+ # 返回完整的长文本报告
257
+ return "\n".join(debug_report)