Add an option to dump the decryption certificate from the KDM CLI.
[dcpomatic.git] / src / lib / string_text_file.cc
index b8ca27e160ca989ad283768f963a1bdf974546db..9b43b35a6fe8fda9ba38e290c068944b5ec6649d 100644 (file)
 #include "string_text_file_content.h"
 #include <dcp/file.h>
 #include <sub/collect.h>
+#include <sub/exceptions.h>
 #include <sub/ssa_reader.h>
 #include <sub/stl_binary_reader.h>
 #include <sub/subrip_reader.h>
+#include <sub/web_vtt_reader.h>
 #include <unicode/ucsdet.h>
 #include <unicode/ucnv.h>
 #include <iostream>
@@ -102,9 +104,21 @@ StringTextFile::StringTextFile (shared_ptr<const StringTextFileContent> content)
                ucnv_close (to_utf8);
 
                if (ext == ".srt") {
-                       reader.reset(new sub::SubripReader(utf8.get()));
+                       try {
+                               reader.reset(new sub::SubripReader(utf8.get()));
+                       } catch (sub::SubripError& subrip_error) {
+                               /* Sometimes files are have the .srt extension but are really WEBVTT... */
+                               try {
+                                       reader.reset(new sub::WebVTTReader(utf8.get()));
+                               } catch (sub::WebVTTHeaderError&) {
+                                       /* ...but in this case there isn't even a WebVTT error */
+                                       throw subrip_error;
+                               }
+                       }
                } else if (ext == ".ssa" || ext == ".ass") {
                        reader.reset(new sub::SSAReader(utf8.get()));
+               } else if (ext == ".vtt") {
+                       reader.reset(new sub::WebVTTReader(utf8.get()));
                }
        }
 
@@ -118,7 +132,7 @@ optional<ContentTime>
 StringTextFile::first () const
 {
        if (_subtitles.empty()) {
-               return optional<ContentTime>();
+               return {};
        }
 
        return ContentTime::from_seconds(_subtitles[0].from.all_as_seconds());
@@ -128,7 +142,7 @@ ContentTime
 StringTextFile::length () const
 {
        if (_subtitles.empty ()) {
-               return ContentTime ();
+               return {};
        }
 
        return ContentTime::from_seconds (_subtitles.back().to.all_as_seconds ());