mirror of https://github.com/mpv-player/mpv
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
This commit is contained in:
parent
64ae475e40
commit
35e8710b86
|
@ -5,6 +5,20 @@
|
||||||
-- the internal playlist. (It stops if the it would add an already existing
|
-- the internal playlist. (It stops if the it would add an already existing
|
||||||
-- playlist entry at the same position - this makes it "stable".)
|
-- playlist entry at the same position - this makes it "stable".)
|
||||||
-- Add at most 5000 * 2 files when starting a file (before + after).
|
-- 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
|
MAXENTRIES = 5000
|
||||||
|
|
||||||
local msg = require 'mp.msg'
|
local msg = require 'mp.msg'
|
||||||
|
@ -12,7 +26,10 @@ local options = require 'mp.options'
|
||||||
local utils = require 'mp.utils'
|
local utils = require 'mp.utils'
|
||||||
|
|
||||||
o = {
|
o = {
|
||||||
disabled = false
|
disabled = false,
|
||||||
|
images = true,
|
||||||
|
videos = true,
|
||||||
|
audio = true
|
||||||
}
|
}
|
||||||
options.read_options(o)
|
options.read_options(o)
|
||||||
|
|
||||||
|
@ -22,11 +39,30 @@ function Set (t)
|
||||||
return set
|
return set
|
||||||
end
|
end
|
||||||
|
|
||||||
EXTENSIONS = Set {
|
function SetUnion (a,b)
|
||||||
'mkv', 'avi', 'mp4', 'ogv', 'webm', 'rmvb', 'flv', 'wmv', 'mpeg', 'mpg', 'm4v', '3gp',
|
local res = {}
|
||||||
'mp3', 'wav', 'ogm', 'flac', 'm4a', 'wma', 'ogg', 'opus',
|
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)
|
function add_files_at(index, files)
|
||||||
index = index - 1
|
index = index - 1
|
||||||
local oldcount = mp.get_property_number("playlist-count", 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
|
-- check if this is a manually made playlist
|
||||||
if (pl_count > 1 and autoloaded == nil) or
|
if (pl_count > 1 and autoloaded == nil) or
|
||||||
(pl_count == 1 and EXTENSIONS[string.lower(get_extension(filename))] == nil) then
|
(pl_count == 1 and EXTENSIONS[string.lower(get_extension(filename))] == nil) then
|
||||||
|
msg.verbose("stopping: manually made playlist")
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
autoloaded = true
|
autoloaded = true
|
||||||
|
@ -114,6 +151,7 @@ function find_and_add_entries()
|
||||||
|
|
||||||
local files = utils.readdir(dir, "files")
|
local files = utils.readdir(dir, "files")
|
||||||
if files == nil then
|
if files == nil then
|
||||||
|
msg.verbose("no other files in directory")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
table.filter(files, function (v, k)
|
table.filter(files, function (v, k)
|
||||||
|
|
Loading…
Reference in New Issue