def correct_video(state, file_path, file_id, local, ffmpeg): """Function that deals with errors in videos or corrupted videos.""" folder_path = os.path.dirname(file_path) if(state == 'corrupt'): # Move the file into corrupted folder if(not os.path.exists(os.path.join(folder_path, 'corrupted'))): os.makedirs(os.path.join(folder_path, 'corrupted')) os.rename( file_path, os.path.join(folder_path, 'corrupted', os.path.basename(file_path))) elif(state == 'error'): # Reencode if(not os.path.exists(os.path.join(folder_path, 'errors'))): os.makedirs(os.path.join(folder_path, 'errors')) new_file_path = os.path.join( folder_path, 'errors', os.path.basename(file_path)) os.rename(file_path, new_file_path) temp_vid = Video(file_id, new_file_path, category='error') temp_vid.populate_video_details(local) temp_vid.baseConvertVideo( ffmpeg, local, os.path.splitext(file_path)[0] + '.mp4')