Last active
June 10, 2023 01:24
-
-
Save gurrgur/0993e0cdb0033ca492c05aafb00873c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
from pathlib import Path | |
from datetime import datetime, timedelta | |
import json | |
import subprocess | |
d = Path("Dynamic_Wallpapers") | |
for xmlfile in d.glob("*.xml"): | |
f = xmlfile.name | |
name = f.rsplit(".")[0] | |
tree = ET.parse(d / f) | |
root = tree.getroot() | |
t = datetime( | |
year=int(root.find("starttime").find("year").text), | |
month=int(root.find("starttime").find("month").text), | |
day=int(root.find("starttime").find("day").text), | |
hour=int(root.find("starttime").find("hour").text), | |
minute=int(root.find("starttime").find("minute").text), | |
second=int(root.find("starttime").find("second").text), | |
) | |
sequence = [] | |
for c in root: | |
if c.tag == "starttime": | |
continue | |
crossfade = c.tag == "transition" | |
filename = c.find("from").text if crossfade else c.find("file").text | |
sequence.append( | |
{ | |
#"SolarAzimuth": "*", | |
#"SolarElevation": "*", | |
"CrossFade": crossfade, | |
"Time": str(t.hour).zfill(2) + ":" + str(t.minute).zfill(2), | |
"FileName": str(Path(name) / Path(filename).name) | |
} | |
) | |
dt = timedelta(seconds=float(c.find("duration").text)) | |
t = t + dt | |
manifest_data = {"Type": "solar", "Meta": sequence} | |
manifest_file = d / (name + ".json") | |
with open(manifest_file, "w") as m: | |
json.dump(manifest_data, m, indent=4) | |
out_dir = Path("avif") | |
if not out_dir.is_dir(): | |
out_dir.mkdir() | |
out_file = out_dir / (name + '.avif') | |
cmd = [ | |
'kdynamicwallpaperbuilder', | |
'--output', | |
f'./{out_file}', | |
f'./{str(manifest_file)}', | |
] | |
if not out_file.is_file(): | |
print("starting subprocess:", cmd) | |
subprocess.run(cmd) | |
else: | |
print("skip:", cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, thanks for this! I modified it a bit for some large speed improvements. Hope it's helpful to you
-Marcus