diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-11-20 22:52:27 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-11-20 22:52:27 +0100 |
commit | 4cb02f98ebcdfa992253adab467a64143908ab3d (patch) | |
tree | 72751ce26b93d762f1d63345eef6e0d67dcceed7 | |
parent | 42f9267e6d0fe0c97e5ea3a7a36e2533c8e8a80a (diff) |
mediainfo using the original programmedia_info
-rw-r--r-- | readme.md | 2 | ||||
-rw-r--r-- | src/preview.rs | 32 | ||||
-rw-r--r-- | src/term_manager.rs | 12 |
3 files changed, 45 insertions, 1 deletions
@@ -106,6 +106,7 @@ - [x] Resize immediatly - [x] display should be "terminal manager" and it shouldn't handle anything else (git, available space etc.) - [x] preview EXIF for image files +- [x] media info for video file / audio file ## TODO @@ -128,7 +129,6 @@ - [x] preview - [ ] auto mount usb keys ??? - [ ] mtp... but fast [libmtp.rs](https://docs.rs/libmtp-rs/0.7.7/libmtp_rs/) -- [ ] media info for video file / audio file ## BUGS diff --git a/src/preview.rs b/src/preview.rs index 64af553..8725ac2 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -25,6 +25,7 @@ pub enum Preview { Pdf(PdfContent), Compressed(CompressedContent), Image(ExifContent), + Media(MediainfoContent), Empty, } @@ -46,6 +47,10 @@ impl Preview { "png" | "jpg" | "jpeg" | "tiff" | "heif" => { Ok(Self::Image(ExifContent::new(file_info.path.clone())?)) } + "mkv" | "ogg" | "ogm" | "riff" | "mpeg" | "mp2" | "mp3" | "mp4" | "wm" | "qt" + | "ac3" | "dts" | "aac" | "mac" | "flac" | "avi" => { + Ok(Self::Media(MediainfoContent::new(file_info.path.clone())?)) + } _ => { let mut file = std::fs::File::open(file_info.path.clone())?; let mut buffer = vec![0; Self::CONTENT_INSPECTOR_MIN_SIZE]; @@ -82,6 +87,7 @@ impl Preview { Self::Pdf(pdf) => pdf.len(), Self::Compressed(zip) => zip.len(), Self::Image(img) => img.len(), + Self::Media(media) => media.len(), } } @@ -399,6 +405,32 @@ impl ExifContent { } } +#[derive(Clone)] +pub struct MediainfoContent { + length: usize, + pub content: Vec<String>, +} + +impl MediainfoContent { + fn new(path: PathBuf) -> FmResult<Self> { + let content: Vec<String>; + if let Ok(output) = std::process::Command::new("mediainfo").arg(path).output() { + let s = String::from_utf8(output.stdout).unwrap_or_default(); + content = s.lines().map(|s| s.to_owned()).collect(); + } else { + content = vec![]; + } + Ok(Self { + length: content.len(), + content, + }) + } + + fn len(&self) -> usize { + self.length + } +} + fn catch_unwind_silent<F: FnOnce() -> R + panic::UnwindSafe, R>(f: F) -> std::thread::Result<R> { let prev_hook = panic::take_hook(); panic::set_hook(Box::new(|_| {})); diff --git a/src/term_manager.rs b/src/term_manager.rs index 5abdfb8..833ef4a 100644 --- a/src/term_manager.rs +++ b/src/term_manager.rs @@ -436,6 +436,18 @@ impl Display { self.term.print(row, line_number_width + 3, line)?; } } + Preview::Media(media) => { + for (i, line) in media + .content + .iter() + .enumerate() + .skip(tab.window.top) + .take(min(length, tab.window.bottom + 1)) + { + let row = Self::calc_line_row(i, tab); + self.term.print(row, line_number_width + 3, line)?; + } + } Preview::Empty => (), } Ok(()) |