Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from jm_logic import run_jm_download | |
| # 合并导入,避免重复 | |
| from eh_logic import run_eh_download, debug_eh_info | |
| # --- 界面构建 --- | |
| with gr.Blocks(title="二次元聚合下载器") as demo: | |
| gr.Markdown("## 📦 二次元聚合下载器 (JMComic + E-Hentai)") | |
| gr.Markdown("支持多线程下载、自动合并 PDF、智能画质压缩。") | |
| with gr.Tabs(): | |
| # ================= JMComic Tab ================= | |
| with gr.TabItem("🦄 JMComic (ID下载)"): | |
| gr.Markdown("一行一个 ID,下载完一个才会开始下一个,稳定防崩。") | |
| with gr.Row(): | |
| jm_inp_ids = gr.Textbox( | |
| label="输入本子 ID 列表 (回车分隔)", | |
| placeholder="438696\n123456", | |
| lines=5 | |
| ) | |
| with gr.Row(): | |
| # ✨ JM 也加上了画质滑块 | |
| jm_quality = gr.Slider( | |
| minimum=10, maximum=100, value=75, step=5, | |
| label="PDF 画质压缩 (100=原图无损, 75=推荐均衡)", | |
| info="JM原图通常很大,建议设置 75 以大幅节省体积。" | |
| ) | |
| with gr.Row(): | |
| jm_auth_select = gr.Radio( | |
| ["使用账号密码 (推荐)", "使用 Cookies (手动)"], | |
| label="登录方式", | |
| value="使用账号密码 (推荐)" | |
| ) | |
| with gr.Group(visible=True) as group_user: | |
| with gr.Row(): | |
| jm_inp_user = gr.Textbox(label="用户名", placeholder="JM账号") | |
| jm_inp_pass = gr.Textbox(label="密码", type="password") | |
| with gr.Group(visible=False) as group_cookie: | |
| jm_inp_cookie = gr.Textbox(label="Cookies", placeholder="key=value...") | |
| def toggle_auth(choice): | |
| if choice == "使用账号密码 (推荐)": | |
| return gr.update(visible=True), gr.update(visible=False) | |
| else: | |
| return gr.update(visible=False), gr.update(visible=True) | |
| jm_auth_select.change(fn=toggle_auth, inputs=jm_auth_select, outputs=[group_user, group_cookie]) | |
| jm_btn = gr.Button("🚀 开始下载 (JM)", variant="primary") | |
| with gr.Row(): | |
| jm_badge = gr.Label(value="Ready", label="状态") | |
| jm_log = gr.Textbox(label="运行日志", lines=5) | |
| jm_files = gr.File(label="下载结果", file_count="multiple") | |
| # 🔴 记得传入 jm_quality | |
| jm_btn.click( | |
| fn=run_jm_download, | |
| inputs=[jm_inp_ids, jm_auth_select, jm_inp_cookie, jm_inp_user, jm_inp_pass, jm_quality], | |
| outputs=[jm_files, jm_log, jm_badge] | |
| ) | |
| # ================= E-Hentai Tab ================= | |
| with gr.TabItem("🐼 E-Hentai (链接下载)"): | |
| gr.Markdown("**提示**:必须填写 Cookies (Netscape格式) 才能下载 EX 站或原图。") | |
| with gr.Row(): | |
| eh_url = gr.Textbox( | |
| label="画廊链接 (URL)", | |
| placeholder="https://e-hentai.org/g/xxxxx/yyyy/" | |
| ) | |
| with gr.Row(): | |
| eh_quality = gr.Slider( | |
| minimum=10, maximum=100, value=75, step=5, | |
| label="PDF 画质压缩 (100=原图无损, 75=推荐均衡)", | |
| info="数值越小文件越小。100为直接打包原图(速度最快),<100会进行重压缩(较慢)。" | |
| ) | |
| with gr.Row(): | |
| eh_cookie = gr.Textbox( | |
| label="Cookies (Netscape 格式)", | |
| placeholder="# Netscape HTTP Cookie File\n.e-hentai.org\tTRUE\t/ ...", | |
| lines=5, | |
| info="请使用 Chrome 插件 'Get cookies.txt LOCALLY' 导出并在粘贴至此。" | |
| ) | |
| eh_btn = gr.Button("🚀 开始下载 (EH)", variant="primary") | |
| with gr.Row(): | |
| eh_badge = gr.Label(value="Ready", label="状态") | |
| eh_log = gr.Textbox(label="运行日志 (自动滚动)", lines=5) | |
| eh_files = gr.File(label="下载结果") | |
| # --- 正常下载事件绑定 --- | |
| eh_btn.click( | |
| fn=run_eh_download, | |
| inputs=[eh_url, eh_cookie, eh_quality], | |
| outputs=[eh_files, eh_log, eh_badge] | |
| ) | |
| # ================= 🆕 新增:调试工具区域 ================= | |
| gr.Markdown("---") # 分割线 | |
| with gr.Accordion("🛠️ 调试工具 (遇到 Unknown_Gallery 或 失败时点我)", open=False): | |
| gr.Markdown("如果不清楚为什么下载失败,或者标题显示 Unknown,请点击下方按钮查看详细诊断报告。") | |
| debug_btn = gr.Button("🔍 运行标题诊断", variant="secondary") | |
| debug_out = gr.Textbox(label="诊断报告 (原始 JSON 输出)", lines=15) | |
| # --- 调试按钮事件绑定 --- | |
| debug_btn.click( | |
| fn=debug_eh_info, | |
| inputs=[eh_url, eh_cookie], | |
| outputs=[debug_out] | |
| ) | |
| if __name__ == "__main__": | |
| demo.queue().launch(ssr_mode=False, show_error=True) |