yta-video-frame-time 0.0.16__tar.gz → 0.0.23__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of yta-video-frame-time might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yta-video-frame-time
3
- Version: 0.0.16
3
+ Version: 0.0.23
4
4
  Summary: Youtube Autonomous Video Frame Time Module
5
5
  License-File: LICENSE
6
6
  Author: danialcala94
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "yta-video-frame-time"
3
- version = "0.0.16"
3
+ version = "0.0.23"
4
4
  description = "Youtube Autonomous Video Frame Time Module"
5
5
  authors = [
6
6
  {name = "danialcala94",email = "danielalcalavalera@gmail.com"}
@@ -0,0 +1,52 @@
1
+ """
2
+ TODO: I think this module should not be here, or maybe
3
+ yes, but I need this decorator.
4
+ """
5
+ from functools import wraps
6
+
7
+
8
+ def parameter_to_time_interval(
9
+ param_name: str
10
+ ):
11
+ """
12
+ Force the parameter with the given `param_name` to
13
+ be a `TimeInterval` instance.
14
+
15
+ Values accepted:
16
+ - `TimeInterval` instance
17
+ - `tuple[float, float]` that will be `(start, end)`
18
+ """
19
+ def decorator(
20
+ func
21
+ ):
22
+ @wraps(func)
23
+ def wrapper(
24
+ *args,
25
+ **kwargs
26
+ ):
27
+ from inspect import signature
28
+ from yta_validation import PythonValidator
29
+ from yta_video_frame_time.interval import TimeInterval
30
+
31
+ sig = signature(func)
32
+ bound = sig.bind(*args, **kwargs)
33
+ bound.apply_defaults()
34
+
35
+ value = bound.arguments[param_name]
36
+
37
+ if PythonValidator.is_instance_of(value, TimeInterval):
38
+ pass
39
+ elif (
40
+ PythonValidator.is_tuple(value) and
41
+ len(value) == 2
42
+ ):
43
+ value = TimeInterval(*value)
44
+ bound.arguments[param_name] = value
45
+ else:
46
+ raise Exception(f'The "{param_name}" parameter must be a TimeInterval or a tuple[float, float].')
47
+
48
+ return func(*bound.args, **bound.kwargs)
49
+
50
+ return wrapper
51
+
52
+ return decorator