Created
January 8, 2017 16:55
-
-
Save i026e/ce8f817311a21c9bfe83ebe52c76d26e to your computer and use it in GitHub Desktop.
(Linux) Wrap .swf file with a html and open in web-browser
This file contains hidden or 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Sun Jan 8 18:58:23 2017 | |
@author: pavel | |
""" | |
import os | |
import sys | |
import subprocess | |
from tempfile import NamedTemporaryFile | |
template = """ | |
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>{swf_name}</title> | |
</head> | |
<body> | |
<object width="{width}" height="{height}"> | |
<embed src="{swf_path}" type="application/x-shockwave-flash" width="{width}" height="{height}"> | |
</object> | |
</body> | |
</html> | |
""" | |
def get_screen_resolution(): | |
output = subprocess.Popen('xrandr | grep "\*" | cut -d" " -f4',shell=True, stdout=subprocess.PIPE).communicate()[0] | |
resolution = output.split()[0].split(b'x') | |
return {"width": int(resolution[0]), "height": int(resolution[1])} | |
def create_tempfile(swf_path, width, height): | |
basename = os.path.basename(swf_path) | |
f = NamedTemporaryFile(prefix="swf_" + basename + "_", suffix=".htm", | |
delete = False, mode="w") | |
html = template.format(swf_path = swf_path, | |
swf_name = basename, | |
width = width, | |
height = height) | |
f.write(html) | |
f.close() | |
print(swf_path, "wrapped by", f.name) | |
return f.name | |
def open_tempfile(tempfile_path): | |
subprocess.Popen(["xdg-open", tempfile_path]) | |
print("launched", tempfile_path) | |
def main(files_list): | |
scr_resolution = get_screen_resolution() | |
width = int(scr_resolution.get("width")*2/3) | |
height = int(scr_resolution.get("height")*2/3) | |
for swf_path in files_list: | |
tmp_path = create_tempfile(swf_path, width, height) | |
open_tempfile(tmp_path) | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. I made a small change to support relative files when I notice it wasn't working in command line: