Giter Site home page Giter Site logo

mpv_sponsorblock's Introduction

mpv_sponsorblock

A fully-featured port of SponsorBlock for mpv.

Requirements

  • Python 3

Installation

Move sponsorblock.lua and sponsorblock_shared into your mpv scripts folder.

mpv/scripts/
├── sponsorblock.lua
└── sponsorblock_shared
    ├── main.lua
    └── sponsorblock.py

Usage

Play a YouTube video, sponsors will be skipped automatically.

Default key bindings:

  • g to set segment boundaries
  • G (shift+g) to submit a segment
  • h to upvote the last segment
  • H (shift+h) to downvote the last segment

These can be remapped with the following script bindings: sponsorblock/set_segment, sponsorblock/submit_segment, sponsorblock/upvote_segment, sponsorblock/downvote_segment

Add lines in the following format to your input.conf: alt+g script-binding sponsorblock/set_segment

mpv_sponsorblock's People

Contributors

ajariel avatar ajayyy avatar foldex avatar henri-j-norden avatar kiwec avatar mrrawes avatar po5 avatar zocker1999net avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpv_sponsorblock's Issues

Endcards/Credit

I was testing this script with this video

https://www.youtube.com/watch?v=Ij8bRn7ZH3w

On Google Chrome + SponsorBlock
from 9:47 to the end of the video there's a category called "Endcards/Credit"

On MPV + This script
There is no category there, it doesn't skip it

This is the script:

categories = "sponsor","selfpromo","interaction","intro","outro","preview","music_offtopic",
skip_categories = "sponsor","selfpromo","interaction","intro","outro","preview","music_offtopic",

TypeError: the JSON object must be str, not 'bytes'

Hi, I have the latest version of the script and I get this error in the terminal:

[sponsorblock] Traceback (most recent call last):
[sponsorblock]   File "/home/g4570n/.config/mpv/scripts/sponsorblock_shared/sponsorblock.py", line 34, in <module>
[sponsorblock]     segments = json.load(response)
[sponsorblock]   File "/usr/lib/python3.5/json/__init__.py", line 268, in load
[sponsorblock]     parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
[sponsorblock]   File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
[sponsorblock]     s.__class__.__name__))
[sponsorblock] TypeError: the JSON object must be str, not 'bytes'

I have these versions installed:

mpv 0.23.0
Python 3.5.4

[Request] Don't cache adveertisement sections

Title says it all, currently mpv dow download the advertisement/sponsor sections of videos being streamed ith youtube-dl.
It would be great if these sections can be skipped while downloading, to save some bandwith.

Script doesn't work on Windows (without some workaround)

I have both Python 2.7.18 x86 and 3.8.7 installed, both set to add to PATH on install (it's opt-in). The issue is that "python" is set to 2.7 by default, and python3 is not set to anything (I reinstalled both to double check).

The solution I found was simply replacing "python" or "python3" on line 11 with just "py".

mtime of database does not seem to be updated

Even though I have sponsor segments for videos that are older than the mtime of my db file, the file does not appear to be updated according to its mtime.

~/.config/mpv/scripts/sponsorblock_shared ∇ stat *.db
  File: sponsorblock.db
  Size: 977641472 	Blocks: 1909464    IO Block: 4096   regular file
Device: 254,0	Inode: 6690398     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/     fichte)   Gid: ( 1000/     fichte)
Access: 2022-08-24 13:21:22.390665683 +0200
Modify: 2021-08-24 11:34:57.215487190 +0200
Change: 2021-08-24 11:34:57.238819758 +0200
 Birth: 2021-08-24 11:33:26.218823081 +0200

Support for IINA

Is it possible to add support IINA? Its a macos player based on mpv.

