Skip to content

Commit

Permalink
feat: do not use sequence number as record start time
Browse files Browse the repository at this point in the history
resolve #202
  • Loading branch information
acgnhik committed Dec 24, 2023
1 parent 6cd97ab commit 71ca3f8
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions src/blrec/hls/operators/segment_dumper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import io
from datetime import datetime, timedelta, timezone
from pathlib import PurePath
from typing import Callable, Optional, Tuple, Union

Expand All @@ -10,7 +9,6 @@

from blrec.utils.ffprobe import ffprobe

from ..helpler import sequence_number_of
from .segment_fetcher import InitSectionData, SegmentData

__all__ = ('SegmentDumper',)
Expand All @@ -29,7 +27,6 @@ def _reset(self) -> None:
self._path: str = ''
self._file: Optional[io.BufferedWriter] = None
self._filesize: int = 0
self._record_start_time: Optional[int] = None

@property
def path(self) -> str:
Expand All @@ -39,10 +36,6 @@ def path(self) -> str:
def filesize(self) -> int:
return self._filesize

@property
def record_start_time(self) -> Optional[int]:
return self._record_start_time

@property
def file_opened(self) -> Observable[Tuple[str, int]]:
return self._file_opened
Expand All @@ -57,8 +50,7 @@ def __call__(
return self._dump(source)

def _open_file(self) -> None:
assert self._record_start_time is not None
path, timestamp = self._path_provider(self._record_start_time)
path, timestamp = self._path_provider()
self._path = str(PurePath(path).with_suffix('.m4s'))
self._file = open(self._path, 'wb') # type: ignore
logger.debug(f'Opened file: {self._path}')
Expand All @@ -80,13 +72,6 @@ def _write_data(self, item: Union[InitSectionData, SegmentData]) -> Tuple[int, i
def _update_filesize(self, size: int) -> None:
self._filesize += size

def _set_record_start_time(self, item: Union[InitSectionData, SegmentData]) -> None:
seq = sequence_number_of(item.segment.uri)
dt = datetime.utcfromtimestamp(seq)
tz = timezone(timedelta(hours=8))
ts = dt.replace(year=datetime.today().year, tzinfo=tz).timestamp()
self._record_start_time = int(ts)

def _must_split_file(
self, prev_init_item: Optional[InitSectionData], curr_init_item: InitSectionData
) -> bool:
Expand Down Expand Up @@ -159,7 +144,6 @@ def on_next(item: Union[InitSectionData, SegmentData]) -> None:
if split_file:
self._close_file()
self._reset()
self._set_record_start_time(item)
self._open_file()

try:
Expand Down

0 comments on commit 71ca3f8

Please sign in to comment.