2023-12-26 14:48:33 +03:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M:peek()
|
2024-01-11 20:35:57 +03:00
|
|
|
local cache = ya.file_cache(self)
|
|
|
|
if not cache then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-12-26 14:48:33 +03:00
|
|
|
if self:preload() == 1 then
|
2024-01-11 20:35:57 +03:00
|
|
|
ya.image_show(cache, self.area)
|
2023-12-26 14:48:33 +03:00
|
|
|
ya.preview_widgets(self, {})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function M:seek(units)
|
|
|
|
local h = cx.active.current.hovered
|
|
|
|
if h and h.url == self.file.url then
|
|
|
|
ya.manager_emit("peek", {
|
2024-03-01 05:22:12 +03:00
|
|
|
math.max(0, cx.active.preview.skip + units),
|
2024-04-22 09:18:00 +03:00
|
|
|
only_if = self.file.url,
|
2023-12-26 14:48:33 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function M:preload()
|
|
|
|
local percentage = 5 + self.skip
|
|
|
|
if percentage > 95 then
|
2024-04-22 09:18:00 +03:00
|
|
|
ya.manager_emit("peek", { 90, only_if = self.file.url, upper_bound = true })
|
2023-12-26 14:48:33 +03:00
|
|
|
return 2
|
|
|
|
end
|
|
|
|
|
2024-01-11 20:35:57 +03:00
|
|
|
local cache = ya.file_cache(self)
|
2024-01-15 13:30:50 +03:00
|
|
|
if not cache or fs.cha(cache) then
|
2023-12-26 14:48:33 +03:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2024-01-09 22:12:57 +03:00
|
|
|
local child, code = Command("ffmpegthumbnailer"):args({
|
2024-01-01 13:28:38 +03:00
|
|
|
"-q",
|
|
|
|
"6",
|
|
|
|
"-c",
|
|
|
|
"jpeg",
|
|
|
|
"-i",
|
|
|
|
tostring(self.file.url),
|
|
|
|
"-o",
|
|
|
|
tostring(cache),
|
|
|
|
"-t",
|
|
|
|
tostring(percentage),
|
|
|
|
"-s",
|
|
|
|
tostring(PREVIEW.max_width),
|
|
|
|
}):spawn()
|
|
|
|
|
|
|
|
if not child then
|
2024-01-09 22:12:57 +03:00
|
|
|
ya.err("spawn `ffmpegthumbnailer` command returns " .. tostring(code))
|
2024-01-01 13:28:38 +03:00
|
|
|
return 0
|
|
|
|
end
|
2023-12-26 14:48:33 +03:00
|
|
|
|
2024-01-01 13:28:38 +03:00
|
|
|
local status = child:wait()
|
2024-05-30 20:09:30 +03:00
|
|
|
return status and status.success and 1 or 2
|
2023-12-26 14:48:33 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|