Last active
December 26, 2015 12:39
-
-
Save mazesoul87/7152211 to your computer and use it in GitHub Desktop.
获取flash宽高的python脚本
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
#encoding:utf-8 | |
__author__ = "Forrest Liu" | |
import os | |
import zlib | |
import tempfile | |
import binascii | |
W_H_RULELIST = {"50":[[0, 10], [5, 10], 5], "58":[[1, 40], [6, 10], 6], | |
"60":[[1, 10], [7, 10], 6], "68":[[2, 40], [8, 10], 7], | |
"70":[[2, 10], [9, 10], 7], "78":[[3, 40], [10, 10], 8], | |
"80":[[3, 10], [11, 10], 8], "88":[[2, 40], [12, 10], 9]} | |
def get_swf_size(fobj): | |
_m, path = tempfile.mkstemp() | |
tmpfil = open(path, "r+b") | |
tmpfil.write(fobj.read(8)) | |
fobj.seek(0) | |
_type = fobj.read(3) | |
fobj.seek(8) | |
if _type == "CWS": | |
main_data = zlib.decompress(fobj.read()) | |
elif _type == "FWS": | |
main_data = fobj.read() | |
else: | |
return () | |
tmpfil.write(main_data[:13]) | |
tmpfil.seek(8) | |
ctrl_code = binascii.hexlify(tmpfil.read(1)) | |
try: | |
postion = W_H_RULELIST[ctrl_code] | |
except: | |
return () | |
_length = postion[2] | |
w_h_info = [] | |
for i in range(_length): | |
tmpfil.seek(i + 9) | |
_temp = binascii.hexlify(tmpfil.read(1)) | |
w_h_info.append(_temp) | |
w_h_info = "".join(w_h_info) | |
width = int(w_h_info[postion[0][0]:postion[0][0] + 4], 16) / postion[0][1] | |
height = int(w_h_info[postion[1][0]:postion[1][0] + 4], 16) / postion[1][1] | |
tmpfil.close() | |
os.remove(tmpfil) | |
return (width, height) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment