Skip to content

Instantly share code, notes, and snippets.

@franga2000
Created February 7, 2021 19:24
Show Gist options
  • Save franga2000/52d4e51fc625ea65e67eaed67be10152 to your computer and use it in GitHub Desktop.
Save franga2000/52d4e51fc625ea65e67eaed67be10152 to your computer and use it in GitHub Desktop.
Capture screenshots from Adobe Digital Editions
import os
import sys
import time
from pathlib import Path
import pyautogui
from ewmh import EWMH
# Utility functions
def find_ade_window():
global wm
client_list = wm.getClientList()
for window in client_list:
if "Adobe Digital Editions" in wm.getWmName(window).decode("utf-8"):
return window
def echo(s):
print(s, end="", flush=True)
def ensure_active():
global wm
while not wm.getActiveWindow() == win:
input("ADE not in focus, pausing. Press any key to continue")
print("Resuming in 3 seconds...")
time.sleep(3)
# Script starts here
session = 0
if len(sys.argv) > 1:
session = int(sys.argv[1])
basedir = f"screens/{session}"
Path(basedir).mkdir(parents=True, exist_ok=True)
print(f"Session {session}, saving to: '{basedir}/'")
i = 0
wm = EWMH()
echo("ADE window: ")
win = find_ade_window()
if not win:
print("No ADE window detected!")
sys.exit(1)
print(win.__dict__)
ensure_active()
print("Starting capture!")
# Main loop - this is where everything happens
while True:
echo(f"{i}: ")
# TODO: Check if the book is over
echo("CHECK ")
ensure_active()
filename = f"{basedir}/{i}-%02d.png"
os.system(f"xwd -id {win.id} | convert xwd:- -shave 0x50 -crop 3x1@ +repage '{filename}'")
echo("SCREEN ")
ensure_active()
pyautogui.press('right')
echo("NEXT\n")
time.sleep(.5)
i += 1
print()
print("BYE!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment