from PIL import Image
import os, shutil

frames_folder = "frames/"
out_folder = "maps/"

map_number = 0
i = 0
for f in os.listdir(frames_folder):
	if f.lower().endswith(".bmp"):
		im = Image.open(os.path.join(frames_folder, f))
		pix = im.load() # https://stackoverflow.com/a/138260/1172196
		if pix[0,0] != (92, 148, 252): 
			# during the fade in the map isnt black,
			# so this makes sure the top left corner of the screen is that vivid blue color
			continue
		first_square = pix[26,58] 
		last_square = pix[173,204]
		# if the first and last squares of the map aren't black, 
		# and there has been 100 frames since last match, then it could be a map!
		if first_square != (0, 0, 0) and last_square != (0, 0, 0) and i >= 100: 
			print map_number, first_square, last_square, f
			# copy 
			new_filename = "%03d.bmp" % map_number
			shutil.copy(os.path.join(frames_folder, f), os.path.join(out_folder, new_filename))
			i = 0 
			map_number += 1
		i += 1