feat: added autoload_types
option
Controls what file types to look for when deciding next file to play. Comma separated list of: `video`, `audio`, `image`, `subtitle` closes #387
This commit is contained in:
@@ -142,6 +142,9 @@ window_border_opacity=0.8
|
||||
# If there's no playlist and file ends, load next file in the directory
|
||||
# Requires `keep-open=yes` in `mpv.conf`.
|
||||
autoload=no
|
||||
# What types to accept as next item when autoloading or requesting to play next file
|
||||
# Can be: video, audio, image, subtitle
|
||||
autoload_types=video,audio,image
|
||||
# Enable uosc's playlist/directory shuffle mode
|
||||
# This simply makes the next selected playlist or directory item be random, just
|
||||
# like any other player in the world. It also has an easily togglable control button.
|
||||
|
@@ -74,6 +74,7 @@ defaults = {
|
||||
window_border_opacity = 0.8,
|
||||
|
||||
autoload = false,
|
||||
autoload_types = 'video,audio,image',
|
||||
shuffle = false,
|
||||
|
||||
ui_scale = 1,
|
||||
@@ -174,6 +175,15 @@ config = {
|
||||
audio = split(options.audio_types, ' *, *'),
|
||||
image = split(options.image_types, ' *, *'),
|
||||
media = split(options.video_types .. ',' .. options.audio_types .. ',' .. options.image_types, ' *, *'),
|
||||
autoload = (function()
|
||||
---@type string[]
|
||||
local option_values = {}
|
||||
for _, name in ipairs(split(options.autoload_types, ' *, *')) do
|
||||
local value = options[name .. '_types']
|
||||
if type(value) == 'string' then option_values[#option_values + 1] = value end
|
||||
end
|
||||
return split(table.concat(option_values, ','), ' *, *')
|
||||
end)(),
|
||||
subtitle = split(options.subtitle_types, ' *, *'),
|
||||
},
|
||||
stream_quality_options = split(options.stream_quality_options, ' *, *'),
|
||||
@@ -500,7 +510,7 @@ function load_file_index_in_current_directory(index)
|
||||
|
||||
local serialized = serialize_path(state.path)
|
||||
if serialized and serialized.dirname then
|
||||
local files = read_directory(serialized.dirname, config.types.media)
|
||||
local files = read_directory(serialized.dirname, config.types.autoload)
|
||||
|
||||
if not files then return end
|
||||
sort_filenames(files)
|
||||
@@ -1025,7 +1035,7 @@ bind_command('delete-file-next', function()
|
||||
mp.commandv('playlist-remove', 'current')
|
||||
else
|
||||
if is_local_file then
|
||||
local paths, current_index = get_adjacent_files(state.path, config.types.media)
|
||||
local paths, current_index = get_adjacent_files(state.path, config.types.autoload)
|
||||
if paths and current_index then
|
||||
local index, path = decide_navigation_in_list(paths, current_index, 1)
|
||||
if path then next_file = path end
|
||||
|
@@ -312,21 +312,25 @@ function read_directory(path, allowed_types)
|
||||
return files, directories
|
||||
end
|
||||
|
||||
-- Returns full absolute paths of files in the same directory as file_path,
|
||||
-- Returns full absolute paths of files in the same directory as `file_path`,
|
||||
-- and index of the current file in the table.
|
||||
-- Returned table will always contain `file_path`, regardless of `allowed_types`.
|
||||
---@param file_path string
|
||||
---@param allowed_types? string[]
|
||||
---@param allowed_types? string[] Filter adjacent file types. Does NOT filter out the `file_path`.
|
||||
function get_adjacent_files(file_path, allowed_types)
|
||||
local current_file = serialize_path(file_path)
|
||||
if not current_file then return end
|
||||
local files = read_directory(current_file.dirname, allowed_types)
|
||||
local current_meta = serialize_path(file_path)
|
||||
if not current_meta then return end
|
||||
local files = read_directory(current_meta.dirname)
|
||||
if not files then return end
|
||||
sort_filenames(files)
|
||||
local current_file_index
|
||||
local paths = {}
|
||||
for index, file in ipairs(files) do
|
||||
paths[#paths + 1] = join_path(current_file.dirname, file)
|
||||
if current_file.basename == file then current_file_index = index end
|
||||
for _, file in ipairs(files) do
|
||||
local is_current_file = current_meta.basename == file
|
||||
if is_current_file or not allowed_types or has_any_extension(file, allowed_types) then
|
||||
paths[#paths + 1] = join_path(current_meta.dirname, file)
|
||||
if is_current_file then current_file_index = #paths end
|
||||
end
|
||||
end
|
||||
if not current_file_index then return end
|
||||
return paths, current_file_index
|
||||
@@ -361,7 +365,7 @@ end
|
||||
---@param delta number
|
||||
function navigate_directory(delta)
|
||||
if not state.path or is_protocol(state.path) then return false end
|
||||
local paths, current_index = get_adjacent_files(state.path, config.types.media)
|
||||
local paths, current_index = get_adjacent_files(state.path, config.types.autoload)
|
||||
if paths and current_index then
|
||||
local _, path = decide_navigation_in_list(paths, current_index, delta)
|
||||
if path then mp.commandv('loadfile', path) return true end
|
||||
|
Reference in New Issue
Block a user