experimental media player support w/ `media` feature

pull/22/head
chris west 4 years ago
parent 88cc95c59f
commit 65c8403e0e

@ -16,6 +16,7 @@ exclude = [
[features]
tls = ["native-tls"]
tor = ["tor-stream"]
media = []
default = ["tls", "tor"]
[profile.release]

@ -21,9 +21,9 @@ pub enum Type {
Image, // I | download
PNG, // p | download
Info, // i | yellow
Sound, // s | download
Sound, // s | green underline
Document, // d | download
Video, // ; | download
Video, // ; | green underline
Xml, // x | cyan
Calendar, // c | download
Mailbox, // M | unsupported
@ -76,6 +76,13 @@ impl Type {
}
}
#[cfg(not(feature = "media"))]
/// Does nothing without the 'media' feature.
pub fn is_media(self) -> bool {
false
}
#[cfg(feature = "media")]
/// Check if media to open in player
pub fn is_media(self) -> bool {
match self {

@ -239,6 +239,7 @@ i# show emoji status indicators
iemoji no
";
#[cfg(not(feature = "media"))]
const TYPES: &str = "
i ** gopher types **
i
@ -270,6 +271,42 @@ TTelnet3270 /help/types phetch
i
";
#[cfg(feature = "media")]
const TYPES: &str = "
i ** gopher types **
i
iphetch supports these links:
i
0text files /Mirrors/RFC/rfc1436.txt fnord.one 65446
1menu items /lawn/ascii bitreich.org
3errors /help/types phetch
7search servers / forthworks.com 7001
8telnet links /help/types phetch
hexternal urls URL:https://en.wikipedia.org/wiki/Phetch phetch
i
ithese download types:
i
4binhex /help/types phetch
5dosfiles /help/types phetch
6uuencoded files /help/types phetch
9binaries /help/types phetch
gGIFs /help/types phetch
Iimages downloads /help/types phetch
ddocuments /help/types phetch
i
iand opening these in a media player:
i
ssound files URL:https://freepd.com/music/Wakka%20Wakka.mp3 phetch
;video files URL:https://www.youtube.com/watch?v=oHg5SJYRHA0 phetch
i
iphetch does not support:
i
2CSO Entries /help/types phetch
+Mirrors /help/types phetch
TTelnet3270 /help/types phetch
i
";
const ABOUT: &str = "
i ~ version: v{version} ~
i

@ -315,7 +315,10 @@ impl Menu {
let text = line.text_truncated(&self.raw);
// color the line
if line.typ.is_download() {
if line.typ.is_media() {
out.push_str(color!(Underline));
out.push_str(color!(Green));
} else if line.typ.is_download() {
out.push_str(color!(Underline));
out.push_str(color!(White));
} else if !line.typ.is_supported() {

@ -187,6 +187,12 @@ impl UI {
// binary downloads
let typ = gopher::type_for_url(url);
#[cfg(feature = "media")]
if typ.is_media() {
return self.open_media(url);
}
if typ.is_download() {
self.dirty = true;
return if self.confirm(&format!("Download {}?", url)) {
@ -488,6 +494,32 @@ impl UI {
}
}
#[cfg(feature = "media")]
/// Opens a media file with `mpv`.
fn open_media(&mut self, url: &str) -> Result<()> {
// mpv only supports /9/
let url = url.replace("/;/", "/9/").replace("/s/", "/9/");
// support URL: selectors
let url = if let Some (idx) = url.find("URL:") {
url.split_at(idx).1.trim_start_matches("URL:")
} else {
&url
};
terminal::disable_raw_mode()?;
let mut cmd = process::Command::new("mpv")
.arg(url)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.spawn()?;
cmd.wait()?;
terminal::enable_raw_mode()?;
self.dirty = true; // redraw when finished with session
Ok(())
}
/// Opens an interactive telnet session.
fn telnet(&mut self, url: &str) -> Result<()> {
let gopher::Url { host, port, .. } = gopher::parse_url(url);

Loading…
Cancel
Save