6363
6464import math
6565import typing as ty
66+ import warnings
6667from dataclasses import dataclass
6768from enum import Enum
6869from fractions import Fraction
@@ -220,28 +221,32 @@ def frame_num(self) -> ty.Optional[int]:
220221 def framerate (self ) -> ty .Optional [int ]:
221222 return self ._framerate
222223
223- # TODO(v0.7): Mark this as deprecated (use frame_num instead).
224224 def get_frames (self ) -> int :
225- """Get the current time/position in number of frames. This is the
226- equivalent of accessing the self.frame_num property (which, along
227- with the specified framerate, forms the base for all of the other
228- time measurement calculations, e.g. the :meth:`get_seconds` method).
225+ """[DEPRECATED] Get the current time/position in number of frames.
229226
230- If using to compare a :class:`FrameTimecode` with a frame number,
231- you can do so directly against the object (e.g. ``FrameTimecode(10, 10.0) <= 10``).
227+ Use the `frame_num` property instead.
232228
233- Returns:
234- int: The current time in frames (the current frame number).
229+ :meta private:
235230 """
231+ warnings .warn (
232+ "get_frames() is deprecated, use the `frame_num` property instead." ,
233+ DeprecationWarning ,
234+ stacklevel = 2 ,
235+ )
236236 return self .frame_num
237237
238- # TODO(v0.7): Mark this as deprecated (use framerate instead).
239238 def get_framerate (self ) -> float :
240- """Get Framerate: Returns the framerate used by the FrameTimecode object.
239+ """[DEPRECATED] Get Framerate: Returns the framerate used by the FrameTimecode object.
241240
242- Returns:
243- float: Framerate of the current FrameTimecode object, in frames per second.
241+ Use the `framerate` property instead.
242+
243+ :meta private:
244244 """
245+ warnings .warn (
246+ "get_framerate() is deprecated, use the `framerate` property instead." ,
247+ DeprecationWarning ,
248+ stacklevel = 2 ,
249+ )
245250 return self .framerate
246251
247252 # TODO(v0.7): Figure out how to deal with VFR here.
@@ -258,20 +263,33 @@ def equal_framerate(self, fps) -> bool:
258263 # TODO(v0.7): Support this comparison in the case FPS is not set but a timecode is.
259264 return math .fabs (self .framerate - fps ) < MAX_FPS_DELTA
260265
261- # TODO(v0.7): Add a `seconds` property to replace this and deprecate the existing one.
266+ @property
267+ def seconds (self ) -> float :
268+ """The frame's position in number of seconds."""
269+ if self ._timecode :
270+ return self ._timecode .seconds
271+ # Assume constant framerate if we don't have timing information.
272+ return float (self ._frame_num ) / self ._framerate
273+
262274 def get_seconds (self ) -> float :
263- """Get the frame's position in number of seconds.
275+ """[DEPRECATED] Get the frame's position in number of seconds.
276+
277+ Use the `seconds` property instead.
264278
265279 If using to compare a :class:`FrameTimecode` with a frame number,
266280 you can do so directly against the object (e.g. ``FrameTimecode(10, 10.0) <= 1.0``).
267281
268282 Returns:
269283 float: The current time/position in seconds.
284+
285+ :meta private:
270286 """
271- if self ._timecode :
272- return self ._timecode .seconds
273- # Assume constant framerate if we don't have timing information.
274- return float (self ._frame_num ) / self ._framerate
287+ warnings .warn (
288+ "get_seconds() is deprecated, use the `seconds` property instead." ,
289+ DeprecationWarning ,
290+ stacklevel = 2 ,
291+ )
292+ return self .seconds
275293
276294 def get_timecode (self , precision : int = 3 , use_rounding : bool = True ) -> str :
277295 """Get a formatted timecode string of the form HH:MM:SS[.nnn].
@@ -285,7 +303,7 @@ def get_timecode(self, precision: int = 3, use_rounding: bool = True) -> str:
285303 str: The current time in the form ``"HH:MM:SS[.nnn]"``.
286304 """
287305 # Compute hours and minutes based off of seconds, and update seconds.
288- secs = self .get_seconds ()
306+ secs = self .seconds
289307 hrs = int (secs / _SECONDS_PER_HOUR )
290308 secs -= hrs * _SECONDS_PER_HOUR
291309 mins = int (secs / _SECONDS_PER_MINUTE )
@@ -438,7 +456,7 @@ def __eq__(self, other: ty.Union[int, float, str, "FrameTimecode"]) -> "FrameTim
438456 if isinstance (other , int ):
439457 return self ._frame_num == other
440458 elif isinstance (other , float ):
441- return self .get_seconds () == other
459+ return self .seconds == other
442460 elif isinstance (other , str ):
443461 return self ._frame_num == self ._parse_timecode_string (other )
444462 elif isinstance (other , FrameTimecode ):
@@ -462,7 +480,7 @@ def __lt__(self, other: ty.Union[int, float, str, "FrameTimecode"]) -> bool:
462480 if isinstance (other , int ):
463481 return self ._frame_num < other
464482 elif isinstance (other , float ):
465- return self .get_seconds () < other
483+ return self .seconds < other
466484 elif isinstance (other , str ):
467485 return self ._frame_num < self ._parse_timecode_string (other )
468486 elif isinstance (other , FrameTimecode ):
@@ -481,7 +499,7 @@ def __le__(self, other: ty.Union[int, float, str, "FrameTimecode"]) -> bool:
481499 if isinstance (other , int ):
482500 return self ._frame_num <= other
483501 elif isinstance (other , float ):
484- return self .get_seconds () <= other
502+ return self .seconds <= other
485503 elif isinstance (other , str ):
486504 return self ._frame_num <= self ._parse_timecode_string (other )
487505 elif isinstance (other , FrameTimecode ):
@@ -500,7 +518,7 @@ def __gt__(self, other: ty.Union[int, float, str, "FrameTimecode"]) -> bool:
500518 if isinstance (other , int ):
501519 return self ._frame_num > other
502520 elif isinstance (other , float ):
503- return self .get_seconds () > other
521+ return self .seconds > other
504522 elif isinstance (other , str ):
505523 return self ._frame_num > self ._parse_timecode_string (other )
506524 elif isinstance (other , FrameTimecode ):
@@ -519,7 +537,7 @@ def __ge__(self, other: ty.Union[int, float, str, "FrameTimecode"]) -> bool:
519537 if isinstance (other , int ):
520538 return self ._frame_num >= other
521539 elif isinstance (other , float ):
522- return self .get_seconds () >= other
540+ return self .seconds >= other
523541 elif isinstance (other , str ):
524542 return self ._frame_num >= self ._parse_timecode_string (other )
525543 elif isinstance (other , FrameTimecode ):
@@ -541,7 +559,7 @@ def __int__(self) -> int:
541559 return self ._frame_num
542560
543561 def __float__ (self ) -> float :
544- return self .get_seconds ()
562+ return self .seconds
545563
546564 def __str__ (self ) -> str :
547565 return self .get_timecode ()
0 commit comments