import sys

scale = 1.5

def transform():
    with open(sys.argv[1]) as f:
        for line in f.readlines():
            if "<img alt='PIC' src='videos/" in line:
                begin, end = line.split("<img", maxsplit=1)
                yield begin

                img, rest = end.split("/>", maxsplit=1)
                yield rest

                src = img.split("src='")[1].split("'")[0]
                assert src.endswith(".png"), src
                src = src.removesuffix(".png") + ".mp4"
                yield "<video style='width: 100%;' controls=''>"
                yield f"<source src='{src}' type='video/mp4'>"
                yield "</video>"
            else:
                yield line

lines = list(transform())
with open(sys.argv[1], 'w') as f:
    f.write(''.join(lines))
