aboutsummaryrefslogtreecommitdiff
path: root/transcoder
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-01-28 17:55:11 +0100
committermetamuffin <metamuffin@disroot.org>2024-01-28 17:55:11 +0100
commit727be96686a2c6c5747b26be15933e11c9cab9c6 (patch)
tree817accf6c4965e814cc8736fdbd17b423fae0669 /transcoder
parent5b587f2914908daa804bb643ac216001290077ab (diff)
downloadjellything-727be96686a2c6c5747b26be15933e11c9cab9c6.tar
jellything-727be96686a2c6c5747b26be15933e11c9cab9c6.tar.bz2
jellything-727be96686a2c6c5747b26be15933e11c9cab9c6.tar.zst
clean up some code + subrip support?
Diffstat (limited to 'transcoder')
-rw-r--r--transcoder/src/subtitles.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/transcoder/src/subtitles.rs b/transcoder/src/subtitles.rs
index 84db5a9..9118ebc 100644
--- a/transcoder/src/subtitles.rs
+++ b/transcoder/src/subtitles.rs
@@ -3,11 +3,30 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2024 metamuffin <metamuffin.org>
*/
-use anyhow::anyhow;
+use anyhow::{anyhow, bail, Context};
use jellycommon::jhls::SubtitleCue;
use std::fmt::Write;
-// TODO discontinued for now. since this should be snippetized aswell.
+pub fn parse_subtitles(
+ codec: &str,
+ codec_private: Option<Vec<u8>>,
+ blocks: Vec<(u64, u64, Vec<u8>)>,
+) -> anyhow::Result<Vec<SubtitleCue>> {
+ match codec {
+ "D_WEBVTT/SUBTITLES" => parse_webvtt_blocks(blocks),
+ "S_HDMV/PGS" => bail!("no HDMV/PGS yet"),
+ "S_HDMV/TEXTST" => bail!("no HDMV/PGS yet"),
+ "S_ARISUB" => bail!("no arisub yet"),
+ "S_TEXT/UTF8" => parse_subrip_blocks(blocks),
+ "S_VOBSUB" => bail!("no vobsub yet"),
+ "S_TEXT/ASS" => parse_ass_blocks(
+ codec_private.ok_or(anyhow!("ass without CodecPrivate"))?,
+ blocks,
+ ),
+ x => bail!("unknown sub codec {x:?}"),
+ }
+ .context(anyhow!("parsing {codec} subtitles"))
+}
pub fn write_webvtt(title: String, subtitles: Vec<SubtitleCue>) -> anyhow::Result<String> {
let mut out = String::new();
@@ -39,12 +58,12 @@ pub fn parse_webvtt_blocks(blocks: Vec<(u64, u64, Vec<u8>)>) -> anyhow::Result<V
}
Ok(out)
}
-pub fn parse_pgs_blocks(blocks: Vec<(u64, u64, Vec<u8>)>) -> anyhow::Result<Vec<SubtitleCue>> {
+pub fn parse_subrip_blocks(blocks: Vec<(u64, u64, Vec<u8>)>) -> anyhow::Result<Vec<SubtitleCue>> {
let mut out = Vec::new();
for (pts, dur, block) in blocks {
- let _content = String::from_utf8_lossy(&block).trim().to_string();
+ let content = String::from_utf8_lossy(&block).trim().to_string();
out.push(SubtitleCue {
- content: "PGS stub".to_string(),
+ content,
start: pts as f64 / 1000.,
end: (pts + dur) as f64 / 1000.,
});