emk / subtitles-rs

Use SRT subtitle files to study foreign languages (in progress)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bilingual srt timings failure.

rdearman opened this issue · comments

substudy combine  Love_Letter_with_you_.srt Love_Letter_with_you_en.srt > Love_Letter_with_you.bilingual.srt
Error: Cannot truncate time period Period { begin: 154.0, end: 164.0 } at 154

Stack backtrace:
   0: anyhow::error::<impl anyhow::Error>::msg
   1: substudy::clean::clean_subtitle_file
   2: substudy::srt::SubtitleFile::cleaned_from_path
   3: substudy::cmd_combine
   4: substudy::main::{{closure}}
   5: tokio::runtime::park::CachedParkThread::block_on
   6: tokio::runtime::context::runtime::enter_runtime
   7: substudy::main
   8: std::sys_common::backtrace::__rust_begin_short_backtrace
   9: std::rt::lang_start::{{closure}}
  10: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/ops/function.rs:284:13
  11: std::panicking::try::do_call
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:554:40
  12: std::panicking::try
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:518:19
  13: std::panic::catch_unwind
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panic.rs:142:14
  14: std::rt::lang_start_internal::{{closure}}
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/rt.rs:148:48
  15: std::panicking::try::do_call
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:554:40
  16: std::panicking::try
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:518:19
  17: std::panic::catch_unwind
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panic.rs:142:14
  18: std::rt::lang_start_internal
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/rt.rs:148:20
  19: main

I solved this problem by synchronising the timestamps between the two files. But I would have been fine if the program just took the timestamps from file #1 and used those timestamps for the contents in the other file. But if you are going to need both files to have the same timestamps, a better error message would be good.

Thank you for the bug report!

(some notes, mostly for myself)

This error probably occurred because we had mutliple, overlapping subtitles starting at 154 seconds. Substudy requires subtitles in a file to be non-overlapping—one subtitle must end before the other begins. And all subtitles must be longer than 0 seconds. Substudy will try to fix broken subtitle files, but if the files can't be easily modified to fit these rules, it will give up.

The error here is Cannot truncate time period Period { begin: 154.0, end: 164.0 } at 154 which usually means that substudy found two different subtitles starting around 154 seconds, and tried to "truncate" the time period of the first subtitle so that it finished before the second. But since the two subtitles started at the same time, that meant that the first subtitle wound up being 0 seconds long. This is not terribly user friendly.

I'm not entirely sure what to do here. Substudy does require at least semi-plausible SRT files as inputs, but lots of real-world subtitle data is horribly broken. Should we just refuse to run? Should we throw out subtitle data until out input looks semi-reasonable? Or should we do something else?

This turns out to be a duplicate of #37. I'll do any further work there. Thank you again for the report!