swftools-common
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swftools-common] SWF python module: no attribute polling?


From: Daichi Shinozaki
Subject: Re: [Swftools-common] SWF python module: no attribute polling?
Date: Thu, 20 Jan 2005 23:44:41 +0900
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040616

Hi,

michael geary wrote:
I'm trying to get some info about a loaded SWF.
> When I'm in the python interpreter, I can simply
type my swf variable and get a dump of some info:

 >>> swf
File size       325414
Movie width     664
Movie height    634
Frame rate      12.0
Frame count     32

but how can I get this information programmatically?

You can get the frame rate of a loaded movie using
python>>> swf = SWF.load("foo.swf")
python>>> swf.fps

I think rest of properties is not accessible from the python module.
Here is the patch to SWF.c version 0.6.2.

--- lib/python/SWF.c.orig       Sat Aug 14 18:15:18 2004
+++ lib/python/SWF.c    Thu Jan 20 15:07:02 2005
@@ -49,7 +49,7 @@

 typedef struct {
     PyObject_HEAD
-    SWF swf; //swf.firstTag ist not used
+    SWF swf; //swf.firstTag is not used
     PyObject*taglist;
     char*filename;
 } SWFObject;
@@ -301,6 +301,18 @@
        Py_INCREF(ret);
mylog(" %08x(%d) swf_getattr %s = %08x(%d)\n", (int)self, self->ob_refcnt, a, ret, ret->ob_refcnt);
        return ret;
+    } else if(!strcmp(a, "filesize")) {
+       int s = swf->swf.fileSize;
+       return Py_BuildValue("i", s);
+    } else if(!strcmp(a, "width")) {
+       int w = (swf->swf.movieSize.xmax - swf->swf.movieSize.xmin) / 20;
+       return Py_BuildValue("i", w);
+    } else if(!strcmp(a, "height")) {
+       int h =  (swf->swf.movieSize.ymax - swf->swf.movieSize.ymin) / 20;
+       return Py_BuildValue("i", h);
+    } else if(!strcmp(a, "framecount")) {
+       int f = swf->swf.frameCount;
+       return Py_BuildValue("i", f);
     }

     ret = Py_FindMethod(swf_functions, self, a);
@@ -438,4 +450,3 @@
        to keep it around */
     // free(all_methods)
 }
-

By applying this patch, properties(movie width,height, frame rate,count)
become available.

This is a (useless) example:

        0         [swfinfo.py]
_________\/______ Please snip and save _____________________
         /\
        0
#!/usr/bin/env python

import SWF
import sys

if len(sys.argv) < 2:
    print "Usage: " + sys.argv[0] + " foo.swf"
    sys.exit()

#try:
swf = SWF.load(sys.argv[1])

# print swf

result = "File size\t" + str(swf.filesize) + \
         "\nMovie width\t" + str(swf.width) + \
         "\nMovie height\t" + str(swf.height) + \
         "\nFrame rate\t" + str(swf.fps) + \
         "\nFrame count\t" + str(swf.framecount) + \
         "\n\n" + \
         "done."
print result
______________________________________

Regards,

--
Daichi Shinozaki
SHIELD.JP Admin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]