Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SponserBlock Support #222

Open
ghost opened this issue May 4, 2022 · 1 comment
Open

SponserBlock Support #222

ghost opened this issue May 4, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented May 4, 2022

What Problem Does This Solve?

Adds Sponserblock to Tubed


Suggest a Solution (optional)

I understand this will have to be after this app gets working again without api, however there is code for this for the regular Kodi Youtube app. There is a request there to add tubed support but its been there for a year. Just wondering if you could either add Sponserblock as a setting into this Kodi app or help support progress on their project for support.


@ghost ghost added the enhancement New feature or request label May 4, 2022
@SethFalco
Copy link

SethFalco commented May 27, 2023

The script.service.sponsorblock addon now supports multiple apps, though a PR is still needed for Tubed. It would be easiest to add it in the script instead of this plugin directly.

As the one that added support for plugin.video.invidious, here is a good starting point to get Tubed support.

Create resources/lib/apis/tubed_api.py, and define a new AbstractApi implementation named TubedApi.

A minimal implementation could look like this:

from six.moves.urllib import parse as urlparse

from .abstract_api import AbstractApi
from .models import NotificationPayload

from ..utils.xbmc import get_playing_file_path


class TubedApi(AbstractApi):

    def parse_notification_payload(self, data):  # type: (str) -> NotificationPayload | None
        return None

    def get_video_id(self):  # type: () -> str | None
        try:
            path_url = urlparse.urlsplit(get_playing_file_path())
            query = urlparse.parse_qs(path_url.query)
        except Exception:
            return None

        valid_url = (
            path_url.scheme == "plugin"
            and path_url.path.startswith("/")
        )

        return query.get("video_id")[0] if valid_url else None

    def should_preload_segments(self, method, data): # type: (str, NotificationPayload) -> bool
        return False

Reference:

'PlayMedia(plugin://%s/?mode=%s&video_id=%s)' %

In resources/lib/apis/api_factory.py, update API_MAP to include a mapping of the Kodi addon ID to the respective AbstractAPI implementation:

from .invidious_api import InvidiousApi
from .youtube_api import YouTubeApi
from .tubed_api import TubedApi

# …

API_MAP = {
    "plugin.video.youtube": YouTubeApi,
    "plugin.video.invidious": InvidiousApi,
    "plugin.video.tubed": TubedApi
}

Finally, in addon.xml, update the context-menu extension point to also show on the plugin.video.tubed app. This will show the button to configure Kodi SponsorBlock settings on the app.

<visible>String.IsEqual(ListItem.Property(Addon.ID),plugin.video.youtube) | String.IsEqual(ListItem.Property(Addon.ID),plugin.video.invidious) | String.IsEqual(ListItem.Property(Addon.ID),plugin.video.tubed)</visible>

I have not tested the code above, and it would be missing some features like preloading segments. However, 90% of the functionality, including skipping sponsor segments, should work.

If a Tubed user could test this implementation, feel free to do a PR. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant