Skip to content

Instantly share code, notes, and snippets.

@PassionPenguin
Last active July 17, 2022 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PassionPenguin/9377e40839f49e6356005b711bfa7239 to your computer and use it in GitHub Desktop.
Save PassionPenguin/9377e40839f49e6356005b711bfa7239 to your computer and use it in GitHub Desktop.
Bookan Book Generator

README

How to

  1. make sure you have access to /storage/emulated/0/Android/data/cn.com.bookan dir.
  2. make sure you have downloaded the book you want to read (the version of which must be Original Preview).
  3. copy /storage/emulated/0/Android/data/cn.com.bookan/files/bookan/magazine to your PC.

If you can run python on your android device and you can install packages with pip, you can ignore this step.

  1. install the required dependency with the file requirements.txt.
  2. copy bookan.py to the magazine folder and run the file.

Test env

Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Pillow==9.2.0
Windows 10 Pro 21H2 19044.1826 [Windows Feature Experience Pack 120.2212.4180.0]

---

cn.com.bookan v7.5.0
from PIL import Image
import os
import glob
for p in glob.glob("*.txt"):
# get image paths from file `p`
# the format of the txt file is always the following:
# FILE START
# bookid/imageid1.0
# bookid/imageid2.0
# bookid/imageid3.0
# ...
#
# FILE END
image_list = open(p, "r", encoding="utf-8").read().replace("/storage/emulated/0/Android/data/cn.com.bookan/files/bookan/magazine/", "").split("\n")
image_list.pop() # last element is empty
output = Image.open(image_list[0])
image_list.pop(0)
images = []
for i in image_list:
images.append(Image.open(i))
output.save(os.path.splitext(p)[0] + ".pdf", "PDF", save_all=True, append_images=images)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment