Recently I needed to be able to determine the dimensions of SWF (Flash animation) files so I could embed them properly on a web page but I couldn’t immediately find something useful with Google that would perform the task. I am aware of the Hachoir project, but it seemed a bit overkill for my simple use case and a quick try with hachoir-metadata failed to parse my particular SWF file.
Luckily the container section of the SWF file format (which contains the metadata) is rather simple and writing a parser for it turned out to be a nice distraction from my normal duties. The result is hexagonit.swfheader which is a minimal package (no dependencies outside the standard library) that provides a single function that parses SWF files and returns the metadata.
The package comes also with a console script that you can use on the command line to quickly introspect local SWF files. In a buildout you’ll need to use the zc.recipe.egg:scripts recipe to get the script installed.
3 Comments
You may want to note that this requires at least Python 2.4, or include a fallback for using “reversed”.
Hi justin and thanks for the feedback.
I just pushed hexagonit.swfheader 1.0.1 to the PyPI which is compatible with Python 2.3. Unfortunately 2.3 doesn’t have the doctest.DocFileSuite() function so the test runner is currently broken on 2.3.
Thanks for this. I was in the exact same predicament. You’re a lifesaver.