siku2 / script.service.sponsorblock

Kodi add-on for SponsorBlock
MIT License
124 stars 14 forks source link

Support for plugin.video.tubed #25

Open p-hash opened 3 years ago

p-hash commented 3 years ago

Tubed is a newer kodi youtube plugin from the same developer. I think it is better to use it instead of plugin.video.youtube

Links: https://forum.kodi.tv/showthread.php?tid=358806 https://github.com/anxdpanic/plugin.video.tubed

TubeCast is already using Tubed: https://github.com/enen92/script.tubecast/commit/8d30ef170cc8156ac20e6bedeb2e27ed61dd15ef

siku2 commented 3 years ago

Oh cool, I was unaware there was a new plugin. Thanks for the heads up!

matejdro commented 3 years ago

This looks cool. What are actual advantages of this plugin over plugin.video.youtube? I can't find them listed anywhere.

Arndorferd commented 2 years ago

The advantage is being able to create playlists and channels outside of an account a lot like freetube, I second support for this its better than youtube plugin

SethFalco commented 1 year ago

Please refer to my comment here:


I'll copy and paste the important bits.

Ideally, it should just take the following changes:

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

A minimal implementation could look like this, though it won't preload segments:

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: https://github.com/anxdpanic/plugin.video.tubed/blob/65455a691e89bbb995b57a2875cb34f4168cb6e9/resources/lib/src/generators/video.py#L325

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>

If someone who uses plugin.video.tubed could test this, feel free to do a PR. It would be even better if you could implement the #parse_notification_payload and #should_preload_segments functions, but the extension will work without them. :+1: