Improve handling of image subtitle IDs in XML (DoM bug #1965)
[libdcp.git] / src / subtitle_asset.cc
index 083a8040d8dce5f8c533dbea43ca5420f2d7866f..aeec99d7926f89b872a0614803a5bbaf0eb0e2be 100644 (file)
@@ -385,13 +385,33 @@ SubtitleAsset::maybe_add_subtitle (string text, list<ParseState> const & parse_s
                                )
                        );
                break;
-       case ParseState::IMAGE:
+       case ParseState::Type::IMAGE:
+       {
+               switch (standard) {
+               case INTEROP:
+                       if (text.size() >= 4) {
+                               /* Remove file extension */
+                               text = text.substr(0, text.size() - 4);
+                       }
+                       break;
+               case SMPTE:
+                       /* It looks like this urn:uuid: is required, but DoM wasn't expecting it (and not writing it)
+                        * until around 2.15.140 so I guess either:
+                        *   a) it is not (always) used in the field, or
+                        *   b) nobody noticed / complained.
+                        */
+                       if (text.substr(0, 9) == "urn:uuid:") {
+                               text = text.substr(9);
+                       }
+                       break;
+               }
+
                /* Add a subtitle with no image data and we'll fill that in later */
                _subtitles.push_back (
                        shared_ptr<Subtitle> (
                                new SubtitleImage (
-                                       Data (),
-                                       standard == INTEROP ? text.substr(0, text.size() - 4) : text,
+                                       Data(),
+                                       text,
                                        ps.in.get(),
                                        ps.out.get(),
                                        ps.h_position.get_value_or(0),
@@ -405,6 +425,7 @@ SubtitleAsset::maybe_add_subtitle (string text, list<ParseState> const & parse_s
                        );
                break;
        }
+       }
 }
 
 list<shared_ptr<Subtitle> >