*/
-#include "string_text_file.h"
+
#include "cross.h"
#include "exceptions.h"
+#include "string_text_file.h"
#include "string_text_file_content.h"
-#include <sub/subrip_reader.h>
+#include <dcp/file.h>
+#include <sub/collect.h>
#include <sub/ssa_reader.h>
#include <sub/stl_binary_reader.h>
-#include <sub/collect.h>
+#include <sub/subrip_reader.h>
+#include <sub/web_vtt_reader.h>
#include <unicode/ucsdet.h>
#include <unicode/ucnv.h>
#include <iostream>
#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<const StringTextFileContent> content)
{
string ext = content->path(0).extension().string();
std::unique_ptr<sub::Reader> 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 */
reader.reset(new sub::SubripReader(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()));
}
}
StringTextFile::first () const
{
if (_subtitles.empty()) {
- return optional<ContentTime>();
+ return {};
}
return ContentTime::from_seconds(_subtitles[0].from.all_as_seconds());
StringTextFile::length () const
{
if (_subtitles.empty ()) {
- return ContentTime ();
+ return {};
}
return ContentTime::from_seconds (_subtitles.back().to.all_as_seconds ());