-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathordered-chapters-playlist.lua
45 lines (34 loc) · 1.62 KB
/
ordered-chapters-playlist.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
--[[
This script is for playing files with ordered chapters on filesystems which cannot
be scanned directly by mpv.
The script sets the 'ordered-chapters-files' option to direct mpv to a playlist
file containing the external ordered chapter files. The playlist should use
relative paths in order to work across file systems.
The `playlist_name` variable can be changed to modify what the name of the playlist file should be.
available at: https://github.com/CogentRedTester/mpv-scripts
]]--
local playlist_name = ".ordered-chapters.m3u"
local mp = require 'mp'
local utils = require 'mp.utils'
--returns the file extension of the given file
function get_extension(filename, def)
return string.lower(filename):match("%.([^%./\\]+)$") or def
end
--returns the protocol scheme of the given url, or nil if there is none
function get_protocol(filename, def)
return string.lower(filename):match("^(%a[%w+-.]*)://") or def
end
local function main()
local path = mp.get_property('stream-open-filename')
if get_protocol(path) == "edl" then return end
if get_extension(path) ~= "mkv" then return end
if utils.file_info(path) then return end
path = path:gsub('\\', '/')
local directory = path:sub(1, path:find("/[^/]*$"))
local playlist = directory .. playlist_name
--sets ordered chapters to use a playlist file inside the directory
mp.set_property('file-local-options/ordered-chapters-files', playlist)
end
--we need to run the function for both in case a script has modified the path during the on_load_fail hook
mp.add_hook('on_load', 45, main)
mp.add_hook('on_load_fail', 45, main)