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 = {
|
|
|
|
"\d/\d/\d_\d\.jpg": "krpanosteal",
|
2018-10-21 12:21:48 +00:00
|
|
|
"pano\_[frblud].jpg": "krpanosteal",
|
2019-02-18 16:23:47 +00:00
|
|
|
"my.matterport.com/show/": "matterportsteal",
|
2020-05-19 09:53:16 +00:00
|
|
|
"cdn-1.matterport.com": "matterportsimple",
|
2020-05-02 11:24:31 +00:00
|
|
|
"youtube.com": "youtubesteal",
|
|
|
|
"l\d_[frblud]_\d\d_\d\d.jpg": "giraffesteal"
|
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())
|