#Goes through each video and sees if it is corrupted or not. If it is, remove it.

import skvideo.io
import numpy as np
import os
import sys

def test_videos():
    data_dirs = '/home-2/fyu12@jhu.edu/scratch/ReiterLab/cataract_phase_separated/'
    sub_dirs = os.listdir(data_dirs)
    for sub in sub_dirs:
        phase_dir = data_dirs + sub + '/'
        vids = os.listdir(phase_dir)
        for vid_name in vids:
            if vid_name[-3:] == 'avi':
                try:
                    vid = skvideo.io.FFmpegReader(phase_dir + vid_name)
                except ValueError:
                    print('Unable to open ' + vid_name + '. Removing.')
                    os.remove(phase_dir+vid_name)
    return 'Process Complete'    

def main():
    print(test_videos())

if __name__ == "__main__":
    main()
