2023-01-26 17:05:01 +00:00
|
|
|
local utils = require 'mp.utils'
|
|
|
|
local msg = require 'mp.msg'
|
|
|
|
local options = require 'mp.options'
|
|
|
|
|
|
|
|
|
|
|
|
function sleep(n)
|
|
|
|
os.execute("sleep " .. tonumber(n))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function createDir(dirname)
|
|
|
|
os.execute("mkdir -p -m 711 " .. dirname)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function file_exists(name)
|
|
|
|
local f = io.open(name, "r")
|
|
|
|
return f ~= nil and io.close(f)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function get_url_host(s)
|
|
|
|
return (s.."/"):match("://(.-)/")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make_cache_track(url)
|
2023-06-13 13:18:07 +00:00
|
|
|
mp.command('script-message streamsave-autostart no')
|
2023-01-26 17:05:01 +00:00
|
|
|
find_uuid = "%x+-%x+-%x+-%x+-%x+"
|
|
|
|
uuid = string.sub(url, string.find(url, find_uuid))
|
|
|
|
host = get_url_host(url)
|
2023-03-04 01:23:18 +00:00
|
|
|
cache_path_file = 'cache/' .. host .. '/' .. uuid .. '.mkv'
|
2023-06-13 13:18:07 +00:00
|
|
|
cache_path_named_file = 'cache/' .. host .. '/' .. uuid .. '.mkv'
|
2023-01-26 17:05:01 +00:00
|
|
|
if false == file_exists(cache_path_file) then
|
|
|
|
createDir('cache/' .. host .. '/')
|
|
|
|
msg.verbose('Caching ' .. cache_path_file .. '')
|
2023-03-04 00:25:09 +00:00
|
|
|
mp.command('script-message streamsave-title ' .. uuid .. '')
|
2023-06-13 13:18:07 +00:00
|
|
|
mp.command('script-message streamsave-force_title ' .. uuid .. '')
|
|
|
|
mp.command('script-message streamsave-label overwrite')
|
2023-03-04 00:25:09 +00:00
|
|
|
mp.set_property('script-opts/media-uuid', uuid)
|
2023-03-04 01:23:18 +00:00
|
|
|
mp.command('script-message streamsave-extension .mkv')
|
2023-03-04 00:25:09 +00:00
|
|
|
mp.command('script-message streamsave-path cache/' .. host .. '')
|
2023-06-13 13:18:07 +00:00
|
|
|
mp.command('script-message streamsave-autostart yes')
|
2023-01-26 17:05:01 +00:00
|
|
|
else
|
|
|
|
msg.verbose('Already cached ' .. cache_path_file .. '')
|
2023-02-05 00:02:32 +00:00
|
|
|
os.execute('touch ' .. cache_path_file .. '')
|
2023-01-26 17:05:01 +00:00
|
|
|
mp.set_property("stream-open-filename", cache_path_file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
mp.add_hook("on_load", 11, function()
|
|
|
|
msg.verbose('reusable cache hook activated')
|
|
|
|
local url = mp.get_property("stream-open-filename", "")
|
|
|
|
if true == (url:find("https?://") == 1) then
|
|
|
|
make_cache_track(url)
|
|
|
|
end
|
|
|
|
end)
|
2023-06-13 13:18:07 +00:00
|
|
|
|
|
|
|
mp.register_event("file-loaded", function()
|
|
|
|
msg.verbose('reusable cache post-hook activated')
|
|
|
|
local url = mp.get_property("stream-open-filename", "")
|
|
|
|
if true == (url:find("https?://") == 1) then
|
|
|
|
make_cache_track(url)
|
|
|
|
end
|
|
|
|
end)
|