mirror of
https://github.com/thegeneralist01/archivr
synced 2026-12-04 18:56:44 +01:00
fix: preserve SRT subtitles in entry export bundles
This commit is contained in:
parent
bf8ef34a7a
commit
b4bce15f66
3 changed files with 69 additions and 3 deletions
|
|
@ -335,6 +335,8 @@ fn render_video(
|
|||
.unwrap_or_default();
|
||||
let tracks: String = subtitles
|
||||
.iter()
|
||||
// SRT files stay in the ZIP, but HTML video tracks require WebVTT.
|
||||
.filter(|sub| ext_of_s(&sub.name) == "vtt")
|
||||
.enumerate()
|
||||
.map(|(i, sub)| {
|
||||
let sub_src = asset_src(mode, sub);
|
||||
|
|
@ -560,3 +562,28 @@ fn render_container(
|
|||
s.push_str("</ol>");
|
||||
s
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn video_tracks_use_vtt_only_even_when_srt_precedes_it() {
|
||||
let asset = |name: &str| Asset {
|
||||
source: PathBuf::new(),
|
||||
name: name.to_string(),
|
||||
byte_size: 0,
|
||||
};
|
||||
let html = render_video(
|
||||
&asset("video.mp4"),
|
||||
AssetMode::Bundle,
|
||||
&std::collections::HashMap::new(),
|
||||
&[asset("captions.srt"), asset("captions.vtt")],
|
||||
);
|
||||
|
||||
assert_eq!(html.matches("<track ").count(), 1);
|
||||
assert!(html.contains("src=\"assets/captions.vtt\""));
|
||||
assert!(html.contains(" default>"));
|
||||
assert!(!html.contains("captions.srt"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -922,6 +922,45 @@ mod tests {
|
|||
assert!(count <= 1, "child title at most once; found {count}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn srt_subtitle_of_child_is_preserved_in_html_and_markdown_bundles() {
|
||||
let ctx = TestCtx::new();
|
||||
let (parent_uid, child_uid) = ctx.add_container_entry("Playlist", "Video");
|
||||
let conn = ctx.conn();
|
||||
let entry_id = database::entry_id_for_uid(&conn, &child_uid)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let relpath = "raw/captions.srt";
|
||||
let srt = "1\n00:00:00,000 --> 00:00:02,000\nCaption text.\n";
|
||||
std::fs::write(ctx.paths.store_path.join(relpath), srt).unwrap();
|
||||
database::add_entry_artifact(
|
||||
&conn,
|
||||
&database::NewArtifact {
|
||||
entry_id,
|
||||
artifact_role: "subtitle".to_string(),
|
||||
storage_area: "raw".to_string(),
|
||||
relpath: relpath.to_string(),
|
||||
blob_id: None,
|
||||
logical_path: None,
|
||||
metadata_json: None,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for format in [ExportFormat::Html, ExportFormat::Markdown] {
|
||||
let opts = ExportOptions {
|
||||
format,
|
||||
layout: ExportLayout::Together,
|
||||
include_credit: false,
|
||||
caller_bits: u32::MAX,
|
||||
};
|
||||
let export =
|
||||
export_entries(&ctx.paths, std::slice::from_ref(&parent_uid), &opts).unwrap();
|
||||
let (file, _, _, _) = export.open().unwrap();
|
||||
assert_eq!(read_zip_entry(file, "assets/captions.srt"), srt);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validation_empty() {
|
||||
let ctx = TestCtx::new();
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ pub(crate) enum ExportBody {
|
|||
#[derive(Debug)]
|
||||
pub(crate) struct ExportEntry {
|
||||
pub summary: EntrySummary,
|
||||
/// Subtitle `.vtt` assets in track order.
|
||||
/// Subtitle `.vtt` and `.srt` assets in track order.
|
||||
pub subtitles: Vec<Asset>,
|
||||
pub body: ExportBody,
|
||||
}
|
||||
|
|
@ -192,10 +192,10 @@ pub(crate) fn load_entry(
|
|||
}
|
||||
}
|
||||
|
||||
// ----- subtitles (VTT only) -----
|
||||
// ----- subtitles -----
|
||||
let subtitles: Vec<Asset> = subtitle_artifacts
|
||||
.iter()
|
||||
.filter(|a| a.relpath.to_lowercase().ends_with(".vtt"))
|
||||
.filter(|a| matches!(ext_of_s(&a.relpath).as_str(), "vtt" | "srt"))
|
||||
.filter_map(|a| {
|
||||
archive::resolve_artifact_path(store_path, a)
|
||||
.map(|p| Asset {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue