from pprint import pprint
import pickle
import os

with open('/home/thebears/Web/Nuggets/SearchInterface/SearchBackend/crap.p','rb') as ff:
    cc = pickle.load(ff)


tstamp, folder_scores  = cc[1],cc[0]


for i in range(100):
    target_tstamp = tstamp + i

    matching_file = None
    next_file = None
    for video_file in folder_scores['videos']:
        start_time = video_file['start_time']
        end_time = video_file['end_time']

        if target_tstamp > start_time and target_tstamp < end_time:
            matching_file = video_file
        if start_time > target_tstamp and next_file is None:
            next_file = video_file


    if matching_file is not None:
        fname = matching_file['file_name']
        offset = target_tstamp - matching_file['start_time']
    else:
        fname = 'None Found'
        offset = -1
        if next_file is not None:
            fname = next_file['file_name']
            offset = 0

    web_name = 'media/'+os.path.basename(fname)
    ret_val = dict(full_path = fname, path=web_name, timeoffset = offset)
    pprint(ret_val)
    pprint('-----------------------------------')
