Ejemplo n.º 1
0
def test_find_hash(outro_file):
    hashes = list(credits.hash_file(outro_file))
    img_file = os.path.join(TEST_DATA, 'out8.jpg')
    img_hash, frame, pos = next(credits.hash_file(img_file))

    needels, files = credits.hash_image_folder(TEST_DATA)
    for stack_hash, stack_ms, stacknr, needel_ms, needelnr, stacknr in credits.find_hashes(
            needels, hashes):
        assert stack_hash == img_hash and files[needelnr]
Ejemplo n.º 2
0
def test_find_where_a_img_is_in_video(outro_file):
    img_file = os.path.join(TEST_DATA, 'out8.jpg')

    h, t = next(credits.hash_file(img_file))

    v_hashes = list(credits.hash_file(outro_file))

    for vh, i in v_hashes:
        if vh == h:
            # Check that the image if between 47 sec and 49 sec.
            assert i > 47464 and i < 49425
Ejemplo n.º 3
0
def test_most_common(intro_file):

    intro_hashes = list(credits.hash_file(intro_file))

    def mc():

        l = []
        for hash_, t in intro_hashes:
            d = {}
            h = tuple(hash_)
            if h not in d:
                d[h] = 'name'
                d['pos'] = []
                d['pos'].append(t)
                d['size'] = 1
            else:
                d['size'] += 1
                d['pos'].append(t)

            l.append(d)

        return l

    t = mc()
    f = sorted(t, key=itemgetter('size'))
    print(list(f)[0])
Ejemplo n.º 4
0
def test_find_partial_video_inside_another(intro_file):
    # This is cut from the one minute mark of intro_file
    # and last for 2 min
    part = os.path.join(TEST_DATA, 'part.mkv')

    # Check the parts file by file.
    part_hashes = list(credits.hash_file(part, frame_range=False))
    intro_hashes = list(credits.hash_file(intro_file, frame_range=True))

    for straw, sms, i, pms, _, z in credits.find_hashes(part_hashes,
                                                        intro_hashes,
                                                        no_dupe_frames=True):
        sms_sec = math.floor(sms / 1000)
        pms_sec = math.floor(pms / 1000)

        assert sms_sec >= 60 and sms_sec <= 180
        assert pms_sec >= 0 and pms_sec <= 120
        print('%r %s %s' % (straw, misc.sec_to_hh_mm_ss(sms_sec),
                            misc.sec_to_hh_mm_ss(pms_sec)))