X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsubrip.cc;h=11ad3302d3659abf107eed8b8fa69d33d8109c69;hb=3b48d5494c3cae7743d283203f5c8021860ab81f;hp=380a2ce2cb7e7757c2e1fc7472f571d72aa0a693;hpb=b299c1873bf23414061d551843275c77a9256a05;p=dcpomatic.git diff --git a/src/lib/subrip.cc b/src/lib/subrip.cc index 380a2ce2c..11ad3302d 100644 --- a/src/lib/subrip.cc +++ b/src/lib/subrip.cc @@ -18,6 +18,7 @@ */ #include +#include #include "subrip.h" #include "subrip_content.h" #include "subrip_subtitle.h" @@ -65,13 +66,18 @@ SubRip::SubRip (shared_ptr content) switch (state) { case COUNTER: { + if (line.empty ()) { + /* a blank line at the start is ok */ + break; + } + int x = 0; try { x = lexical_cast (line); } catch (...) { } - + if (x == next_count) { state = METADATA; ++next_count; @@ -89,8 +95,7 @@ SubRip::SubRip (shared_ptr content) throw SubRipError (line, _("a time/position line"), content->path (0)); } - current->from = convert_time (p[0]); - current->to = convert_time (p[2]); + current->period = ContentTimePeriod (convert_time (p[0]), convert_time (p[2])); if (p.size() > 3) { current->x1 = convert_coordinate (p[3]); @@ -126,18 +131,18 @@ SubRip::SubRip (shared_ptr content) ContentTime SubRip::convert_time (string t) { - ContentTime r = 0; + ContentTime r; vector a; boost::algorithm::split (a, t, boost::is_any_of (":")); assert (a.size() == 3); - r += lexical_cast (a[0]) * 60 * 60 * TIME_HZ; - r += lexical_cast (a[1]) * 60 * TIME_HZ; + r += ContentTime::from_seconds (lexical_cast (a[0]) * 60 * 60); + r += ContentTime::from_seconds (lexical_cast (a[1]) * 60); vector b; boost::algorithm::split (b, a[2], boost::is_any_of (",")); - r += lexical_cast (b[0]) * TIME_HZ; - r += lexical_cast (b[1]) * TIME_HZ / 1000; + r += ContentTime::from_seconds (lexical_cast (b[0])); + r += ContentTime::from_seconds (lexical_cast (b[1]) / 1000); return r; } @@ -229,8 +234,8 @@ ContentTime SubRip::length () const { if (_subtitles.empty ()) { - return 0; + return ContentTime (); } - return _subtitles.back().to; + return _subtitles.back().period.to; }