2021-03-16 13:37:38 +00:00
|
|
|
-- gallery-dl_hook.lua
|
|
|
|
--
|
|
|
|
-- load online image galleries as playlists using gallery-dl
|
|
|
|
-- https://github.com/mikf/gallery-dl
|
|
|
|
--
|
|
|
|
-- to use, prepend the gallery url with: gallery-dl://
|
|
|
|
-- e.g.
|
|
|
|
-- `mpv gallery-dl://https://imgur.com/....`
|
|
|
|
|
2023-05-23 13:31:17 +00:00
|
|
|
local mp = require 'mp'
|
2021-03-16 13:37:38 +00:00
|
|
|
local utils = require 'mp.utils'
|
|
|
|
local msg = require 'mp.msg'
|
|
|
|
|
|
|
|
local function exec(args)
|
2023-05-23 13:31:17 +00:00
|
|
|
local ret = utils.subprocess({ args = args })
|
2021-03-16 13:37:38 +00:00
|
|
|
return ret.status, ret.stdout, ret
|
|
|
|
end
|
|
|
|
|
|
|
|
mp.add_hook("on_load", 15, function()
|
2023-05-23 13:31:17 +00:00
|
|
|
local fn = mp.get_property("stream-open-filename", "")
|
|
|
|
if (fn:find("gdl://") ~= 1) then
|
|
|
|
msg.debug("not a gdl:// url: " .. fn)
|
2021-03-16 13:37:38 +00:00
|
|
|
return
|
|
|
|
end
|
2023-05-23 13:31:17 +00:00
|
|
|
local url = string.gsub(url, "gdl://", "")
|
2021-03-16 13:37:38 +00:00
|
|
|
|
2023-05-23 13:31:17 +00:00
|
|
|
local es, urls, result = exec({ "gallery-dl", "-g", url })
|
2021-03-16 13:37:38 +00:00
|
|
|
if (es < 0) or (urls == nil) or (urls == "") then
|
|
|
|
msg.error("failed to get album list.")
|
|
|
|
end
|
|
|
|
|
|
|
|
mp.commandv("loadlist", "memory://" .. urls)
|
|
|
|
end)
|