| import multiprocessing |
| import pathlib |
| import orjson |
|
|
|
|
| qp = multiprocessing.Queue() |
|
|
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
| |
| bare_root = pathlib.Path("gutenberg") |
| idx_nums = [str(i) for i in range(0, 10)] |
|
|
|
|
| def iterative_folders(root: pathlib.Path): |
| files = [] |
| for item in root.iterdir(): |
| if item.is_dir(): |
| if len(item.stem) == 1 and item.stem[0] in idx_nums: |
| files.extend(iterative_folders(item)) |
| continue |
| |
| if ".txt" not in item.suffix.lower(): |
| html = item / f"{item.stem}-h" |
|
|
| if html.is_dir() and list(html.glob("*.htm")): |
| |
| |
| files.append([html, "html"]) |
| elif (item / f"{item.stem}.txt").exists(): |
| |
| files.append([html, "txt"]) |
| elif (item / f"{item.stem}-8.txt").exists(): |
| |
| files.append([html, "txt-8"]) |
| elif (item / f"{item.stem}-0.txt").exists(): |
| |
| files.append([html, "txt-0"]) |
| elif (item / f"{item.stem}-t" / f"{item.stem}-t.tex").exists(): |
| |
| files.append([html, "tex-folder"]) |
| elif (item / "mp3").exists(): |
| files.append([html, "audiobook-mp3"]) |
| |
| elif (item / "ogg").exists(): |
| files.append([html, "audiobook-ogg-fb"]) |
| pass |
| |
| elif (item / "m4b").exists(): |
| files.append([html, "audiobook-m4b-fb"]) |
| pass |
| |
| else: |
| files.append([item, "unk"]) |
| print("????", item) |
| else: |
| continue |
| |
| |
| |
| return files |
|
|
|
|
| z = [] |
| for rd in idx_nums: |
| z.extend(iterative_folders(bare_root / rd)) |
|
|
| for idx, item in enumerate(z): |
| z[idx] = [str(item[0]), item[1]] |
|
|
| pathlib.Path("index.json").write_bytes(orjson.dumps(z, option=orjson.OPT_INDENT_2)) |
|
|