summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2024-03-02 20:53:29 +0100
committerqkzk <qu3nt1n@gmail.com>2024-03-02 20:53:29 +0100
commitda996764d9b4cb220c5564f403359cfaed93e1ac (patch)
tree240da4d2236f31b40ef8b520801ba9f1fa7067ba
parentb496e4b4763b75a9c15cf7707ab634b4cacbcbeb (diff)
preview torrent files with transmission-show
-rw-r--r--development.md3
-rw-r--r--src/common/constant_strings_paths.rs2
-rw-r--r--src/io/display.rs3
-rw-r--r--src/modes/display/preview.rs38
4 files changed, 44 insertions, 2 deletions
diff --git a/development.md b/development.md
index d3da7e9..9e0707c 100644
--- a/development.md
+++ b/development.md
@@ -874,6 +874,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- Dynamic filtering while typing a filter
- Search as you type: do / then type a pattern and you will jump to the match.
- replace `tar tvf` by `bsdtar -v --list --file`. Which can preview .deb and .rpm files
+- preview torrent files with `transmission-show`
#### Changelog
@@ -944,7 +945,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- [x] setting a filter reset the "found" searched path & index
- [x] search as you type
- [x] replace `tar tvf` by `bsdtar -v --list --file`. Which can preview .deb and .rpm files
-- [ ] torrent with [transmission show](https://github.com/ranger/ranger/blob/38bb8901004b75a407ffee4b9e176bc0a436cb15/ranger/data/scope.sh#L82C13-L82C48)
+- [x] torrent with `transmission-show`
## TODO
diff --git a/src/common/constant_strings_paths.rs b/src/common/constant_strings_paths.rs
index c8477d6..5089884 100644
--- a/src/common/constant_strings_paths.rs
+++ b/src/common/constant_strings_paths.rs
@@ -210,3 +210,5 @@ pub const LIBREOFFICE: &str = "libreoffice";
pub const LAZYGIT: &str = "lazygit";
/// duf
pub const NCDU: &str = "ncdu";
+/// transmission-show
+pub const TRANSMISSION_SHOW: &str = "transmission-show";
diff --git a/src/io/display.rs b/src/io/display.rs
index 7b102ac..27f4469 100644
--- a/src/io/display.rs
+++ b/src/io/display.rs
@@ -396,6 +396,9 @@ impl<'a> WinMain<'a> {
Preview::FifoCharDevice(text) => {
impl_preview!(text, tab, length, canvas, line_number_width, window, height)
}
+ Preview::Torrent(text) => {
+ impl_preview!(text, tab, length, canvas, line_number_width, window, height)
+ }
Preview::Empty => (),
}
diff --git a/src/modes/display/preview.rs b/src/modes/display/preview.rs
index a04e2a9..05dfcfd 100644
--- a/src/modes/display/preview.rs
+++ b/src/modes/display/preview.rs
@@ -16,7 +16,7 @@ use tuikit::attr::{Attr, Color};
use crate::common::{
CALC_PDF_PATH, FFMPEG, FONTIMAGE, ISOINFO, JUPYTER, LIBREOFFICE, LSBLK, LSOF, MEDIAINFO,
- PANDOC, RSVG_CONVERT, SS, THUMBNAIL_PATH, UEBERZUG,
+ PANDOC, RSVG_CONVERT, SS, THUMBNAIL_PATH, TRANSMISSION_SHOW, UEBERZUG,
};
use crate::log_info;
use crate::modes::ContentWindow;
@@ -47,6 +47,7 @@ pub enum ExtensionKind {
Notebook,
Office,
Epub,
+ Torrent,
#[default]
Unknown,
}
@@ -72,6 +73,7 @@ impl ExtensionKind {
"ipynb" => Self::Notebook,
"doc" | "docx" | "odt" | "sxw" | "xlsx" | "xls" => Self::Office,
"epub" => Self::Epub,
+ "torrent" => Self::Torrent,
_ => Self::Unknown,
}
}
@@ -107,6 +109,7 @@ pub enum Preview {
Socket(Socket),
BlockDevice(BlockDevice),
FifoCharDevice(FifoCharDevice),
+ Torrent(Torrent),
#[default]
Empty,
}
@@ -201,6 +204,10 @@ impl Preview {
ExtensionKind::Epub if is_program_in_path(PANDOC) => {
Ok(Self::epub(&file_info.path).context("Preview: Couldn't parse epub")?)
}
+ ExtensionKind::Torrent if is_program_in_path(TRANSMISSION_SHOW) => {
+ Ok(Self::torrent(&file_info.path)
+ .context("Preview couldn't explore the torrent file")?)
+ }
_ => match Self::preview_syntaxed(extension, &file_info.path) {
Some(syntaxed_preview) => Ok(syntaxed_preview),
None => Self::preview_text_or_binary(file_info),
@@ -300,6 +307,10 @@ impl Preview {
))
}
+ pub fn torrent(path: &Path) -> Result<Self> {
+ Ok(Self::Torrent(Torrent::new(path).context("")?))
+ }
+
/// The size (most of the time the number of lines) of the preview.
/// Some preview (thumbnail, empty) can't be scrolled and their size is always 0.
pub fn len(&self) -> usize {
@@ -317,6 +328,7 @@ impl Preview {
Self::Socket(socket) => socket.len(),
Self::BlockDevice(blockdevice) => blockdevice.len(),
Self::FifoCharDevice(fifo) => fifo.len(),
+ Self::Torrent(torrent) => torrent.len(),
}
}
@@ -1106,6 +1118,29 @@ impl Iso {
}
}
+pub struct Torrent {
+ pub content: Vec<String>,
+ length: usize,
+}
+
+impl Torrent {
+ fn new(path: &Path) -> Result<Self> {
+ let path = path.to_str().context("couldn't parse the path")?;
+ let content: Vec<String> =
+ execute_and_capture_output_without_check(TRANSMISSION_SHOW, &[path])?
+ .lines()
+ .map(|s| s.to_owned())
+ .collect();
+ Ok(Self {
+ length: content.len(),
+ content,
+ })
+ }
+ fn len(&self) -> usize {
+ self.length
+ }
+}
+
/// Common trait for many preview methods which are just a bunch of lines with
/// no specific formatting.
/// Some previewing (thumbnail and syntaxed text) needs more details.
@@ -1151,3 +1186,4 @@ impl_window!(Socket, String);
impl_window!(BlockDevice, String);
impl_window!(FifoCharDevice, String);
impl_window!(TreeLines, TreeLineBuilder);
+impl_window!(Torrent, String);