diff options
| author | omagdy <omar.professional8777@gmail.com> | 2025-01-01 21:01:47 +0200 |
|---|---|---|
| committer | omagdy <omar.professional8777@gmail.com> | 2025-01-01 21:01:47 +0200 |
| commit | 73d94f515e632a94fcbaa041438abf8f34971eb7 (patch) | |
| tree | 60456ceea1f5505316a95c8cfe25018b3509cbec /yazi | |
| parent | 71d81e0a24a4e26f2ce8f6327ac80a501d4f4636 (diff) | |
| download | dotfiles-73d94f515e632a94fcbaa041438abf8f34971eb7.tar.xz dotfiles-73d94f515e632a94fcbaa041438abf8f34971eb7.zip | |
update
Diffstat (limited to 'yazi')
| -rw-r--r-- | yazi/.config/yazi/keymap.toml | 5 | ||||
| -rw-r--r-- | yazi/.config/yazi/package.toml | 5 | ||||
| -rw-r--r-- | yazi/.config/yazi/plugins/mediainfo.yazi/DO_NOT_MODIFY_ANYTHING_IN_THIS_DIRECTORY | 0 | ||||
| -rw-r--r-- | yazi/.config/yazi/plugins/mediainfo.yazi/LICENSE | 19 | ||||
| -rw-r--r-- | yazi/.config/yazi/plugins/mediainfo.yazi/README.md | 29 | ||||
| -rw-r--r-- | yazi/.config/yazi/plugins/mediainfo.yazi/init.lua | 115 | ||||
| -rw-r--r-- | yazi/.config/yazi/yazi.toml | 5 |
7 files changed, 178 insertions, 0 deletions
diff --git a/yazi/.config/yazi/keymap.toml b/yazi/.config/yazi/keymap.toml index f01816a..a5105a4 100644 --- a/yazi/.config/yazi/keymap.toml +++ b/yazi/.config/yazi/keymap.toml @@ -7,3 +7,8 @@ desc = "Cd to College folder" on = [ "g", "p" ] run = "cd ~/programming/" desc = "Cd to ~/programming" + +[[manager.prepend_keymap]] +on = [ "g", "b" ] +run = "cd /mnt/Storage/omar/Books/" +desc = "Cd to Books" diff --git a/yazi/.config/yazi/package.toml b/yazi/.config/yazi/package.toml new file mode 100644 index 0000000..fe5ac43 --- /dev/null +++ b/yazi/.config/yazi/package.toml @@ -0,0 +1,5 @@ +[plugin] +deps = [{ use = "boydaihungst/mediainfo", rev = "ddfd5ec" }] + +[flavor] +deps = [] diff --git a/yazi/.config/yazi/plugins/mediainfo.yazi/DO_NOT_MODIFY_ANYTHING_IN_THIS_DIRECTORY b/yazi/.config/yazi/plugins/mediainfo.yazi/DO_NOT_MODIFY_ANYTHING_IN_THIS_DIRECTORY new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/yazi/.config/yazi/plugins/mediainfo.yazi/DO_NOT_MODIFY_ANYTHING_IN_THIS_DIRECTORY diff --git a/yazi/.config/yazi/plugins/mediainfo.yazi/LICENSE b/yazi/.config/yazi/plugins/mediainfo.yazi/LICENSE new file mode 100644 index 0000000..0399f1c --- /dev/null +++ b/yazi/.config/yazi/plugins/mediainfo.yazi/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2024 Lauri Niskanen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/yazi/.config/yazi/plugins/mediainfo.yazi/README.md b/yazi/.config/yazi/plugins/mediainfo.yazi/README.md new file mode 100644 index 0000000..45d04be --- /dev/null +++ b/yazi/.config/yazi/plugins/mediainfo.yazi/README.md @@ -0,0 +1,29 @@ +# mediainfo.yazi + +<!--toc:start--> + +- [mediainfo.yazi](#mediainfoyazi) + - [Installation](#installation) + <!--toc:end--> + +This is a Yazi plugin for previewing media files. The preview shows thumbnail +using `ffmpeg` if available and media metadata using `mediainfo`. +Only for yazi >= 0.4 + +## Installation + +Install the plugin: + +```bash +ya pack -a boydaihungst/mediainfo +``` + +Create `~/.config/yazi/yazi.toml` and add: + +```toml +[plugin] +prepend_previewers = [ + { mime = "{image,audio,video}/*", run = "mediainfo"}, + { mime = "application/subrip", run = "mediainfo"}, +] +``` diff --git a/yazi/.config/yazi/plugins/mediainfo.yazi/init.lua b/yazi/.config/yazi/plugins/mediainfo.yazi/init.lua new file mode 100644 index 0000000..b583b06 --- /dev/null +++ b/yazi/.config/yazi/plugins/mediainfo.yazi/init.lua @@ -0,0 +1,115 @@ +local skip_labels = { + ["Complete name"] = true, + ["CompleteName_Last"] = true, + ["Unique ID"] = true, + ["File size"] = true, + ["Format/Info"] = true, + ["Codec ID/Info"] = true, + ["MD5 of the unencoded content"] = true, +} + +local M = {} +local suffix = "_mediainfo" + +local function read_mediainfo_cached_file(file_path) + -- Open the file in read mode + local file = io.open(file_path, "r") + + if file then + -- Read the entire file content + local content = file:read("*all") + file:close() + return content + end +end + +function M:peek(job) + local start, cache_img_url = os.clock(), ya.file_cache(job) + if not cache_img_url or self:preload(job) ~= 1 then + return + end + + local cache_img_url_no_skip = ya.file_cache({ file = job.file, skip = 0 }) + local cache_mediainfo_path = tostring(cache_img_url_no_skip) .. suffix + ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock())) + local output = read_mediainfo_cached_file(cache_mediainfo_path) + + local lines = {} + + if output then + local i = 0 + for str in output:gmatch("[^\n]*") do + local label, value = str:match("(.*[^ ]) +: (.*)") + local line + + if label then + if not skip_labels[label] then + line = ui.Line({ + ui.Span(label .. ": "):style(ui.Style():bold()), + ui.Span(value):style(ui.Style():fg("blue")), + }) + end + elseif str ~= "General" then + line = ui.Line({ ui.Span(str):style(ui.Style():fg("green")) }) + end + + if line then + if i >= job.skip then + table.insert(lines, line) + end + + local max_width = math.max(1, job.area.w - 3) + i = i + math.max(1, math.ceil(line:width() / max_width)) + end + end + end + + local rendered_img_rect = ya.image_show(cache_img_url, job.area) + local image_height = rendered_img_rect and rendered_img_rect.h or 0 + ya.preview_widgets(job, { + ui.Text(lines) + :area(ui.Rect({ + x = job.area.x, + y = job.area.y + image_height, + w = job.area.w, + h = job.area.h - image_height, + })) + :wrap(ui.Text.WRAP), + }) +end + +function M:seek(job) + local h = cx.active.current.hovered + if h and h.url == job.file.url then + ya.manager_emit("peek", { + math.max(0, cx.active.preview.skip + job.units), + only_if = job.file.url, + }) + end +end + +function M:preload(job) + local video = require("video") + video = ya.dict_merge(video, { skip = job.skip, file = job.file }) + local cache_img_status = video:preload(job) + if cache_img_status ~= 1 then + return cache_img_status + end + + local cache_img_url_no_skip = ya.file_cache({ file = job.file, skip = 0 }) + local cache_mediainfo_url = Url(tostring(cache_img_url_no_skip) .. suffix) + + local cha = fs.cha(cache_mediainfo_url) + if cha and cha.len > 1000 then + return 1 + end + local cmd = "mediainfo" + local output, _ = Command(cmd):args({ tostring(job.file.url) }):stdout(Command.PIPED):output() + + return fs.write( + cache_mediainfo_url, + output and output.stdout or string.format("Failed to start `%s`, Do you have `%s` installed?", cmd, cmd) + ) and 1 or 2 +end + +return M diff --git a/yazi/.config/yazi/yazi.toml b/yazi/.config/yazi/yazi.toml new file mode 100644 index 0000000..8237360 --- /dev/null +++ b/yazi/.config/yazi/yazi.toml @@ -0,0 +1,5 @@ +[plugin] +prepend_previewers = [ + { mime = "{image,audio,video}/*", run = "mediainfo"}, + { mime = "application/subrip", run = "mediainfo"}, +] |
