#!/bin/python2.7

import argparse
import re
import random
import struct
from itertools import chain

#################
### ARGUMENTS ###
#################

parser = argparse.ArgumentParser(add_help=True)
parser.add_argument("file", help="input file")
parser.add_argument("-o", "--output", help="output file")
parser.add_argument('-m', "--mode", action='store', dest='modevalue',help='choose mode')
parser.add_argument('-c', action='store', dest='countframes',help='var1', default=1)
parser.add_argument('-n', action='store', dest='positframes',help='var2', default=1)
parser.add_argument('-s', action='store', dest='simple_value',
                    help='Store a simple value')

args = parser.parse_args()

filein = args.file
fileout = args.output
mode = args.modevalue
countframes = args.countframes
positframes = args.positframes

####################
### OPENING FILE ###
####################

#open .avi file as binary
with open (filein, 'rb') as f: 
	## split the content at "idx1"
	a = f.read().split('idx1', 1)
	a1 = a[1]

	## get the length of the index and store it
	a1, idxl = a1[4:], a1[:4]

	## get the first iframe and store it
	n = 16
	iframe, a1 = a1[:n], a1[n:] 
	
	## put all frames in array
	b = [a1[i:i+n] for i in range(0, len(a1), n)] 
	
	## take out all of the sound frames cuz who gives a fuck
	sframeregex = re.compile(b'01wb\x10\x00\x00\x00.{8}')
	b = [x for x in b if not re.match(sframeregex,x)]

	## calculate number of frames
	c = len(b)

#########################
### OPERATIONS TO IDX ###
#########################

	### MODE - SHUFFLE 
	#####################

	if mode == "shuffle":
		g = random.sample(b,c)

	### MODE - DELETE IFRAMES
	###########################

	if mode == "ikill":
		iframeregex = re.compile(b'00dc\x10\x00\x00\x00.{8}')
		g = [x for x in b if not re.match(iframeregex,x)]

	### MODE - BLOOM
	##################

	if mode == "bloom":
		## bloom options
		repeat = int(countframes)	
		frame = int(positframes)
	
		## split list
		lista = b[:frame]
		listb = b[frame:]

		## rejoin list with bloom
		g = lista + ([b[frame]]*repeat) + listb

	### MODE - P PULSE
	##################
	
	if mode == "pulse":
		pulselen = int(countframes)
		pulseryt = int(positframes)
	
		d = [[x for j in range(pulselen)] if not i%pulseryt else x for i,x in enumerate(b)]
		e = [item for sublist in d for item in sublist]
		f = ''.join(e)
		g = [f[i:i+n] for i in range(0, len(f), n)] 
	
	##just having fun by adding this at the end of the bloom
	#d = random.sample(d,c + repeat)

########################
### FIX INDEX LENGTH ###
######################## 

	print "old index size : " + str(c + 1) + " frames"
	hey = len(g)*16
	print "new index size : " + str((hey/16) + 1) + " frames"

	## convert it to packed data
	idxl = struct.pack('<I',hey)

###################
### SAVING FILE ###
###################

	## rejoin the whole thing
	data = ''.join(a[0] + "idx1" + idxl + iframe + ''.join(g)) 
	f = open(fileout, 'wb')
	f.write(data)
	f.close()

@@ -1612,17 +1612,19 @@
 fle%22:%0A%09%09
-g
+idx
  = rando
@@ -1770,25 +1770,27 @@
 x00.%7B8%7D')%0A%09%09
-g
+idx
  = %5Bx for x 
@@ -2051,17 +2051,19 @@
 bloom%0A%09%09
-g
+idx
  = lista
@@ -2221,17 +2221,19 @@
 es)%0A%09%0A%09%09
-d
+idx
  = %5B%5Bx f
@@ -2309,17 +2309,19 @@
 e(b)%5D%0A%09%09
-e
+idx
  = %5Bitem
@@ -2336,17 +2336,19 @@
 list in 
-d
+idx
  for ite
@@ -2363,17 +2363,19 @@
 list%5D%0A%09%09
-f
+idx
  = ''.jo
@@ -2381,19 +2381,25 @@
 oin(
-e
+idx
 )%0A%09%09
-g
+idx
  = %5B
-f
+idx
 %5Bi:i
@@ -2424,17 +2424,19 @@
 (0, len(
-f
+idx
 ), n)%5D %0A
@@ -2670,17 +2670,19 @@
 y = len(
-g
+idx
 )*16%0A%09pr
@@ -2943,17 +2943,19 @@
 ''.join(
-g
+idx
 )) %0A%09f =

Create tomato.py