Skip to content

Commit

Permalink
ignore segments that do not fit into reduce skips setting (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
matejdro authored Dec 11, 2021
1 parent c03d5dc commit d7f145b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions resources/lib/player_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def onPlayBackStarted(self): # type: () -> None
if not self._prepare_segments(video_id):
return

self._next_segment = self._segments[0]
self._select_next_checkpoint()
self._should_start = True

def onAVStarted(self): # type: () -> None
Expand All @@ -143,11 +143,33 @@ def onAVStarted(self): # type: () -> None
self.start_listener()

def _select_next_checkpoint(self):
reduce_skips_seconds = (
addon.get_config(CONF_REDUCE_SKIPS_MS, int) / 1000.0
)

current_time = self.getTime()
logger.debug("searching for next segment after %g", current_time)
self._next_segment = next(
(seg for seg in self._segments if seg.start > current_time), None
(seg for seg in self._segments if self._is_segment_skippable(seg, current_time, reduce_skips_seconds)), None
)

def _is_segment_skippable(self, seg, current_time, reduce_skips_seconds):
if seg.start < current_time:
return False

chained_end = self.__get_segment_end_handle_overlap(seg)
min_skip_position = current_time + reduce_skips_seconds

if chained_end < min_skip_position:
logger.debug("skipping segment %s because there is not enough margin for 'Reduce all skips by this much' setting (%g)", seg, reduce_skips_seconds)
return False

if chained_end - seg.start < reduce_skips_seconds:
logger.debug("skipping segment %s because it is shorter than 'Reduce all skips by this much' setting (%g)", seg, reduce_skips_seconds)
return False

return True


def _reset_next_checkpoint(self):
self._next_segment = None
Expand Down

0 comments on commit d7f145b

Please sign in to comment.