tubesync icon indicating copy to clipboard operation
tubesync copied to clipboard

Use SponsorBlock API to remove sponsored segments and Endcards/Credits

Open Extarys opened this issue 4 years ago • 8 comments

Most videos have an Endcards (check 23:05 on this amazing Technology Connection video) or Raid Shitty Legend sponsorships.

The endcards have no purpose outside of youtube itself and break the flow between two videos when watching on a media server/not on youtube.

Sponsorships are understandable the first time you watch a recent video, but are just annoying when it's a 3 year old video you watched for the fifth time.

Those segments also add to the filesize and therefore require more diskspace.

  • I'm not sure we can cut a video without reeencoding it :disappointed: research is needed
  • In case it is not, including chapter markers with "sponsored segment" or "endcard" would suffice. In this case it would be good to make it human and machine readable in case someone come up with a plugin for Jellyfin or Plex for example.

Extarys avatar Apr 09 '21 16:04 Extarys

Yes I've been looking into this myself for a while ever since I started downloading YouTube videos to watch on other devices. This would be provided by youtube-dl or similar upstream library as a feature and not something I would code into TubeSync directly. It doesn't look like youtube-dl supports sponsor cutting itself at all. There are some forks of youtube-dl like yt-dlc ( https://github.com/blackjack4494/yt-dlc ) which do say they support it in their feature set, however:

  1. I'm not entirely sure how comfortable I'd be basing TubeSync on a much smaller (in terms of dev support and popularity) core upstream library
  2. It would introduce a dependency to query some external database for sponsorship start and end times, I assume some API queries, per downloaded video, which could introduce a bunch of other issues (unobvious privacy concerns, if the API breaks does TubeSync break etc.)

I agree this would be a great feature, but it likely requires a bunch of testing and fiddling first. I'll put it on the future wishlist for now.

meeb avatar Apr 10 '21 11:04 meeb

@meeb I just found out that yt-dlp have SponsorBlock integration :)

Might save a lot of time. Could have a simple config - Off, On - Mark only, On - Remove: --no-sponskrub Do not use sponskrub --sponskrub-cut Cut out the sponsor sections instead of simply marking them --no-sponskrub-cut Simply mark the sponsor sections, not cut them out (default)

And yt-dlp does have other very nice features too!

Extarys avatar Apr 27 '21 11:04 Extarys

Yeah I've seen it. I covered it (well, yt-dlc not yt-dlp, similar libraries) in my response above as well. I'm considering it, but there's a bunch of potential downsides. I'm looking at making it an opt-in feature rather than replace youtube-dl entirely at the moment.

meeb avatar Apr 27 '21 13:04 meeb

So now that Tubesync is using yt-dlp this should be even more likely, I've been using yt-dlp and the --sponsorblock-remove and --sponsorblock-mark options in a terminal for awhile now, I say yeah make them opt in for people who want to use them. I'd also love to help get this implemented if I can.

Deanosim avatar May 24 '22 15:05 Deanosim

I would like to add this, however I don't believe yt-dlp has sponsorblock options exposed over the embedded API yet. If or when this gets implemented in yt-dlp I'll definitely look at adding it to TubeSync.

meeb avatar May 24 '22 16:05 meeb

Looking at the yt-dlp code there is a postprocessor

{ 'key': 'SponsorBlock', 'categories': sponsorblock_query, 'api': opts.sponsorblock_api, 'when': 'after_filter' }

opts.sponsorblock_api defaults to https://sponsor.ajay.app sponsorblock_query is what you put after sponsorblock-mark

https://github.com/yt-dlp/yt-dlp/blob/c4a62b99f682bac966ede4a58d1b20f0f3f49f1e/yt_dlp/init.py#L521

If you need an example how to use the postprocessors: https://github.com/Cycor/ytdl-tg-bot/blob/be1981ead33bb0e60687659fc814aa30507a655b/bot.py#L110

Cycor avatar May 24 '22 17:05 Cycor

Interesting, thanks @Cycor I'll certainly give that a test.

meeb avatar May 24 '22 17:05 meeb

This is definitely of interest to me :D

voarsh2 avatar Aug 20 '22 16:08 voarsh2

I was able to get sponsorblock working as a post processor.

This enables chapter support, english subtitle support, and sponsorblock support. You can adjust the categories/remove_sponsor_segments accordingly. There is a full list of categories here: https://github.com/yt-dlp/yt-dlp/blob/14f25df2b6233553e968df023430ca96c0b1df9f/yt_dlp/postprocessor/sponsorblock.py

One thing to note I did need to upgrade my version of ffmpeg to get this to work https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz

sync\youtube.py changes at line 94

    opts = get_yt_opts()
    opts.update({
        'format': media_format,
        'merge_output_format': extension,
        'outtmpl': output_file,
        'quiet': True,
        'progress_hooks': [hook],
        'writeinfojson': info_json,
        'sponsorblock_remove': True,
        'nocheckcertificate': True,
        'writesubtitles': True,
        'writeautomaticsub': False,
        'subtitleslangs': ["en", "-live_chat"],
        'postprocessors': [{
                'key': 'SponsorBlock',
                'categories': ['sponsor','selfpromo','interaction']
            }, {
                'key': 'FFmpegSubtitlesConvertor',
                'format': 'srt'
            }, {
                'key': 'FFmpegThumbnailsConvertor',
                'format': 'jpg',
                'when': 'before_dl'
            }, {
                'key': 'EmbedThumbnail',
                'already_have_thumbnail': True
            }, {
                'key': 'FFmpegEmbedSubtitle',
                'already_have_subtitle': False
            }, {
                'key': 'ModifyChapters',
                'remove_sponsor_segments': ['sponsor','selfpromo','interaction']
            }, {
                'key': 'FFmpegMetadata',
                'add_chapters': True,
                'add_metadata': True
            }

            ]
    })

bawitdaba avatar Oct 13 '22 22:10 bawitdaba

Nice work, thanks! I'll give this a test and if it works I'll bundle it into the next release. Cheers for the contribution!

meeb avatar Oct 14 '22 10:10 meeb

This is in :latest.

meeb avatar Mar 24 '23 01:03 meeb