mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-09-23 02:28:54 +02:00
42 lines
1.6 KiB
Fennel
42 lines
1.6 KiB
Fennel
;<! tmpl:setPostProcessor(opt.fennelCompile) !>
|
|
; vim: filetype=fennel
|
|
|
|
;; MPV script to skip SponsorBlock segments added by yt-dlp's `--sponsorblock-mark=all` option
|
|
|
|
;; list of SponsorBlock segment types to skip
|
|
(local blacklist [:Intro :Sponsor :Outro :Endcards/Credits "Intermission/Intro Animation"])
|
|
|
|
;; chapters alredy skipped this file
|
|
;; table of chapter id => true
|
|
(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#]
|
|
(when (and chapter# (not (. skipped chapter#)))
|
|
(let [chapter-list (mp.get_property_native :chapter-list)
|
|
chapter (. chapter-list (+ chapter# 1))
|
|
next (. chapter-list (+ chapter# 2))
|
|
seg-type (string.match chapter.title "%[SponsorBlock%]: (.*)")]
|
|
;; when the pattern matches and the type isn't blacklisted...
|
|
(when (and seg-type (should-skip seg-type))
|
|
(msg (.. "skip: " seg-type))
|
|
;; add to skipped to not skip chapter again
|
|
(tset skipped chapter# true)
|
|
;; set time to start of next chapter or end of video
|
|
(mp.set_property :time-pos (if next next.time
|
|
(mp.get_property_native :duration)))))))
|
|
|
|
(mp.observe_property :chapter :number on-chapter-change)
|
|
(mp.register_event :file-loaded #(set skipped {})) ;; reset skipped chapters on file load
|