2018-10-17 08:57:09 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import re
|
|
|
|
import importlib
|
2018-10-17 17:25:29 +00:00
|
|
|
import argparse
|
2019-02-18 16:23:47 +00:00
|
|
|
import subprocess
|
2020-05-02 11:24:31 +00:00
|
|
|
import traceback
|
2018-10-17 08:57:09 +00:00
|
|
|
|
|
|
|
regs = {
|
2020-07-07 12:39:55 +00:00
|
|
|
r"\d/\d/\d_\d\.jpg": "krpanosteal",
|
2022-09-29 05:58:07 +00:00
|
|
|
r"\_[frblud].jpg": "krpanosteal",
|
2020-07-07 12:39:55 +00:00
|
|
|
r"my.matterport.com/show/": "matterportsteal",
|
|
|
|
r"cdn-1.matterport.com": "matterportsimple",
|
|
|
|
r"youtube.com": "youtubesteal",
|
|
|
|
r"l\d_[frblud]_\d\d_\d\d.jpg": "giraffesteal",
|
2021-02-27 07:20:21 +00:00
|
|
|
r"=x\d-y\d-z\d": "googlesteal",
|
|
|
|
r"[brflud]\/\d\/\d_\d\.jpg": "tdvsteal",
|
2021-02-27 07:38:23 +00:00
|
|
|
"c\d_l\d_\d_\d.jpg": "pindorasteal",
|
|
|
|
"/[frblud]/l\d/\d/l\d_[frblud]_\d_\d.jpg": "eyerevolutionsteal",
|
|
|
|
"(pos|neg)[xyz]\.jpg": "xvrsteal",
|
2018-10-17 08:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def parse_url(url):
|
|
|
|
global regs
|
|
|
|
|
|
|
|
selected = None
|
|
|
|
|
|
|
|
for regex, handler in regs.items():
|
|
|
|
if re.search(regex, url):
|
|
|
|
selected = handler
|
|
|
|
break
|
|
|
|
|
|
|
|
if not selected:
|
2020-05-19 09:53:16 +00:00
|
|
|
raise ValueError("No matching handler found")
|
2018-10-17 08:57:09 +00:00
|
|
|
|
|
|
|
return importlib.import_module(selected).process_url
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-10-17 17:25:29 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('url', help='URL to process')
|
2019-02-18 16:23:47 +00:00
|
|
|
parser.add_argument('--title', help='title to be used for the file name', default="No Title")
|
2018-10-17 17:25:29 +00:00
|
|
|
parser.add_argument("--rotation", nargs=3, type=int, help="rotation on x/y/z axes", metavar=("x","y","z"))
|
|
|
|
parser.add_argument("--resolution", type=int, nargs=2, metavar=("w","h"))
|
2019-02-18 16:23:47 +00:00
|
|
|
parser.add_argument("--output", default=".")
|
2018-10-17 17:25:29 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2018-10-19 17:36:59 +00:00
|
|
|
try:
|
|
|
|
handler = parse_url(args.url)
|
|
|
|
image = handler(args.url, args.rotation or [0,0,0], args.resolution or [3840, 1920])
|
2019-02-18 16:23:47 +00:00
|
|
|
if not hasattr(image, "im"):
|
|
|
|
with open(args.output + "/" + args.title + ".mkv", "wb") as video:
|
|
|
|
video.write(image)
|
|
|
|
subprocess.run(["/usr/bin/ffmpeg",
|
|
|
|
"-i", args.output + "/" + args.title + ".mkv",
|
|
|
|
"-ss", "00:00:10",
|
|
|
|
"-vframes", "1",
|
|
|
|
"-f", "image2",
|
|
|
|
args.output + "/" + args.title + ".thumb.jpg"])
|
|
|
|
else:
|
|
|
|
image.save(args.output + "/" + args.title + ".png")
|
2020-05-02 11:24:31 +00:00
|
|
|
except Exception:
|
2018-10-19 17:36:59 +00:00
|
|
|
with open(args.output + "/" + args.title + ".err", "w") as errorfile:
|
2020-05-02 11:24:31 +00:00
|
|
|
errorfile.write(traceback.format_exc())
|