Skip to content

Instantly share code, notes, and snippets.

@clsource
Created August 14, 2012 02:27
Show Gist options
  • Save clsource/3345818 to your computer and use it in GitHub Desktop.
Save clsource/3345818 to your computer and use it in GitHub Desktop.
Extract all sound within SWF File
#!/usr/bin/env python
# Filename: soundex.py
# Based on the code by Jonathan Wong http://hawflakes.unoc.net/?p=182
# by ClSource
# requires swfextract
# This program takes a swf and extract all the sounds within.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar <[email protected]>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO
import commands,sys,re
def parse(filename):
# check filename for .swf extension
fileprefix = filename[0:filename.find('.swf')]
# open file
status, output = commands.getstatusoutput("swfextract %s" % (filename,))
# If status was wrong, terminate.
if status != 0:
print "Filetype not supported!"
raise TypeError
print output
# find "Sounds: ID(s)"
sound_identifier = "Sounds: ID(s)"
start = output.find(sound_identifier)
sound_extract = []
if start:
start += len(sound_identifier)+1
sound_end = output.find("[-F]",start)
# print start,sound_end
sound_extract = output[start:sound_end-2].replace(" ","")
# now extract all the data
print # New line
print "swfextract %s -P -s %s" % (filename,sound_extract)
print # New line
sounds = sound_extract.split(",")
for sound in sounds:
print "Extracting Sound:",sound
print "swfextract %s -P -s %s -o %s.wav" %(filename,sound,sound)
status,output = commands.getstatusoutput(("swfextract %s -P -s %s -o %s.wav" %(filename,sound,sound)))
if status == 0:
print "Success!",output
else:
print "Error",output
print # New Line
return sound_extract
if __name__=="__main__":
try:
sounds = parse(sys.argv[1])
except:
print "Usage: soundex <filename>.swf"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment