diff options
author | metamuffin <metamuffin@disroot.org> | 2023-09-29 21:15:07 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-09-29 21:15:07 +0200 |
commit | 795438f691657c2fdcfe113f933950b63df84271 (patch) | |
tree | fba3d1e6d34bb92709282a4826bbbbbd9215ef1e /common/src/stream.rs | |
parent | c62eb3a2fdaa80f472be6ecbfc2cbf2479d8d914 (diff) | |
download | jellything-795438f691657c2fdcfe113f933950b63df84271.tar jellything-795438f691657c2fdcfe113f933950b63df84271.tar.bz2 jellything-795438f691657c2fdcfe113f933950b63df84271.tar.zst |
stream wrapper for remux mkv/webm
Diffstat (limited to 'common/src/stream.rs')
-rw-r--r-- | common/src/stream.rs | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/common/src/stream.rs b/common/src/stream.rs index 59166b8..3fb1008 100644 --- a/common/src/stream.rs +++ b/common/src/stream.rs @@ -13,7 +13,7 @@ pub struct StreamSpec { } #[rustfmt::skip] -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] #[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))] pub enum StreamFormat { @@ -36,3 +36,47 @@ impl Default for StreamSpec { } } } + +impl StreamSpec { + pub fn to_query(&self) -> String { + use std::fmt::Write; + let mut u = String::new(); + writeln!(u, "format={}", self.format.ident()).unwrap(); + + if !self.tracks.is_empty() { + writeln!( + u, + "&tracks={}", + self.tracks + .iter() + .map(|s| s.to_string()) + .collect::<Vec<_>>() + .join(",") + ) + .unwrap(); + } + if let Some(abr) = self.abr { + writeln!(u, "&abr={abr}").unwrap(); + } + if let Some(vbr) = self.vbr { + writeln!(u, "&vbr={vbr}").unwrap(); + } + if let Some(index) = self.index { + writeln!(u, "&index={index}").unwrap(); + } + u + } +} + +impl StreamFormat { + pub fn ident(&self) -> &'static str { + match self { + StreamFormat::Original => "original", + StreamFormat::Matroska => "matroska", + StreamFormat::Webm => "webm", + StreamFormat::Hls => "hls", + StreamFormat::Jhls => "jhls", + StreamFormat::Segment => "hlsseg", + } + } +} |