1313 Any ,
1414 Optional ,
1515 Union ,
16- Callable ,
1716)
17+ from collections .abc import Callable
1818from collections .abc import Iterator , Sequence
1919
2020from logzero import setup_logger # type: ignore[import]
2929EventData = Any
3030
3131
32- def parse_datetime_sec (d : Union [ str , float , int ] ) -> datetime :
32+ def parse_datetime_sec (d : str | float | int ) -> datetime :
3333 return datetime .fromtimestamp (float (d ), tz = timezone .utc )
3434
3535
@@ -41,7 +41,7 @@ class Action(NamedTuple):
4141 since_started : float
4242 action : str
4343 # this can be None if its a livestream, those dont have a percent-pos
44- percentage : Optional [ float ]
44+ percentage : float | None
4545
4646
4747class Media (NamedTuple ):
@@ -50,9 +50,9 @@ class Media(NamedTuple):
5050 start_time : datetime # when the media started playing
5151 end_time : datetime # when the media was closed/finished
5252 pause_duration : float # how long the media was paused for (typically 0)
53- media_duration : Optional [ float ] # length of the media
53+ media_duration : float | None # length of the media
5454 # title of the media (if URL, could be <title>...</title> from ytdl
55- media_title : Optional [ str ]
55+ media_title : str | None
5656 # additional metadata on what % I was through the media while pausing/playing/seeking
5757 actions : list [Action ]
5858 metadata : dict [str , Any ] # metadata from the file, if it exists
@@ -147,7 +147,7 @@ def _read_event_stream(
147147 continue
148148 if d ["end_time" ] < d ["start_time" ]:
149149 logger .warning (f"End time is less than start time! { d } " )
150- fdur : Optional [ float ] = None
150+ fdur : float | None = None
151151 if "duration" in d :
152152 fdur = float (d ["duration" ])
153153 start_time = parse_datetime_sec (float (d ["start_time" ]))
@@ -223,7 +223,7 @@ def _reconstruct_event_stream(
223223 # exec "$mpv_path" "${mpv_options[@]}"
224224 #
225225 # get when mpv launched from the filename
226- start_time : Optional [ float ] = None
226+ start_time : float | None = None
227227 try :
228228 start_time = float (int (PurePath (filename ).stem ) / 1e9 )
229229 except ValueError as ve :
@@ -242,7 +242,7 @@ def _reconstruct_event_stream(
242242 # used to help determine state
243243 is_playing = True # assume playing at beginning
244244 pause_duration = 0.0 # pause duration for this entry
245- pause_start_time : Optional [ float ] = None # if the entry is paused, when it started
245+ pause_start_time : float | None = None # if the entry is paused, when it started
246246 actions : dict [float , tuple [str , float ]] = {}
247247
248248 # a heuristic to determine if this is an old file, is-paused can be useful
0 commit comments