Created
April 17, 2020 23:57
-
-
Save odigity/107fca82a7f552ecc38d4f7cde4cd5ae to your computer and use it in GitHub Desktop.
A tool for viewing/modifying the basename inside a Faceswap alignments.fsa file.
This file contains hidden or 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
#!/usr/bin/env python3 | |
import argparse | |
import pickle | |
import re | |
import zlib | |
def readfrom( fsafile ): | |
return pickle.loads( | |
zlib.decompress( | |
open( fsafile, 'rb' ).read() | |
) | |
) | |
def writeto( fsafile, fsadict ): | |
open( fsafile, 'wb' ).write( | |
zlib.compress( | |
pickle.dumps(fsadict) | |
) | |
) | |
def split_fsakey( fsakey ): | |
basename = re.search( '^(.+)_\d+\.png$', fsakey ).group(1) | |
facename = re.search( '(_\d+\.png)$', fsakey ).group(1) | |
return ( basename, facename ) | |
def basename_of_fsadict( fsadict ): | |
fsakey1 = list(fsadict.keys())[0] | |
return split_fsakey(fsakey1)[0] | |
parser = argparse.ArgumentParser(description='TODO') | |
parser.add_argument( 'fsafile' ) | |
parser.add_argument( '-r', '--rename' ) | |
args = parser.parse_args() | |
fsadict = readfrom(args.fsafile) | |
basename = basename_of_fsadict(fsadict) | |
if args.rename: | |
fsadict2 = {} | |
for oldkey in fsadict: | |
newkey = args.rename + split_fsakey(oldkey)[1] | |
fsadict2[newkey] = fsadict[oldkey] | |
writeto( args.fsafile, fsadict2 ) | |
else: | |
print( basename ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment