diff --git a/ptulsconv/footage.py b/ptulsconv/footage.py index 0d70bd0..89ef54d 100644 --- a/ptulsconv/footage.py +++ b/ptulsconv/footage.py @@ -1,20 +1,18 @@ from fractions import Fraction import re -import math -from collections import namedtuple from typing import Optional def footage_to_seconds(footage: str) -> Optional[Fraction]: - m = re.match(r'(\d+)\+(\d+)(\.\d+)?') + m = re.match(r'(\d+)\+(\d+)(\.\d+)?', footage) if m is None: return None - feet, frames = m.groups() + feet, frames, _ = m.groups() feet, frames = int(feet), int(frames) fps = 24 frames_per_foot = 16 - total_frames = feet * 16 + frames + total_frames = feet * frames_per_foot + frames - return Fraction(total_frames, fps) \ No newline at end of file + return Fraction(total_frames, fps) diff --git a/tests/unittests/test_footage.py b/tests/unittests/test_footage.py new file mode 100644 index 0000000..a1bdb57 --- /dev/null +++ b/tests/unittests/test_footage.py @@ -0,0 +1,15 @@ +import unittest +from ptulsconv import footage + +class TestFootage(unittest.TestCase): + def test_basic_footage(self): + r1 = "90+0" + f1 = footage.footage_to_seconds(r1) + self.assertEqual(float(f1 or 0), 60.0) + + def test_feet_and_frames(self): + r1 = "1+8" + f1 = footage.footage_to_seconds(r1) + self.assertEqual(float(f1 or 0), 1.0) + +