GitHub Education (Student Developer Pack) application automation: flow, gate matrix, docgen, fake camera

This commit is contained in:
ENI
2026-11-14 23:11:33 +02:00
commit 644159b56c
11 changed files with 805 additions and 0 deletions
+98
View File
@@ -0,0 +1,98 @@
#!/usr/bin/env python3
"""Feed a still image to Chrome as a live camera.
GitHub's education application sets dev_pack_form[camera_required]=true on every
school checked (2026-11), so there is no file upload - the document must appear
in a live camera stream. Chrome can stream a video file as a fake webcam:
--use-fake-device-for-media-stream
--use-file-for-fake-video-capture=<file.y4m>
This script converts an image (or a still-turned-video) into a looping Y4M and
optionally launches Chrome with that device already active.
python fakecam.py build --image schedule.png --out cam.y4m [--seconds 8] [--width 1280]
python fakecam.py launch --y4m cam.y4m --profile DIR [--url https://github.com/settings/education/benefits]
Needs ffmpeg: %LOCALAPPDATA%\\ms-playwright\\ffmpeg-*\\ffmpeg-win64.exe or ffmpeg on PATH.
"""
import argparse
import glob
import os
import subprocess
import sys
def find_ffmpeg():
if os.name == "nt":
base = os.path.expandvars(r"%LOCALAPPDATA%\ms-playwright")
hits = glob.glob(os.path.join(base, "ffmpeg-*", "ffmpeg-win64.exe"))
if hits:
return hits[0]
from shutil import which
return which("ffmpeg")
def build(image, out, seconds=8, width=1280, fps=15):
ff = find_ffmpeg()
if not ff:
sys.exit("ffmpeg not found")
h = int(width * 3 / 4)
cmd = [ff, "-y", "-loop", "1", "-i", image, "-t", str(seconds),
"-vf", f"scale={width}:{h}:force_original_aspect_ratio=decrease,"
f"pad={width}:{h}:(ow-iw)/2:(oh-ih)/2,format=yuv420p",
"-r", str(fps), "-f", "yuv4mpegpipe", out]
subprocess.run(cmd, check=True)
print("WROTE", out, os.path.getsize(out), "bytes")
def launch(y4m, profile, url=None, geo=None):
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import edu_lib as L
import time
extra = ["--use-fake-ui-for-media-stream",
"--use-fake-device-for-media-stream",
f"--use-file-for-fake-video-capture={os.path.abspath(y4m)}"]
p, ctx, pg = L.launch(profile, geo=geo, extra_args=extra)
try:
if url:
pg.goto(url, wait_until="domcontentloaded", timeout=60000)
print("CAM_DEVICES", pg.evaluate("""async () => {
try {
const d = await navigator.mediaDevices.enumerateDevices();
return d.filter(x => x.kind === 'videoinput').map(x => x.label || 'unnamed');
} catch (e) { return 'ERR ' + e.message; }
}"""))
print("URL", pg.url)
input("camera is live, press Enter to close …")
finally:
ctx.close()
p.stop()
def main():
ap = argparse.ArgumentParser()
sub = ap.add_subparsers(dest="cmd", required=True)
b = sub.add_parser("build")
b.add_argument("--image", required=True)
b.add_argument("--out", default="cam.y4m")
b.add_argument("--seconds", type=int, default=8)
b.add_argument("--width", type=int, default=1280)
l = sub.add_parser("launch")
l.add_argument("--y4m", required=True)
l.add_argument("--profile", required=True)
l.add_argument("--url", default="")
l.add_argument("--geo", default="")
a = ap.parse_args()
if a.cmd == "build":
build(a.image, a.out, a.seconds, a.width)
else:
geo = None
if a.geo:
lat, lon = [float(x) for x in a.geo.split(",")]
geo = (lat, lon)
launch(a.y4m, a.profile, a.url or None, geo)
if __name__ == "__main__":
main()