This is the error in the logs:
[ 223.542][d][cplayer] Run command: subprocess, flags=64, args=[python3,/Users/admin/.config/mpv/scripts/sponsorblock/shared/sponsorblock.py,ranges,/Users/admin/.config/mpv/scripts/sponsorblock/shared/sponsorblock.db,https://api.sponsor.ajay.app,IbYG7q9OO18, no, 67108864, yes, no]

Move configuration to a different file

I use git fetch; git reset --hard origin to pull the repo (can't use git pull). My configuration gets lost whenever I run the commands. I'd appreciate it if the config is decoupled from the application.

Statuses in MPV Console

Please consider adding the display of the status of mpv_sponsorblock in the MPV console.

Statuses that are useful to know:

  • [SponsorBlock] %datetime% : Loaded
  • [SponsorBlock] %datetime% : Loading Failed
  • [SponsorBlock] %datetime% : Sponsor Database Downloading : %progress%
  • [SponsorBlock] %datetime% : Sponsor Database Updated
  • [SponsorBlock] %datetime% : Sponsor Database Download Failed
  • [SponsorBlock] %datetime% : Sponsor Data Loaded

etc..

Add example of rebinding keys to the readme

I found the instructions to be rather unclear, I hadn't come across the script-binding command before, so I just put in my input.conf something like this:

alt+g sponsorblock/set_segment
alt+G sponsorblock/submit_segment

which of course results in an error in the mpv console, and left me confused. I got some help from some mpv experts who informed me script-binding was a command to run and that the values from your readme were arguments for it.
In the end I have this, and no more errors:

alt+g script-binding sponsorblock/set_segment
alt+G script-binding sponsorblock/submit_segment

A subtle but important difference. (I had a key conflict on g with the mpv-gallery-view script, so rebinding the keys had to be done before I could even use this script)

[Feature Request] Allow manually skipping categories

I really appreciate being able to manually skip categories in the web extension. Would it be possible to add an option for categories to manually skip and then give some sort of prompt/notice/indicator with the option to skip such a section when it arrises (like the extension)?

Errors shown in Command Line - red text

I'm using the latest version of this repo.

First Run (no sponsorblock.db file):

first run

Second Run (sponsorblock.db file exists):

second run

Files:

list

Could you advise about the line: Cannot find main.* .... ?

`Cannot find main.* [...]` when running mpv

Full error message:

Cannot find main.* for any supported scripting backend in: /home/thomas/.config/mpv/scripts/mpv-sponsorblock-git

This issue has been brought up before in #8, saying there has been a fix deployed, but it seems like this is not working for me.

Any guesses?

I installed the version in the AUR with pkgver=r54.6743bd4
mpv version: mpv 0.34.1-dirty

Chapter Skipping for SponSkrub Chapters in downloaded YT Videos

Summary Ask:

Skip SponSkrub - SponsorBlock Chapters in downloaded yt videos via Chapter Titles


The Command Line Application: yt-dlp allows users to easily/automatically use SponSkrub to create video Chapters based on the SponsorBlock API.

Because of this, downloaded videos can have chapters for: Sponsors, Introductions, Outros, Interactions, Self-Promos and Non-Music sections.

I haven't been able to get the lua script of chapterskip to automatically skip these Chapters, but I think it would be cool to integrate SponSkrub Chapter titles into the type of content that is skipped with the mpv_sponsorblock lua script.

Thanks :)

Type of chapters that could be skipped:
image

Fix the Installation section of README.md

The installation directions for installing don't make sense. Moving the repo's contents into the scripts directory will leave you with these two errors:

Can't load unknown script: /home/debian/.config/mpv/scripts/LICENSE
Can't load unknown script: /home/debian/.config/mpv/scripts/README.md

It would be better to say move the sponsorblock.lua file and the sponsorblock_shared directory into the scripts directory. For anyone new to installing this script it should look something like this:

$ tree ~/.config/mpv/scripts/
/home/debian/.config/mpv/scripts/
├── sponsorblock.lua
└── sponsorblock_shared
    ├── main.lua
    └── sponsorblock.py

1 directory, 3 files

Lua error… '=' expected near continue

When running MPV with this loaded, I get the following errors

[sponsorblock] Loading lua script /Users/jeffsandberg/.config/mpv/scripts/sponsorblock.lua...
[sponsorblock] loading mp.defaults
[sponsorblock] loading file /Users/jeffsandberg/.config/mpv/scripts/sponsorblock.lua
[sponsorblock]
[sponsorblock] stack traceback:
[sponsorblock] 	[C]: ?
[sponsorblock] 	[C]: ?
[sponsorblock] Lua error: /Users/jeffsandberg/.config/mpv/scripts/sponsorblock.lua:195: '=' expected near 'continue'
[sponsorblock] Exiting...

I am running mpv 0.32.0:

mpv 0.32.0 Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects
 built on Fri Jan 31 11:28:05 CET 2020
ffmpeg library versions:
   libavutil       56.31.100
   libavcodec      58.54.100
   libavformat     58.29.100
   libswscale      5.5.100
   libavfilter     7.57.100
   libswresample   3.5.100
ffmpeg version: 4.2.2

and youtube-dl version 2020.06.16.1

the UID file should only be readable by the user

the file sponsorblock.txt (which contains the UID) should only be readable/writable by the user (it sould be given a permission of 600), otherwise other users in the system can read the UID and impersonate the user.

From the Import/Export UserID Section in the SponsorBlock extension: "This should be kept private. This is like a password and should not be shared with anyone. If someone has this, they can impersonate you."

what i do :(

image
whole thing is filled with that video is not even playing . it stucks at updating data :(

Support for Celluloid

I understand that you're officially supporting only mpv, so if you consider this out of scope, please consider it a feature suggestion.

I've tried to run mpv_sponsorblock under Celluloid and it does not seem to work. :(

If you're not familiar, Celluloid is a GTK frontend for mpv. It supports most of mpv's configs and scripts, at least according to the readme.
Any chance you could add support for it?

Thanks for doing this project, even without Celluloid support, it is amazing.

Python was not found

I Installed:

python-3.9.6-amd64.exe

And did that:

Move this repo's contents into your mpv scripts folder.

On console:

[sponsorblock] Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

I tried uninstalling, restarting, installing again, it doesn't work.
(WIndows 10 Pro 64Bit)

Consider setting `scripts_dir` path relative to `sponsorblock.lua`'s path?

I am using a following mpv config layout:

~/.config/mpv/
├── input.conf
└── scripts/
   ├── modules.lua    <-- loads scripts from sub-folders
   ├── mpv_sponsorblock/
   │  ├── LICENSE
   │  ├── README.md
   │  ├── sponsorblock.lua
   │  └── sponsorblock_shared/...
   ├── ...
   └── ...

It however doesn't work with mpv_sponsorblock, as sponsorblock.lua is making assumption it was unpacked into the root of scripts/ folder.

Can scripts_dir variable be set to something like

scripts_dir = debug.getinfo(1).source:match("@?(.*/)")

so that it would be a bit more flexible?

[Feature Request] Option to hide text when skipping

I find myself distracted every time I see any text on the top left of the screen, such as: "[sponsorblock] skipping sponsor".
I would love to get rid of the text indicating what chapter is skipped.
Is it possible to add an option of indication decided by "true" or "false"?

sqlite3.DatabaseError: database disk image is malformed

[sponsorblock] Traceback (most recent call last):
[sponsorblock]   File "/home/user/.config/mpv/scripts/sponsorblock_shared/sponsorblock.py", line 57, in <module>
[sponsorblock]     c.execute("SELECT startTime, endTime, votes, UUID, category FROM sponsorTimes WHERE videoID = ? AND shadowHidden = 0 AND votes > -1 AND category = ?", (sys.argv[4], category))
[sponsorblock] sqlite3.DatabaseError: database disk image is malformed

Is this a po5 / mpv_sponsorblock issue or only data-corruption on my drive?

ERROR: Unable to communicate with SponsorBlock API: The read operation timed out

There appears to be no issue for this error — seen today.

[ytdl_hook] ERROR: Unable to communicate with SponsorBlock API: The read operation timed out 
[ytdl_hook] youtube-dl failed: unexpected error occurred 
Failed to recognize file format.

The online database may be unresponsive at the time of writing.

EDIT: Sorry, I missed when running ping and loading the website:

This website sponsor.ajay.app/ is currently offline. Cloudflare's Always Online™ shows a snapshot of this web page from the Internet Archive's Wayback Machine.


mpv 0.34.1 Copyright © 2000-2021 mpv/MPlayer/mplayer2 projects
built on UNKNOWN
FFmpeg library versions:
libavutil 57.17.100
libavcodec 59.18.100
libavformat 59.16.100
libswscale 6.4.100
libavfilter 8.24.100
libswresample 4.3.100
FFmpeg version: 5.0.1

the current script revision: 6743bd4

[Feature Request] Add keybind to unskip the last skipped segment

I think having a dedicated keybind to unskip the last skipped segment would be great.

This seems relatively easy to implement considering the chapter markings created, and in a way I can already to this by using a chapter seek keybind. This is not ideal however since I'd have to skip two chapters essentially (back to the end of the skipped chapter, then one more time to get to the beginning of the skipped chapter).

My lua knowledge isn't strong enough to create something like this, anyone have some ideas?

Legacy script tries to require script from current directory - mpv 0.32

When opening mpv version 0.32, the following error is generated:

sponsorblock_legacy: stack traceback:
sponsorblock_legacy: 	[C]: in function 'require'
sponsorblock_legacy: 	/home/marty/.config/mpv/scripts/sponsorblock_legacy.lua:2: in main chunk
sponsorblock_legacy: 	[C]: in ?
sponsorblock_legacy: 	[C]: in ?
sponsorblock_legacy: Lua error: /home/marty/.config/mpv/scripts/sponsorblock_legacy.lua:2: module 'sponsorblock/main' not found:
sponsorblock_legacy: 	no field package.preload['sponsorblock/main']
sponsorblock_legacy: 	no file '/usr/share/lua/5.2/sponsorblock/main.lua'
sponsorblock_legacy: 	no file '/usr/share/lua/5.2/sponsorblock/main/init.lua'
sponsorblock_legacy: 	no file '/usr/lib/lua/5.2/sponsorblock/main.lua'
sponsorblock_legacy: 	no file '/usr/lib/lua/5.2/sponsorblock/main/init.lua'
sponsorblock_legacy: 	no file './sponsorblock/main.lua'
sponsorblock_legacy: 	no file '/usr/lib/lua/5.2/sponsorblock/main.so'
sponsorblock_legacy: 	no file '/usr/lib/lua/5.2/loadall.so'
sponsorblock_legacy: 	no file './sponsorblock/main.so'

This looks like ./sponsorblock/main.lua could not be found, thus not required correctly. The folder structure in scripts looks as follows

. ~/.config/mpv/scripts/
├── sponsorblock_legacy.lua
├── sponsorblock/
│  ├── main.lua
│  └── shared
│     ├── sponsorblock.py
│     └── ...

As far as I know, this should be the correct directory structure.
I am running mpv on linux.
It appears that the root folder for lua scripts is set to whatever directory mpv is called from, which means it always attempts to source ./sponsorblock/main.lua from wherever it is called.

Feel free to ignore this report as it only affects the legacy workaround anyways, and for the time being either:

  1. aliasing mpv to be called from the scripts directory or
  2. putting the sponsorblock script into one of the absolute paths looked for by lua work.

But I struggled with this for a little while and thought it worth highlighting.
Anyways, thank you so much for the work of integrating sponsorblock with mpv -- when using one of the workarounds, it works like a charm!

Edit:

Actually, just a quick edit -- changing the legacy script to substitute its package path to the one that the sponsorblock_legacy.lua file resides in also works
(though it's a bit hacky, and probably only works with unix directories):

if mp.get_script_directory == nil then
    local scriptpath = debug.getinfo(1).short_src:match('.*/')
    local originalpath = package.path
    package.path = scriptpath .. "?.lua"

    require 'sponsorblock/main'

    package.path = originalpath
end

One Menu for all Actions

Is it possible to use a menu like this to do all actions from:

image

For example g will open this menu:

Sponsor Block
1: set segment start 
2: set segment end
c: clear segment boundaries
u: upvote last segment
d: downvote last segment
s: submit
Esc: Close Menu

Submit will open a new menu similar to existing one:

image

This way users can use just one key to just open menu, other keys would be bound when menu is open and unbound when menu is closed.

Sorry in advance, if this is unnecessary but it would be clean and easy to remember.

Overlapping and close to each other segments

Example video: https://www.youtube.com/watch?v=Npu7jkJk5nM

There are 2 overlapping segments, one at the beginning, and one at the end. To illustrate:

[===A===]
       [===B===]

When playback arrives at the beginning of A, it skips to end of A instead of end of B.

When fixing this, please don't just detect overlaps, but also segments that are closer than let's say half a second to each other, and skip past that gap as well.

How to disable all keybindings?

Default key bindings:

  • g to set segment boundaries
  • G (shift+g) to submit a segment
  • h to upvote the last segment
  • H (shift+h) to downvote the last segment

These can be remapped with the following script bindings: sponsorblock/set_segment, sponsorblock/submit_segment, sponsorblock/upvote_segment, sponsorblock/downvote_segment

Can the mappings be disabled like keys in the mpv's input.conf?

WHEEL_UP ignore
WHEEL_DOWN ignore

Config File Not Loaded?

I'm using the Windows version of MPV: mpv-x86_64-20200524-git-685bd6a

I'm using the latest version of your script and am getting this issue:

1

Seems like the config values aren't being loaded?

My config file (script-opts\sponsorblock.conf) is simply:

audio_fade=yes
skip_once=yes

`python` invokes Python 2 on some systems.

That's not how windows executables work at all, you don't have to specify the .exe.

Please don't try to lecture others when you've got no idea how something works.

Will implement the solution discussed earlier as it's seemingly the best we'll ever come up with.

Originally posted by @po5 in #4 (comment)

Since you locked that I couldn't properly reply, so I apologize for opening a new issue. I literally set this up on Windows using @jgkamat's patch. It worked.

While I cannot find official documentation, Windows will run commands without the .exe extension as long as they are in the PATH. It even works when you invoke external programs programmatically.

The most proof outside of my own word I could find was this superuser issue where adding an item to a path is one of the solutions offered to run a binary.


Also an actual issue that just occurred to me, the lua script needs to detect if python is installed, else it just fails. I learned this due to the fact Python actually installs a shim these days that just opens the Windows Store and tells you to download Python 3 from there.

Support for Invidious

First, thank you for this port.

However, since I'm using an Invidious instance to get my RSS feed I need to rewrite the links to be the youtube one every time, it would be nice if this could support Invidious links too (at least the public instances).

I guess it can be done by using https://instances.invidio.us/ to get the public instances list or by using a wildcard for every links with /watch?v=

Adding a license

The project is missing a license, meaning the work is under exclusive copyright by default. This way no one can contribute to the project or distribute it.
If you are unsure about which license to pick, https://choosealicense.com has concise and easy to understand explanations on what the most common licenses allow and what they don't.

Write data to a standard writable directory for cache data

Currently, the script attempts to write the user ID and the sponsorblock DB within the "sponsorblock_shared" directory. However, the directory in which the script is located isn't always writable (for example when the script is installed through a system package manager and used with mpv --scripts=[path to script]).

A more standard location would perhaps be $XDG_CACHE_HOME/mpv/scripts/sponsorblock/sponsorblock.{txt,db} on Linux. I'm not sure whether similar standard paths are defined on other platforms though.


NixOS/nixpkgs#92507 (comment)

Support for local files downloaded with youtube-dl

By default, youtube-dl name files [Title]-[VIDEOID].[ext]

Since those stuff are close to standard when using youtube-dl, it would be nice if this script could support it.

My idea would be to have a wildcard for every file that end with -ID.mkv and -ID.mp4.

I will soon add something similar in my scripts (but I'm waiting to see how you will implement it (if you do).

Add support for ytdl:// links

mpv has support for ytdl:// links such as ytdl://tHNQOJ_nsLc. Playing it via mpv ytdl://tHNQOJ_nsLc will play the video but sponsorblock is not loaded. Running mpv https://youtu.be/tHNQOJ_nsLc plays the video and sponsorblock works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.