X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fstring_text_file.cc;h=869a2c96a832cf1044caff7e19463b674230aaa6;hb=refs%2Fheads%2F2493-player-export-frame;hp=793619003aab29cfdee6ec0170ef440c4b63ad3d;hpb=6fa9748f382302fa88292b4219598bb81edc7bd0;p=dcpomatic.git diff --git a/src/lib/string_text_file.cc b/src/lib/string_text_file.cc index 793619003..869a2c96a 100644 --- a/src/lib/string_text_file.cc +++ b/src/lib/string_text_file.cc @@ -18,48 +18,51 @@ */ -#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::shared_ptr; using std::string; -using boost::shared_ptr; +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(); transform (ext.begin(), ext.end(), ext.begin(), ::tolower); - sub::Reader* reader = 0; + std::unique_ptr reader; if (ext == ".stl") { - FILE* 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 = 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,17 +103,17 @@ StringTextFile::StringTextFile (shared_ptr content) ucnv_close (to_utf8); if (ext == ".srt") { - reader = new sub::SubripReader (utf8.get()); + reader.reset(new sub::SubripReader(utf8.get())); } else if (ext == ".ssa" || ext == ".ass") { - reader = new sub::SSAReader (utf8.get()); + reader.reset(new sub::SSAReader(utf8.get())); + } else if (ext == ".vtt") { + reader.reset(new sub::WebVTTReader(utf8.get())); } } if (reader) { - _subtitles = sub::collect > (reader->subtitles ()); + _subtitles = sub::collect>(reader->subtitles()); } - - delete reader; } /** @return time of first subtitle, if there is one */ @@ -118,7 +121,7 @@ optional StringTextFile::first () const { if (_subtitles.empty()) { - return optional(); + return {}; } return ContentTime::from_seconds(_subtitles[0].from.all_as_seconds()); @@ -128,7 +131,7 @@ ContentTime StringTextFile::length () const { if (_subtitles.empty ()) { - return ContentTime (); + return {}; } return ContentTime::from_seconds (_subtitles.back().to.all_as_seconds ());