From cae423e74d4fd3106c1f9a23b8a17ac7a475213c Mon Sep 17 00:00:00 2001 From: cameron Date: Mon, 4 Apr 2022 03:58:21 -0700 Subject: [PATCH 1/5] replaced regex - keep track of position when matching instead --- main.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index c41ab61..d952d6d 100644 --- a/main.py +++ b/main.py @@ -50,30 +50,30 @@ def create_video_fingerprint(path): return video_fingerprint -def get_equal_frames(print1, print2): +def get_equal_frames(print1, print2, start1, start2): equal_frames = [] + for j in range(0, int(len(print1) / 16 / check_frame)): if print1[j * 16 * check_frame:j * 16 * check_frame + 16] == print2[ - j * 16 * check_frame:j * 16 * check_frame + 16]: - equal_frames.append(print1[j * 16 * check_frame:j * 16 * check_frame + 16]) + j * 16 * check_frame:j * 16 * check_frame + 16]: + equal_frames.append(((int(start1 + (j * check_frame)), int(start2 + (j * check_frame))), print1[j * 16 * check_frame:j * 16 * check_frame + 16])) return equal_frames def get_start_end(print1, print2): highest_equal_frames = [] for k in range(0, int(len(print1) / 16 / check_frame)): - equal_frames = get_equal_frames(print1[-k * 16 * check_frame:], print2) + equal_frames = get_equal_frames(print1[-k * 16 * check_frame:], print2, (len(print1) / 16) - (k * check_frame), 0) if len(equal_frames) > len(highest_equal_frames): highest_equal_frames = equal_frames - equal_frames = get_equal_frames(print1, print2[k * 16 * check_frame:]) + equal_frames = get_equal_frames(print1, print2[k * 16 * check_frame:], 0, k * check_frame) if len(equal_frames) > len(highest_equal_frames): highest_equal_frames = equal_frames - regex_string = ".*?".join(highest_equal_frames) + "){1,}" - regex_string = regex_string[:-21] + '(' + regex_string[-21:] - p = re.compile(regex_string) - search = re.search(p, "".join(print1)) - search2 = re.search(p, "".join(print2)) - return (int(search.start() / 16), int(search.end() / 16)), (int(search2.start() / 16), int(search2.end() / 16)) + + if highest_equal_frames: + return (highest_equal_frames[0][0][0], highest_equal_frames[-1][0][0]), (highest_equal_frames[0][0][1], highest_equal_frames[-1][0][1]) + else: + return (0, 0), (0, 0) def get_or_create_fingerprint(file): From 3da7afe2cca2cc7a456801ad3828a7740a6035f3 Mon Sep 17 00:00:00 2001 From: cameron Date: Mon, 4 Apr 2022 04:06:11 -0700 Subject: [PATCH 2/5] fix --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index d952d6d..8a88da4 100644 --- a/main.py +++ b/main.py @@ -62,11 +62,11 @@ def get_equal_frames(print1, print2, start1, start2): def get_start_end(print1, print2): highest_equal_frames = [] - for k in range(0, int(len(print1) / 16 / check_frame)): - equal_frames = get_equal_frames(print1[-k * 16 * check_frame:], print2, (len(print1) / 16) - (k * check_frame), 0) + for k in range(0, int(len(print1) / 16)): + equal_frames = get_equal_frames(print1[-k * 16:], print2, (len(print1) / 16) - k, 0) if len(equal_frames) > len(highest_equal_frames): highest_equal_frames = equal_frames - equal_frames = get_equal_frames(print1, print2[k * 16 * check_frame:], 0, k * check_frame) + equal_frames = get_equal_frames(print1, print2[k * 16:], 0, k * check_frame) if len(equal_frames) > len(highest_equal_frames): highest_equal_frames = equal_frames From 0729291031d4771516b22b0c8df3f34cc03bee10 Mon Sep 17 00:00:00 2001 From: cameron Date: Mon, 4 Apr 2022 04:07:51 -0700 Subject: [PATCH 3/5] fix --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index e112063..f2a169e 100644 --- a/main.py +++ b/main.py @@ -68,7 +68,7 @@ def get_start_end(print1, print2): equal_frames = get_equal_frames(print1[-k * 16:], print2, (len(print1) / 16) - k, 0) if len(equal_frames) > len(highest_equal_frames): highest_equal_frames = equal_frames - equal_frames = get_equal_frames(print1, print2[k * 16:], 0, k * check_frame) + equal_frames = get_equal_frames(print1, print2[k * 16:], 0, k) if len(equal_frames) > len(highest_equal_frames): highest_equal_frames = equal_frames From ce36682cd0bb33c28fcddb3982f048b20b34178d Mon Sep 17 00:00:00 2001 From: cameron Date: Fri, 8 Apr 2022 04:29:31 -0700 Subject: [PATCH 4/5] start at the first frame so [-k:] is actually back to front --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index f2a169e..edcf93e 100644 --- a/main.py +++ b/main.py @@ -64,7 +64,7 @@ def get_equal_frames(print1, print2, start1, start2): def get_start_end(print1, print2): highest_equal_frames = [] - for k in range(0, int(len(print1) / 16)): + for k in range(1, int(len(print1) / 16)): equal_frames = get_equal_frames(print1[-k * 16:], print2, (len(print1) / 16) - k, 0) if len(equal_frames) > len(highest_equal_frames): highest_equal_frames = equal_frames From 9ffe7578d2b3d245649aa26758000241f5576851 Mon Sep 17 00:00:00 2001 From: cameron Date: Fri, 8 Apr 2022 04:51:04 -0700 Subject: [PATCH 5/5] guard against index out of bounds when comparing fingerprints --- main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index edcf93e..604cb1e 100644 --- a/main.py +++ b/main.py @@ -63,9 +63,14 @@ def get_equal_frames(print1, print2, start1, start2): def get_start_end(print1, print2): + if print1 == '' or print2 == '': + return (0, 0), (0, 0) + + search_range = min(len(print1), len(print2)) + highest_equal_frames = [] - for k in range(1, int(len(print1) / 16)): - equal_frames = get_equal_frames(print1[-k * 16:], print2, (len(print1) / 16) - k, 0) + for k in range(1, int(search_range / 16)): + equal_frames = get_equal_frames(print1[-k * 16:], print2, int(search_range / 16) - k, 0) if len(equal_frames) > len(highest_equal_frames): highest_equal_frames = equal_frames equal_frames = get_equal_frames(print1, print2[k * 16:], 0, k)