def Init(pid, overwrite): global FileHandle,Progress,AudioCount,VideoCount,ImageCount,\ Pool,IsDownload,DirName,IsCreate,OutputHTML,FFmpeg IsDownload = set() IsCreate = set() AudioCount = VideoCount = ImageCount = 0 if (os.path.isdir(DirName)): Avalon.warning("\"%s\"已存在" % DirName) if (overwrite == 1): Avalon.warning("跳过%d" % pid) elif (overwrite == 2): Avalon.warning("默认覆盖\"%s\"" % DirName) elif (not Avalon.ask("是否覆盖?", False)): raise UserCancelled("...") elif (os.path.exists(DirName)): raise OSError("存在同名文件") else: os.makedirs(DirName) if (OutputHTML): FileHandle = open("%s/%d.html" % (DirName, pid), "w", encoding="utf-8") Write('<!doctype html><html lang="zh-cn"><head><link rel="stylesheet"'\ ' type="text/css" href="main.css"></head><body><div id="write">') shutil.copy("main.css", DirName + "/") else: FileHandle = open("%s/%d.md" % (DirName, pid), "w", encoding="utf-8") try: subprocess.Popen("ffmpeg",stdout=subprocess.DEVNULL,\ stderr=subprocess.DEVNULL).wait() FFmpeg = 1 except FileNotFoundError: Avalon.warning("未找到ffmpeg,语音将不会被转为mp3") FFmpeg = 0 Pool = DownloadPool(DirName + "/", "file") Progress = tqdm(unit="floor")
def Init(pid, overwrite): global FileHandle, Progress, AudioCount, VideoCount, ImageCount, Pool, IsDownload, DirName, IsCreate, OutputHTML, FFmpeg, OutPutFileName, DirName_New IsDownload = set() IsCreate = set() AudioCount = VideoCount = ImageCount = 0 if (os.path.isdir(DirName)): Avalon.warning("\"%s\"已存在" % DirName) if (overwrite == 1): Avalon.warning("跳过%d" % pid) elif (overwrite == 2): Avalon.warning("默认覆盖\"%s\"" % DirName) elif (overwrite == 3): if (len(DirName) > 30): DirName_New = DirName[:-11] else: DirName_New = DirName if (Server): Avalon.info("已将已存在文件夹备份至" + (datetime.datetime.now().strftime('%m-%d')) + "/" + DirName_New + " " + (datetime.datetime.now() - datetime.timedelta(hours=12)).strftime('%H-%M')) shutil.move(DirName, (datetime.datetime.now().strftime('%m-%d')) + "/" + DirName_New + " " + (datetime.datetime.now() - datetime.timedelta(hours=12)).strftime('%H-%M')) if not (Server): Avalon.info("已将已存在文件夹备份至" + (datetime.datetime.now().strftime('%m-%d')) + "/" + DirName_New + " " + datetime.datetime.now().strftime('%H-%M')) shutil.move(DirName, (datetime.datetime.now().strftime('%m-%d')) + "/" + DirName_New + " " + datetime.datetime.now().strftime('%H-%M')) os.makedirs(DirName) elif (not Avalon.ask("是否覆盖?", False)): raise UserCancelled("...") elif (os.path.exists(DirName)): raise OSError("存在同名文件") else: os.makedirs(DirName) if (OutputHTML): FileHandle = open("%s/%s.html" % (DirName, OutPutFileName), "w+", encoding="utf-8") Write(Html_Header) Write("<title>%s</title>\n" % (title_name)) if (exe_mode): if (not_work_path): shutil.copy("main.css", DirName + "/") elif not (not_work_path): shutil.copy(exe_path + "/main.css", DirName + "/") else: shutil.copy(sys.path[0] + "/main.css", DirName + "/") else: FileHandle = open("%s/%s.md" % (DirName, OutPutFileName), "w+", encoding="utf-8") try: subprocess.Popen("ffmpeg",stdout=subprocess.DEVNULL,\ stderr=subprocess.DEVNULL).wait() FFmpeg = 1 except FileNotFoundError: Avalon.warning("未找到ffmpeg,语音将不会被转为mp3") FFmpeg = 0 Pool = DownloadPool(DirName + "/", "file") Progress = tqdm(unit="floor")
ProcessFloor(fnum, userlist[floor["author_id"]]["name"], floor["time"], ProcessContent(fnum, floor["content"], 0))) if (int(floor["sub_post_number"]) == 0): continue if (comment): GetComment(fnum, pid, floor["id"]) if (lastfid == fid): break # print(fid,lastfid) lastfid = fid while (1): try: if (Avalon.ask("批量模式?", False)): PreSet = True lz = Avalon.ask("只看楼主?", False) comment = (0 if lz else Avalon.ask("包括评论?", True)) OutputHTML = Avalon.ask("输出HTML(否则表示输出Makrdown)?:", True) overwrite = Avalon.ask("默认覆盖?", False) Avalon.info("选定:%s && %s评论 , 目录:\"吧名\\标题\"" % (("楼主" if lz else "全部"), ("全" if comment else "无"))) if (not Avalon.ask("确认无误?", True)): Avalon.warning("请重新输入") else: break else: PreSet = False break except KeyboardInterrupt:
floor["time"], ProcessContent(fnum, floor["content"], 0))) if (int(floor["sub_post_number"]) == 0): continue if (comment): GetComment(fnum, pid, floor["id"]) if (lastfid == fid): break #print(fid,lastfid) lastfid = fid if not (Server): while (1): try: if (Avalon.ask("批量模式?", False)): if (Avalon.ask("开启延迟?", True)): Delay = True while (1): try: Delay_time = ( Avalon.gets("请输入延迟时长(以秒为单位,留空默认为60s):")) if (Delay_time == ""): Delay_time = "60" Delay_time = int(float(Delay_time)) if (Delay_time == 0): Avalon.warning("时长不能为0!") continue break except Exception: Avalon.warning("格式错误,请重新输入!")