Mercurial > ec-dotfiles
changeset 100:06ab5f0f9c28
dumpshot: mindlessly dumps shot*.png files produced by mplayer.
author | Edho Prima Arief <edho@myconan.net> |
---|---|
date | Tue, 19 Jul 2011 15:43:36 +0700 |
parents | 97e24e89388f |
children | a1c6b40a535f |
files | bin/dumpshot |
diffstat | 1 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/dumpshot Tue Jul 19 15:43:36 2011 +0700 @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import sys, os, re + +def is_shotfile(inpath): + finpath = os.path.basename(inpath) + return (finpath[-4:] == ".png") and (finpath[:4] == "shot") + +def main(source_files, targetdir): + max_shot=0 + try: + current_files=os.listdir(targetdir) + for current_file in current_files: + if is_shotfile(current_file): + file_shot = int(re.findall("\d+", current_file)[0]) + if file_shot > max_shot: + max_shot = file_shot + for source_file in source_files: + if is_shotfile(source_file): + max_shot += 1 + target_file = os.path.join(targetdir, "shot%04d.png" % max_shot) + print "Moving: %s => %s" % (source_file, target_file) + os.rename(source_file, target_file) + except: + print "(%s: %s)" % (sys.exc_type, sys.exc_value) + +if __name__ == "__main__": + main(sys.argv[2:], sys.argv[1])