summaryrefslogtreecommitdiffstats
path: root/TOOLS/lua
diff options
context:
space:
mode:
authorMarek Sebera <marek.sebera@gmail.com>2019-09-24 22:16:30 +0200
committerwm4 <1387750+wm4@users.noreply.github.com>2019-10-02 12:48:56 +0200
commit35e8710b86545849484f6544a16047792fa75bb2 (patch)
treec9ecbc7c9cefecec81e3b60d015e80f37e29df9b /TOOLS/lua
parent64ae475e403b2159be0e6e11d1215cc80b8cb090 (diff)
downloadmpv-35e8710b86545849484f6544a16047792fa75bb2.tar.bz2
mpv-35e8710b86545849484f6544a16047792fa75bb2.tar.xz
autoload.lua: Configurable autoload types
Autoload script now suppports loading of not only video, but also image and audio files, in a manner, where one can configure which of the groups (audio, videos, images) is currently enabled. Use file script-opts/autoload.conf with key=value configuration keys disabled,images,videos,audio to configure autoload script. See documentation on top of the script
Diffstat (limited to 'TOOLS/lua')
-rw-r--r--TOOLS/lua/autoload.lua46
1 files changed, 42 insertions, 4 deletions
diff --git a/TOOLS/lua/autoload.lua b/TOOLS/lua/autoload.lua
index 351b87bbbf..92456bc02d 100644
--- a/TOOLS/lua/autoload.lua
+++ b/TOOLS/lua/autoload.lua
@@ -5,6 +5,20 @@
-- the internal playlist. (It stops if the it would add an already existing
-- playlist entry at the same position - this makes it "stable".)
-- Add at most 5000 * 2 files when starting a file (before + after).
+
+--[[
+To configure this script use file autoload.conf in director script-opts (the "script-opts"
+directory must be in the mpv configuration directory, typically ~/.config/mpv/).
+
+Example configuration would be:
+
+disabled=false
+images=false
+videos=true
+audio=true
+
+--]]
+
MAXENTRIES = 5000
local msg = require 'mp.msg'
@@ -12,7 +26,10 @@ local options = require 'mp.options'
local utils = require 'mp.utils'
o = {
- disabled = false
+ disabled = false,
+ images = true,
+ videos = true,
+ audio = true
}
options.read_options(o)
@@ -22,11 +39,30 @@ function Set (t)
return set
end
-EXTENSIONS = Set {
- 'mkv', 'avi', 'mp4', 'ogv', 'webm', 'rmvb', 'flv', 'wmv', 'mpeg', 'mpg', 'm4v', '3gp',
- 'mp3', 'wav', 'ogm', 'flac', 'm4a', 'wma', 'ogg', 'opus',
+function SetUnion (a,b)
+ local res = {}
+ for k in pairs(a) do res[k] = true end
+ for k in pairs(b) do res[k] = true end
+ return res
+end
+
+EXTENSIONS_VIDEO = Set {
+ 'mkv', 'avi', 'mp4', 'ogv', 'webm', 'rmvb', 'flv', 'wmv', 'mpeg', 'mpg', 'm4v', '3gp'
+}
+
+EXTENSIONS_AUDIO = Set {
+ 'mp3', 'wav', 'ogm', 'flac', 'm4a', 'wma', 'ogg', 'opus'
}
+EXTENSIONS_IMAGES = Set {
+ 'jpg', 'jpeg', 'png', 'tif', 'tiff', 'gif', 'webp', 'svg', 'bmp'
+}
+
+EXTENSIONS = Set {}
+if o.videos then EXTENSIONS = SetUnion(EXTENSIONS, EXTENSIONS_VIDEO) end
+if o.audio then EXTENSIONS = SetUnion(EXTENSIONS, EXTENSIONS_AUDIO) end
+if o.images then EXTENSIONS = SetUnion(EXTENSIONS, EXTENSIONS_IMAGES) end
+
function add_files_at(index, files)
index = index - 1
local oldcount = mp.get_property_number("playlist-count", 1)
@@ -102,6 +138,7 @@ function find_and_add_entries()
-- check if this is a manually made playlist
if (pl_count > 1 and autoloaded == nil) or
(pl_count == 1 and EXTENSIONS[string.lower(get_extension(filename))] == nil) then
+ msg.verbose("stopping: manually made playlist")
return
else
autoloaded = true
@@ -114,6 +151,7 @@ function find_and_add_entries()
local files = utils.readdir(dir, "files")
if files == nil then
+ msg.verbose("no other files in directory")
return
end
table.filter(files, function (v, k)