X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fstring_text_file.cc;h=348ccd1d5e7fe95c90b0687963acb576ce6d29bc;hb=213afdc4e9399e3f2aaea3df54ab79535d43045e;hp=8c2c5651854e08a625f2d9602bfc9aaede91cf43;hpb=76e543bd7c85054ff857781707fa570f2b159360;p=dcpomatic.git diff --git a/src/lib/string_text_file.cc b/src/lib/string_text_file.cc index 8c2c56518..348ccd1d5 100644 --- a/src/lib/string_text_file.cc +++ b/src/lib/string_text_file.cc @@ -18,29 +18,34 @@ */ -#include "string_text_file.h" + #include "cross.h" #include "exceptions.h" +#include "string_text_file.h" #include "string_text_file_content.h" -#include +#include +#include #include #include -#include +#include +#include #include #include #include #include "i18n.h" -using std::vector; + using std::cout; -using std::string; using std::shared_ptr; +using std::string; +using std::vector; using boost::scoped_array; using boost::optional; using dcp::ArrayData; using namespace dcpomatic; + StringTextFile::StringTextFile (shared_ptr content) { string ext = content->path(0).extension().string(); @@ -49,17 +54,15 @@ StringTextFile::StringTextFile (shared_ptr content) std::unique_ptr reader; if (ext == ".stl") { - auto f = fopen_boost (content->path(0), "rb"); + dcp::File f(content->path(0), "rb"); if (!f) { - throw OpenFileError (content->path(0), errno, OpenFileError::READ); + throw OpenFileError (f.path(), errno, OpenFileError::READ); } try { - reader.reset(new sub::STLBinaryReader(f)); + reader.reset(new sub::STLBinaryReader(f.get())); } catch (...) { - fclose (f); throw; } - fclose (f); } else { /* Text-based file; sort out its character encoding before we try to parse it */ @@ -100,9 +103,16 @@ StringTextFile::StringTextFile (shared_ptr content) ucnv_close (to_utf8); if (ext == ".srt") { - reader.reset(new sub::SubripReader(utf8.get())); + try { + reader.reset(new sub::SubripReader(utf8.get())); + } catch (...) { + /* Sometimes files are have the .srt extension but are really WEBVTT */ + reader.reset(new sub::WebVTTReader(utf8.get())); + } } else if (ext == ".ssa" || ext == ".ass") { reader.reset(new sub::SSAReader(utf8.get())); + } else if (ext == ".vtt") { + reader.reset(new sub::WebVTTReader(utf8.get())); } } @@ -116,7 +126,7 @@ optional StringTextFile::first () const { if (_subtitles.empty()) { - return optional(); + return {}; } return ContentTime::from_seconds(_subtitles[0].from.all_as_seconds()); @@ -126,7 +136,7 @@ ContentTime StringTextFile::length () const { if (_subtitles.empty ()) { - return ContentTime (); + return {}; } return ContentTime::from_seconds (_subtitles.back().to.all_as_seconds ());