scene_stamps[show][episode_name] = None # retrieve time_stamps and scene_stamps from disk copies (if they exist) for show in list_of_shows: for episode_name in video_file_names[show]: time_stamps_path = DIR_STAMPS[show]+'/'+episode_name+'_timestamps.json' scene_stamps_path = DIR_STAMPS[show]+'/'+episode_name+'_scenestamps.json' try: with open(time_stamps_path, 'r') as fp1, open(scene_stamps_path, 'r') as fp2: time_stamps[show][episode_name] = json.load(fp1) scene_stamps[show][episode_name] = json.load(fp2) except IOError: # if no time_stamps/scene_stamps exist, fetch them and store a copy on disk # the get scene_stamps function gets time and scene_stamps episode_path = DIR_VIDS[show]+'/'+episode_name+'.mp4' result = preprocessor.get_scene_stamps(episode_path) time_stamps[show][episode_name] = result['time_stamps'] scene_stamps[show][episode_name] = result['scene_stamps'] # json converts tuples into lists with open(time_stamps_path, 'w') as fp1, open(scene_stamps_path, 'w') as fp2: json.dump(time_stamps[show][episode_name], fp1) json.dump(scene_stamps[show][episode_name], fp2) # process and store the plot on the drive plot_sentences = {} for show in list_of_shows: plot_sentences[show] = {} for show in list_of_shows: for episode_name in video_file_names[show]: # storing the processed part in json
"BCS1E08", "BCS1E09", "better.call.saul.110.hdtv-lol", ] time_stamps, scene_stamps = [], [] for vid_file in video_file_names: time_stamps_path = DIR_STAMPS + "/" + vid_file + "_proc_ts.json" scene_stamps_path = DIR_STAMPS + "/" + vid_file + "_proc_ss.json" try: with open(time_stamps_path, "r") as fp1, open(scene_stamps_path, "r") as fp2: time_stamps.append(json.load(fp1)) scene_stamps.append(json.load(fp2)) except IOError: with open(time_stamps_path, "w") as fp1, open(scene_stamps_path, "w") as fp2: t1, t2 = get_scene_stamps(DIR_VIDS + "/" + vid_file + ".mp4") time_stamps.append(t1) scene_stamps.append(t2) json.dump(time_stamps[-1], fp1) json.dump(scene_stamps[-1], fp2) plot_sentences = [] for plot in file_names: # storing the processed part in json file_path = DIR_PLOTS + "/" + plot + "_proc_plot.json" try: with open(file_path, "r") as fp: plot_sentences.append(json.load(fp)) except IOError: with open(file_path, "w") as fp: plot_sentences.append(fetch_plot_data(DIR_PLOTS + "/" + plot + "_plot.txt"))