Skip to content

Commit

Permalink
Handle unordered playback events gracefully (#12)
Browse files Browse the repository at this point in the history
* allow checkpoint listener to be running

* update metadata

* Update addon.xml
  • Loading branch information
siku2 authored Oct 1, 2020
1 parent a1ac5eb commit 1d4a51a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ To do this refer to the [Import an existing account](https://github.com/siku2/sc

## Helping out

You can help translate the addon to different languages.
You can help translate the addon to different languages.
Localisation is done using [GitLocalize](https://gitlocalize.com/).
You can start translating [here](https://gitlocalize.com/repo/4205) (you can sign-in using your GitHub account).
If there's a language missing please don't hesitate to open a new issue.
If there's a language missing please don't hesitate to open a new issue.

## Issues and Suggestions

Expand Down
8 changes: 6 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.service.sponsorblock" version="0.2.0" name="SponsorBlock" provider-name="siku2">
<addon id="script.service.sponsorblock" version="0.2.1" name="SponsorBlock" provider-name="siku2">
<requires>
<import addon="xbmc.python" version="2.23.0"/>
<import addon="script.module.requests" version="2.15.1"/>
Expand Down Expand Up @@ -28,6 +28,10 @@ Users submit when a sponsor happens and the add-on automatically skips sponsors
</description>
<disclaimer lang="en_GB">This is an unoffical port of the SponsorBlock browser extension</disclaimer>
<news>
[0.2.1]
- Fixed "Playback fails with sponsor section at video start" (#12)
- Added German translation (@NettoHikari, #9)

[0.2.0]
- Support for SponsorBlock categories
- Option to disable SponsorBlock for unlisted videos.
Expand All @@ -43,4 +47,4 @@ Users submit when a sponsor happens and the add-on automatically skips sponsors
<fanart>resources/images/fanart.jpg</fanart>
</assets>
</extension>
</addon>
</addon>
4 changes: 2 additions & 2 deletions resources/lib/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def onSettingsChanged(self): # type: () -> None
api.set_api_server(addon.get_config(CONF_API_SERVER, str))
api.set_categories(get_categories())

def __handler_playback_init(self, data):
def __handle_playback_init(self, data):
try:
video_id = data["video_id"]
except KeyError:
Expand Down Expand Up @@ -88,4 +88,4 @@ def onNotification(self, sender, method, data): # type: (str, str, str) -> None

logger.debug("notification from YouTube addon: %r %s", method, data)
if method == youtube_api.NOTIFICATION_PLAYBACK_INIT:
self.__handler_playback_init(data)
self.__handle_playback_init(data)
25 changes: 15 additions & 10 deletions resources/lib/utils/checkpoint_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

logger = logging.getLogger(__name__)

MAX_UNDERSHOOT = .25
MAX_UNDERSHOOT = 0.25
"""Amount of tolerance in seconds for waking up early.
If the listener wakes up and the difference to the checkpoint is bigger than this value,
Expand Down Expand Up @@ -38,7 +38,7 @@ class PlayerCheckpointListener(xbmc.Player):

def __init__(self, *args, **kwargs):
super(PlayerCheckpointListener, self).__init__(*args, **kwargs)
self._playback_speed = 1.
self._playback_speed = 1.0

self.__seek = None # type: Optional[Tuple[float, float]]
self.__wakeup = threading.Condition()
Expand Down Expand Up @@ -124,7 +124,9 @@ def __t_cp_reached(self):

overshoot = self._get_current_time() - cp
if overshoot > MAX_OVERSHOOT:
logger.warning("overshot checkpoint %s by %s second(s), not skipping", cp, overshoot)
logger.warning(
"overshot checkpoint %s by %s second(s), ignoring", cp, overshoot
)
self._select_next_checkpoint()
return

Expand Down Expand Up @@ -172,14 +174,17 @@ def _trigger_wakeup(self):

def start(self): # type: () -> None
if self._thread_running:
if not self._stop:
raise RuntimeError("checkpoint listener running and not being stopped")

logger.debug("waiting for checkpoint listener to stop before starting")
self._thread.join()
if self._stop:
logger.debug("waiting for previous checkpoint listener to stop")
self._thread.join()
else:
logger.warning("checkpoint listener already running, stopping")
self.stop()

logger.info("starting checkpoint listener")
self._thread = threading.Thread(target=self.__t_event_loop, name="Checkpoint Listener")
self._thread = threading.Thread(
target=self.__t_event_loop, name="Checkpoint Listener"
)
self._thread.start()

def stop(self):
Expand All @@ -196,7 +201,7 @@ def stop(self):
logger.debug("listener stopped")

def onPlayBackSeek(self, target, offset): # type: (int, int) -> None
self._seek_time = target / 1000.

This comment has been minimized.

Copy link
@Featzaza999

Featzaza999 Oct 30, 2020

zrose584:support_ytlocal

self._seek_time = target / 1000.0
self._trigger_wakeup()

def onPlayBackEnded(self): # type: () -> None
Expand Down
1 change: 1 addition & 0 deletions tools/quick-install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
set -eE

function exit_with_error() {
Expand Down

0 comments on commit 1d4a51a

Please sign in to comment.