Skip to content

Commit 0b7ff06

Browse files
committed
[api] Upgrade deprecation logs to warnings
1 parent 1292cac commit 0b7ff06

21 files changed

+169
-129
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ scene_list = detect('my_video.mp4', ContentDetector())
6666
for i, scene in enumerate(scene_list):
6767
print(' Scene %2d: Start %s / Frame %d, End %s / Frame %d' % (
6868
i+1,
69-
scene[0].get_timecode(), scene[0].get_frames(),
70-
scene[1].get_timecode(), scene[1].get_frames(),))
69+
scene[0].get_timecode(), scene[0].frame_num,
70+
scene[1].get_timecode(), scene[1].frame_num,))
7171
```
7272

7373
We can also split the video into each scene if `ffmpeg` is installed (`mkvmerge` is also supported):

scenedetect/_cli/commands.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def list_scenes(
158158
" | %5d | %11d | %s | %11d | %s |"
159159
% (
160160
i + 1,
161-
start_time.get_frames() + 1,
161+
start_time.frame_num + 1,
162162
start_time.get_timecode(),
163-
end_time.get_frames(),
163+
end_time.frame_num,
164164
end_time.get_timecode(),
165165
)
166166
for i, (start_time, end_time) in enumerate(scenes)
@@ -278,11 +278,11 @@ def save_edl(
278278
# Converts FrameTimecode to HH:MM:SS:FF
279279
# TODO: This should be part of the FrameTimecode object itself.
280280
def get_edl_timecode(timecode: FrameTimecode):
281-
total_seconds = timecode.get_seconds()
281+
total_seconds = timecode.seconds
282282
hours = int(total_seconds // 3600)
283283
minutes = int((total_seconds % 3600) // 60)
284284
seconds = int(total_seconds % 60)
285-
frames_part = int((total_seconds * timecode.get_framerate()) % timecode.get_framerate())
285+
frames_part = int((total_seconds * timecode.framerate) % timecode.framerate)
286286
return f"{hours:02d}:{minutes:02d}:{seconds:02d}:{frames_part:02d}"
287287

288288
edl_content = []
@@ -331,7 +331,7 @@ def _save_xml_fcpx(
331331

332332
# TODO: We should calculate duration from the scene list.
333333
duration = context.video_stream.duration
334-
duration = str(duration.get_seconds()) + "s" # TODO: Is float okay here?
334+
duration = str(duration.seconds) + "s" # TODO: Is float okay here?
335335
path = Path(context.video_stream.path).absolute()
336336
ElementTree.SubElement(
337337
resources,
@@ -355,8 +355,8 @@ def _save_xml_fcpx(
355355
spine = ElementTree.SubElement(sequence, "spine")
356356

357357
for i, (start, end) in enumerate(scenes):
358-
start_seconds = start.get_seconds()
359-
duration_seconds = (end - start).get_seconds()
358+
start_seconds = start.seconds
359+
duration_seconds = (end - start).seconds
360360
clip = ElementTree.SubElement(
361361
spine,
362362
"clip",
@@ -402,7 +402,7 @@ def _save_xml_fcp(
402402
ElementTree.SubElement(sequence, "name").text = context.video_stream.name
403403

404404
duration = scenes[-1][1] - scenes[0][0]
405-
ElementTree.SubElement(sequence, "duration").text = f"{duration.get_frames()}"
405+
ElementTree.SubElement(sequence, "duration").text = f"{duration.frame_num}"
406406

407407
rate = ElementTree.SubElement(sequence, "rate")
408408
ElementTree.SubElement(rate, "timebase").text = str(context.video_stream.frame_rate)
@@ -430,10 +430,10 @@ def _save_xml_fcp(
430430
ElementTree.fromstring(f"<timebase>{context.video_stream.frame_rate}</timebase>")
431431
)
432432
# TODO: Are these supposed to be frame numbers or another format?
433-
ElementTree.SubElement(clip, "start").text = str(start.get_frames())
434-
ElementTree.SubElement(clip, "end").text = str(end.get_frames())
435-
ElementTree.SubElement(clip, "in").text = str(start.get_frames())
436-
ElementTree.SubElement(clip, "out").text = str(end.get_frames())
433+
ElementTree.SubElement(clip, "start").text = str(start.frame_num)
434+
ElementTree.SubElement(clip, "end").text = str(end.frame_num)
435+
ElementTree.SubElement(clip, "in").text = str(start.frame_num)
436+
ElementTree.SubElement(clip, "out").text = str(end.frame_num)
437437

438438
file_ref = ElementTree.SubElement(clip, "file", id=f"file{i + 1}")
439439
ElementTree.SubElement(file_ref, "name").text = context.video_stream.name
@@ -534,12 +534,12 @@ def save_otio(
534534
"duration": {
535535
"OTIO_SCHEMA": "RationalTime.1",
536536
"rate": frame_rate,
537-
"value": float((end - start).get_frames()),
537+
"value": float((end - start).frame_num),
538538
},
539539
"start_time": {
540540
"OTIO_SCHEMA": "RationalTime.1",
541541
"rate": frame_rate,
542-
"value": float(start.get_frames()),
542+
"value": float(start.frame_num),
543543
},
544544
},
545545
"enabled": True,

scenedetect/_cli/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ class TimecodeFormat(Enum):
297297

298298
def format(self, timecode: FrameTimecode) -> str:
299299
if self == TimecodeFormat.FRAMES:
300-
return str(timecode.get_frames())
300+
return str(timecode.frame_num)
301301
if self == TimecodeFormat.TIMECODE:
302302
return timecode.get_timecode()
303303
if self == TimecodeFormat.SECONDS:
304-
return "%.3f" % timecode.get_seconds()
304+
return "%.3f" % timecode.seconds
305305
raise RuntimeError("Unhandled format specifier.")
306306

307307

scenedetect/_cli/controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run_scenedetect(context: CliContext):
6868
logger.info(
6969
"Detected %d scenes, average shot length %.1f seconds.",
7070
len(scenes),
71-
sum([(end_time - start_time).get_seconds() for start_time, end_time in scenes])
71+
sum([(end_time - start_time).seconds for start_time, end_time in scenes])
7272
/ float(len(scenes)),
7373
)
7474
else:
@@ -106,7 +106,7 @@ def _detect(context: CliContext) -> ty.Optional[ty.Tuple[SceneList, CutList]]:
106106
logger.critical(
107107
"Failed to seek to %s / frame %d: %s",
108108
context.start_time.get_timecode(),
109-
context.start_time.get_frames(),
109+
context.start_time.frame_num,
110110
str(ex),
111111
)
112112
return None

scenedetect/backends/moviepy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def position_ms(self) -> float:
143143
The first frame has a time of 0.0 ms.
144144
145145
This method will always return 0.0 if no frames have been `read`."""
146-
return self.position.get_seconds() * 1000.0
146+
return self.position.seconds * 1000.0
147147

148148
@property
149149
def frame_number(self) -> int:
@@ -176,7 +176,7 @@ def seek(self, target: ty.Union[FrameTimecode, float, int]):
176176
if not isinstance(target, FrameTimecode):
177177
target = FrameTimecode(target, self.frame_rate)
178178
try:
179-
self._last_frame = self._reader.get_frame(target.get_seconds())
179+
self._last_frame = self._reader.get_frame(target.seconds)
180180
if hasattr(self._reader, "last_read") and target >= self.duration:
181181
raise SeekError("MoviePy > 2.0 does not have proper EOF semantics (#461).")
182182
self._frame_number = min(

scenedetect/backends/opencv.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import math
2121
import os.path
2222
import typing as ty
23+
import warnings
2324
from fractions import Fraction
2425
from logging import getLogger
2526

@@ -89,9 +90,12 @@ def __init__(
8990
ValueError: specified framerate is invalid
9091
"""
9192
super().__init__()
92-
# TODO(v0.7): Replace with DeprecationWarning that `path_or_device` will be removed in v0.8.
9393
if path_or_device is not None:
94-
logger.error("path_or_device is deprecated, use path or VideoCaptureAdapter instead.")
94+
warnings.warn(
95+
"The `path_or_device` argument is deprecated, use `path` or `VideoCaptureAdapter` instead.",
96+
DeprecationWarning,
97+
stacklevel=2,
98+
)
9599
path = path_or_device
96100
if path is None:
97101
raise ValueError("Path must be specified!")
@@ -224,7 +228,7 @@ def seek(self, target: ty.Union[FrameTimecode, float, int]):
224228

225229
# Have to seek one behind and call grab() after to that the VideoCapture
226230
# returns a valid timestamp when using CAP_PROP_POS_MSEC.
227-
target_frame_cv2 = (self.base_timecode + target).get_frames()
231+
target_frame_cv2 = (self.base_timecode + target).frame_num
228232
if target_frame_cv2 > 0:
229233
target_frame_cv2 -= 1
230234
self._cap.set(cv2.CAP_PROP_POS_FRAMES, target_frame_cv2)

scenedetect/backends/pyav.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def seek(self, target: ty.Union[FrameTimecode, float, int]) -> None:
252252
if target >= 1:
253253
target = target - 1
254254
target_pts = self._video_stream.start_time + int(
255-
(self.base_timecode + target).get_seconds() / self._video_stream.time_base
255+
(self.base_timecode + target).seconds / self._video_stream.time_base
256256
)
257257
self._frame = None
258258
self._container.seek(target_pts, stream=self._video_stream)

scenedetect/common.py

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
import math
6565
import typing as ty
66+
import warnings
6667
from dataclasses import dataclass
6768
from enum import Enum
6869
from 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()

scenedetect/detectors/threshold_detector.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717

1818
import typing as ty
19+
import warnings
1920
from enum import Enum
2021
from logging import getLogger
2122

@@ -68,9 +69,12 @@ def __init__(
6869
method: How to treat `threshold` when detecting fade events.
6970
block_size: [DEPRECATED] DO NOT USE. For backwards compatibility.
7071
"""
71-
# TODO(v0.7): Replace with DeprecationWarning that `block_size` will be removed in v0.8.
7272
if block_size is not None:
73-
logger.error("block_size is deprecated.")
73+
warnings.warn(
74+
"The `block_size` argument is deprecated and will be removed in v0.8.",
75+
DeprecationWarning,
76+
stacklevel=2,
77+
)
7478

7579
super().__init__()
7680
self.threshold = int(threshold)

0 commit comments

Comments
 (0)