summaryrefslogtreecommitdiff
path: root/mpv/scripts/blacklist-extensions.lua
diff options
context:
space:
mode:
authorilotterytea <ilotterytea@proton.me>2024-05-26 20:10:26 +0500
committerilotterytea <ilotterytea@proton.me>2024-05-26 20:10:26 +0500
commit036c889c4a4f7f59d1e1a592586b54c5c5e93005 (patch)
treeaa76d678790abc79f24edf83c17a564eb2c6f65d /mpv/scripts/blacklist-extensions.lua
initial commitHEADmaster
Diffstat (limited to 'mpv/scripts/blacklist-extensions.lua')
-rw-r--r--mpv/scripts/blacklist-extensions.lua80
1 files changed, 80 insertions, 0 deletions
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)