def cli(): parser = ArgumentParser(prog="backupqidian") parser.add_argument("bid", help="book ID", type=int) parser.add_argument("--cookiefile", help="指定 cookies.txt 路径", default="cookies.txt") parser.add_argument("-o", "--output", help="指定保存文件路径", default="text.txt") parser.add_argument("--vip", help="是否抓取 VIP 章节:默认 False", action="store_true") parser.add_argument("--range", help="章节范围,从 1 开始") parser.add_argument("--dry-run", help="看看会下载哪些章节,仅预览,不实际下载", action="store_true") args = parser.parse_args() session = get_session(args.cookiefile) index = get_bookindex(session, args.bid) if args.dry_run: freecs, vipcs = get_chapter_titles(index) else: freecs, vipcs = find_chapter_links(index) if hasattr(args, "range"): RANGE = RangeString(args.range) GLOBAL_COUNTER = 0 tmp = [] for i in freecs: GLOBAL_COUNTER += 1 if RANGE.match(GLOBAL_COUNTER): tmp.append(i) freecs = tmp tmp = [] for i in vipcs: GLOBAL_COUNTER += 1 if RANGE.match(GLOBAL_COUNTER): tmp.append(i) vipcs = tmp if args.dry_run: for c in freecs: print(c) if args.vip: for c in vipcs: print(c) else: outputfile = open(args.output, "at", encoding="utf-8") for c in freecs: download_free(session, c, outputfile) if args.vip: for c in vipcs: download_vip(session, c, outputfile) outputfile.close() print(f"saved at {args.outputfile}")
def rs0(): return RangeString("1")
def rs6(): return RangeString("-")
def rs5(): return RangeString("-3,5,7-10,20-")
def rs4(): return RangeString("3-")
def rs3(): return RangeString("1-3")
def rs2(): return RangeString("1,3")
def rs1(): return RangeString("-3")