mirror of
https://github.com/kristoferssolo/solorice.git
synced 2026-03-18 08:09:40 +00:00
84 lines
2.0 KiB
Lua
84 lines
2.0 KiB
Lua
--- @since 26.1.22
|
|
|
|
local M = {}
|
|
local const = require(".const")
|
|
local utils = require(".utils")
|
|
local adobe = require(".adobe")
|
|
local audio = require(".audio")
|
|
local image = require(".image")
|
|
local video = require(".video")
|
|
|
|
function M:peek(job)
|
|
-- debounce peek
|
|
local start = os.clock()
|
|
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))
|
|
|
|
-- Need mime to decide which module to use
|
|
if not job.mime then
|
|
return
|
|
end
|
|
|
|
local is_video = string.find(job.mime, "^video/")
|
|
local is_audio = string.find(job.mime, "^audio/")
|
|
local is_image = string.find(job.mime, "^image/")
|
|
local is_adobe = const.seekable_mimes[job.mime]
|
|
|
|
if is_adobe then
|
|
return adobe:peek(job)
|
|
elseif is_image then
|
|
return image:peek(job)
|
|
elseif is_video then
|
|
return video:peek(job)
|
|
elseif is_audio then
|
|
return audio:peek(job)
|
|
end
|
|
end
|
|
|
|
function M:seek(job)
|
|
local h = cx.active.current.hovered
|
|
if h and h.url == job.file.url then
|
|
utils.set_state(const.STATE_KEY.units, job.units)
|
|
ya.emit("peek", {
|
|
math.max(0, cx.active.preview.skip + job.units),
|
|
only_if = job.file.url,
|
|
})
|
|
end
|
|
end
|
|
function M:preload(job)
|
|
local cache_img_url = ya.file_cache({ file = job.file, skip = 0 })
|
|
if not cache_img_url then
|
|
ya.dbg("mediainfo", "Can't access yazi cache folder")
|
|
return true
|
|
end
|
|
if not job.mime then
|
|
return false
|
|
end
|
|
local is_video = string.find(job.mime, "^video/")
|
|
local is_audio = string.find(job.mime, "^audio/")
|
|
local is_image = string.find(job.mime, "^image/")
|
|
local is_adobe = const.seekable_mimes[job.mime]
|
|
|
|
if is_adobe then
|
|
return adobe:preload(job)
|
|
elseif is_image then
|
|
return image:preload(job)
|
|
elseif is_video then
|
|
return video:preload(job)
|
|
elseif is_audio then
|
|
return audio:preload(job)
|
|
end
|
|
end
|
|
|
|
function M:entry(job)
|
|
local action = job.args[1]
|
|
|
|
if action == const.ENTRY_ACTION.toggle_metadata then
|
|
utils.set_state(const.STATE_KEY.hide_metadata, not utils.get_state(const.STATE_KEY.hide_metadata))
|
|
ya.emit("peek", {
|
|
force = true,
|
|
})
|
|
end
|
|
end
|
|
|
|
return M
|