mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-14 12:23:40 +01:00
rework mpv sbskip script
This commit is contained in:
parent
377a7c058e
commit
ab61721503
1 changed files with 17 additions and 7 deletions
|
@ -3,13 +3,26 @@
|
||||||
|
|
||||||
;; MPV script to skip SponsorBlock segments added by yt-dlp's `--sponsorblock-mark=all` option
|
;; MPV script to skip SponsorBlock segments added by yt-dlp's `--sponsorblock-mark=all` option
|
||||||
|
|
||||||
;; list of SponsorBlock segment types NOT to skip
|
;; list of SponsorBlock segment types to skip
|
||||||
(local blacklist [:Highlight])
|
(local blacklist [:Intro :Sponsor :Outro :Endcards/Credits :Inermission])
|
||||||
|
|
||||||
;; chapters alredy skipped this file
|
;; chapters alredy skipped this file
|
||||||
;; table of chapter id => true
|
;; table of chapter id => true
|
||||||
(var skipped {})
|
(var skipped {})
|
||||||
|
|
||||||
|
(fn should-skip [typestr]
|
||||||
|
(accumulate [matched false
|
||||||
|
ty (string.gmatch typestr "([^,]+),?%s*")
|
||||||
|
&until matched]
|
||||||
|
(accumulate [blacklisted false
|
||||||
|
_ bl (ipairs blacklist)
|
||||||
|
&until blacklisted]
|
||||||
|
(= ty bl))))
|
||||||
|
|
||||||
|
(fn msg [msg]
|
||||||
|
(print msg)
|
||||||
|
(mp.osd_message (.. "[sbskip] " msg) 4))
|
||||||
|
|
||||||
(fn on-chapter-change [_ chapter#]
|
(fn on-chapter-change [_ chapter#]
|
||||||
(when (and chapter# (not (. skipped chapter#)))
|
(when (and chapter# (not (. skipped chapter#)))
|
||||||
(let [chapter-list (mp.get_property_native :chapter-list)
|
(let [chapter-list (mp.get_property_native :chapter-list)
|
||||||
|
@ -17,11 +30,8 @@
|
||||||
next (. chapter-list (+ chapter# 2))
|
next (. chapter-list (+ chapter# 2))
|
||||||
seg-type (string.match chapter.title "%[SponsorBlock%]: (.*)")]
|
seg-type (string.match chapter.title "%[SponsorBlock%]: (.*)")]
|
||||||
;; when the pattern matches and the type isn't blacklisted...
|
;; when the pattern matches and the type isn't blacklisted...
|
||||||
(when (and seg-type (not (accumulate [has false
|
(when (and seg-type (should-skip seg-type))
|
||||||
_ type (ipairs blacklist)
|
(msg (.. "skip: " seg-type))
|
||||||
&until has]
|
|
||||||
(= type seg-type))))
|
|
||||||
(mp.osd_message (.. "[sbskip] skip: " seg-type) 4)
|
|
||||||
;; add to skipped to not skip chapter again
|
;; add to skipped to not skip chapter again
|
||||||
(tset skipped chapter# true)
|
(tset skipped chapter# true)
|
||||||
;; set time to start of next chapter or end of video
|
;; set time to start of next chapter or end of video
|
||||||
|
|
Loading…
Reference in a new issue