From 036c889c4a4f7f59d1e1a592586b54c5c5e93005 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 26 May 2024 20:10:26 +0500 Subject: initial commit --- mpv/scripts/blacklist-extensions.lua | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 mpv/scripts/blacklist-extensions.lua (limited to 'mpv/scripts/blacklist-extensions.lua') diff --git a/mpv/scripts/blacklist-extensions.lua b/mpv/scripts/blacklist-extensions.lua new file mode 100644 index 0000000..a8ec638 --- /dev/null +++ b/mpv/scripts/blacklist-extensions.lua @@ -0,0 +1,80 @@ +-- From: https://github.com/occivink/mpv-scripts + +opts = { + blacklist="", + whitelist="", + remove_files_without_extension = false, + oneshot = true, +} +(require 'mp.options').read_options(opts) +local msg = require 'mp.msg' + +function split(input) + local ret = {} + for str in string.gmatch(input, "([^,]+)") do + ret[#ret + 1] = str + end + return ret +end + +opts.blacklist = split(opts.blacklist) +opts.whitelist = split(opts.whitelist) + +local exclude +if #opts.whitelist > 0 then + exclude = function(extension) + for _, ext in pairs(opts.whitelist) do + if extension == ext then + return false + end + end + return true + end +elseif #opts.blacklist > 0 then + exclude = function(extension) + for _, ext in pairs(opts.blacklist) do + if extension == ext then + return true + end + end + return false + end +else + return +end + +function should_remove(filename) + if string.find(filename, "://") then + return false + end + local extension = string.match(filename, "%.([^./]+)$") + if not extension and opts.remove_file_without_extension then + return true + end + if extension and exclude(string.lower(extension)) then + return true + end + return false +end + +function process(playlist_count) + if playlist_count < 2 then return end + if opts.oneshot then + mp.unobserve_property(observe) + end + local playlist = mp.get_property_native("playlist") + local removed = 0 + for i = #playlist, 1, -1 do + if should_remove(playlist[i].filename) then + mp.commandv("playlist-remove", i-1) + removed = removed + 1 + end + end + if removed == #playlist then + msg.warn("Removed eveything from the playlist") + end +end + +function observe(k,v) process(v) end + +mp.observe_property("playlist-count", "number", observe) -- cgit v1.2.3