Update 2025-05-31

Update 2025-05-06

Update 2025-05-09

Update 2025-05-11

Update 2025-05-13

Update 2025-05-18

Update 2025-05-19

Update 2025-05-24

Update 2025-05-27

Update 2025-05-29

Update 2025-05-31
This commit is contained in:
2025-05-01 17:16:25 +03:00
parent d028d0ad38
commit 1d7d0b7c22
54 changed files with 1577 additions and 521 deletions

View File

@@ -10,7 +10,7 @@ This is a Yazi plugin for previewing media files. The preview shows thumbnail
using `ffmpeg` if available and media metadata using `mediainfo`.
> [!IMPORTANT]
> Minimum version: yazi v25.2.7.
> Minimum version: yazi v25.5.28.
## Preview
@@ -48,13 +48,14 @@ Install mediainfo CLI:
Install + config this plugin:
> [!IMPORTANT]
> `mediainfo` use video, image, svg, magick built-in plugins behind the scene to render preview image, song cover.
> [!IMPORTANT] > `mediainfo` use video, image, svg, magick built-in plugins behind the scene to render preview image, song cover.
> So you can remove those 3 plugins from `preloaders` and `previewers` sections in `yazi.toml`.
If you have cache problem, run this cmd, and follow the tips: `yazi --clear-cache`
```bash
ya pkg add boydaihungst/mediainfo
# or
ya pack -a boydaihungst/mediainfo
```

View File

@@ -1,4 +1,4 @@
--- @since 25.2.7
--- @since 25.5.28
local skip_labels = {
["Complete name"] = true,
@@ -56,13 +56,13 @@ function M:peek(job)
return
end
local cache_mediainfo_path = tostring(cache_img_url_no_skip) .. suffix
ya.sleep(math.max(0, (rt and rt.preview or PREVIEW).image_delay / 1000 + start - os.clock()))
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))
local output = read_mediainfo_cached_file(cache_mediainfo_path)
local lines = {}
local max_lines = math.floor(job.area.h / 2)
local last_line = 0
local is_wrap = rt and rt.preview and rt.preview.wrap == "yes"
local is_wrap = rt.preview.wrap == "yes"
if output then
local max_width = math.max(1, job.area.w)
@@ -82,11 +82,11 @@ function M:peek(job)
if not skip_labels[label] then
line = ui.Line({
ui.Span(label .. ": "):style(ui.Style():fg("reset"):bold()),
ui.Span(value):style((th and th.spot and th.spot.tbl_col) or ui.Style():fg("blue")),
ui.Span(value):style(th.spot.tbl_col or ui.Style():fg("blue")),
})
end
elseif str ~= "General" then
line = ui.Line({ ui.Span(str):style((th and th.spot and th.spot.title) or ui.Style():fg("green")) })
line = ui.Line({ ui.Span(str):style(th.spot.title or ui.Style():fg("green")) })
end
if line then
@@ -105,7 +105,7 @@ function M:peek(job)
local mediainfo_height = math.min(max_lines, last_line)
if (job.skip > 0 and #lines == 0) and (not is_video or (is_video and job.skip >= 90)) then
ya.manager_emit("peek", { math.max(0, job.skip - max_lines), only_if = job.file.url, upper_bound = false })
ya.emit("peek", { math.max(0, job.skip - max_lines), only_if = job.file.url, upper_bound = false })
return
end
local rendered_img_rect = cache_img_url
@@ -121,7 +121,7 @@ function M:peek(job)
or nil
local image_height = rendered_img_rect and rendered_img_rect.h or 0
ya.preview_widgets(job, {
ya.preview_widget(job, {
ui.Text(lines)
:area(ui.Rect({
x = job.area.x,
@@ -136,8 +136,7 @@ end
function M:seek(job)
local h = cx.active.current.hovered
if h and h.url == job.file.url then
local step = ya.clamp(-10, job.units, 10)
ya.manager_emit("peek", {
ya.emit("peek", {
math.max(0, cx.active.preview.skip + job.units),
only_if = job.file.url,
})
@@ -165,8 +164,8 @@ function M:preload(job)
if cache_img_url_no_skip and (not cache_img_url_no_skip_cha or cache_img_url_no_skip_cha.len <= 0) then
-- audio
if job.mime and string.find(job.mime, "^audio/") then
local qv = 31 - math.floor((rt and rt.preview or PREVIEW).image_quality * 0.3)
local status, _ = Command("ffmpeg"):args({
local qv = 31 - math.floor(rt.preview.image_quality * 0.3)
local status, _ = Command("ffmpeg"):arg({
"-v",
"quiet",
"-threads",
@@ -185,10 +184,7 @@ function M:preload(job)
"-q:v",
qv,
"-vf",
string.format(
"scale=-1:'min(%d,ih)':flags=fast_bilinear",
(rt and rt.preview or PREVIEW).max_height / 2
),
string.format("scale=-1:'min(%d,ih)':flags=fast_bilinear", rt.preview.max_height / 2),
"-f",
"image2",
"-y",
@@ -224,7 +220,7 @@ function M:preload(job)
return true
end
local cmd = "mediainfo"
local output, err = Command(cmd):args({ tostring(job.file.url) }):stdout(Command.PIPED):output()
local output, err = Command(cmd):arg({ tostring(job.file.url) }):stdout(Command.PIPED):output()
if err then
err_msg = err_msg .. string.format("Failed to start `%s`, Do you have `%s` installed?\n", cmd, cmd)
end