Extract subtitle language from text content rather than ISDCFMetadata (part of #1516).
authorCarl Hetherington <cth@carlh.net>
Tue, 2 Apr 2019 23:43:54 +0000 (23:43 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 2 Apr 2019 23:43:54 +0000 (23:43 +0000)
src/lib/film.cc
src/lib/isdcf_metadata.cc
src/lib/isdcf_metadata.h
src/lib/writer.cc
src/wx/isdcf_metadata_dialog.cc
src/wx/isdcf_metadata_dialog.h
test/isdcf_name_test.cc

index 9be048b65d8caa23c6434d1fe4ff8cfebcc66efc..caa95c6be0e0d76d0bef0a5defc163d15929ed5b 100644 (file)
@@ -722,32 +722,35 @@ Film::isdcf_name (bool if_created_now) const
 
        if (!dm.audio_language.empty ()) {
                d += "_" + dm.audio_language;
-               if (!dm.subtitle_language.empty()) {
 
-                       /* I'm not clear on the precise details of the convention for CCAP labelling;
-                          for now I'm just appending -CCAP if we have any closed captions.
-                       */
+               /* I'm not clear on the precise details of the convention for CCAP labelling;
+                  for now I'm just appending -CCAP if we have any closed captions.
+               */
 
-                       bool burnt_in = true;
-                       bool ccap = false;
-                       BOOST_FOREACH (shared_ptr<Content> i, content()) {
-                               BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
-                                       if (j->type() == TEXT_OPEN_SUBTITLE && j->use() && !j->burn()) {
+               optional<string> subtitle_language;
+               bool burnt_in = true;
+               bool ccap = false;
+               BOOST_FOREACH (shared_ptr<Content> i, content()) {
+                       BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
+                               if (j->type() == TEXT_OPEN_SUBTITLE && j->use()) {
+                                       subtitle_language = j->language ();
+                                       if (!j->burn()) {
                                                burnt_in = false;
-                                       } else if (j->type() == TEXT_CLOSED_CAPTION) {
-                                               ccap = true;
                                        }
+                               } else if (j->type() == TEXT_CLOSED_CAPTION && j->use()) {
+                                       ccap = true;
                                }
                        }
+               }
 
-                       string language = dm.subtitle_language;
-                       if (burnt_in && language != "XX") {
-                               transform (language.begin(), language.end(), language.begin(), ::tolower);
+               if (subtitle_language) {
+                       if (burnt_in && *subtitle_language != "XX") {
+                               transform (subtitle_language->begin(), subtitle_language->end(), subtitle_language->begin(), ::tolower);
                        } else {
-                               transform (language.begin(), language.end(), language.begin(), ::toupper);
+                               transform (subtitle_language->begin(), subtitle_language->end(), subtitle_language->begin(), ::toupper);
                        }
 
-                       d += "-" + language;
+                       d += "-" + *subtitle_language;
                        if (ccap) {
                                d += "-CCAP";
                        }
index 1b424c925d90028c11693ccf428265b028cf762f..5e689ee273080e89a4d26b0743c5c304b02bc384 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -33,7 +33,6 @@ using dcp::raw_convert;
 ISDCFMetadata::ISDCFMetadata (cxml::ConstNodePtr node)
        : content_version (node->number_child<int> ("ContentVersion"))
        , audio_language (node->string_child ("AudioLanguage"))
-       , subtitle_language (node->string_child ("SubtitleLanguage"))
        , territory (node->string_child ("Territory"))
        , rating (node->string_child ("Rating"))
        , studio (node->string_child ("Studio"))
@@ -54,7 +53,6 @@ ISDCFMetadata::as_xml (xmlpp::Node* root) const
 {
        root->add_child("ContentVersion")->add_child_text (raw_convert<string> (content_version));
        root->add_child("AudioLanguage")->add_child_text (audio_language);
-       root->add_child("SubtitleLanguage")->add_child_text (subtitle_language);
        root->add_child("Territory")->add_child_text (territory);
        root->add_child("Rating")->add_child_text (rating);
        root->add_child("Studio")->add_child_text (studio);
@@ -72,7 +70,6 @@ operator== (ISDCFMetadata const & a, ISDCFMetadata const & b)
 {
        return a.content_version == b.content_version &&
                a.audio_language == b.audio_language &&
-               a.subtitle_language == b.subtitle_language &&
                a.territory == b.territory &&
                a.rating == b.rating &&
                a.studio == b.studio &&
index 49d204cf42b4fa552d40082c8c10517101f70145..0c70fb6bc49666a3ba63626de4a939ff9514e41d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -46,7 +46,6 @@ public:
 
        int content_version;
        std::string audio_language;
-       std::string subtitle_language;
        std::string territory;
        std::string rating;
        std::string studio;
index 45a74624f7da19564766b26ef2eba18da8f59b84..d0f0825f13a3a5390fbe166fe37e461885114d2b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -35,6 +35,7 @@
 #include "font.h"
 #include "util.h"
 #include "reel_writer.h"
+#include "text_content.h"
 #include <dcp/cpl.h>
 #include <dcp/locale_convert.h>
 #include <boost/foreach.hpp>
@@ -591,7 +592,16 @@ Writer::write_cover_sheet ()
        boost::algorithm::replace_all (text, "$TYPE", _film->dcp_content_type()->pretty_name());
        boost::algorithm::replace_all (text, "$CONTAINER", _film->container()->container_nickname());
        boost::algorithm::replace_all (text, "$AUDIO_LANGUAGE", _film->isdcf_metadata().audio_language);
-       boost::algorithm::replace_all (text, "$SUBTITLE_LANGUAGE", _film->isdcf_metadata().subtitle_language);
+
+       optional<string> subtitle_language;
+       BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
+               BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
+                       if (j->type() == TEXT_OPEN_SUBTITLE && j->use()) {
+                               subtitle_language = j->language ();
+                       }
+               }
+       }
+       boost::algorithm::replace_all (text, "$SUBTITLE_LANGUAGE", subtitle_language.get_value_or("None"));
 
        boost::uintmax_t size = 0;
        for (
index 297f54fa1316aad8560e9027b3b938daae2e4310..9226af8b9108f265d32d2815cfe4fd77130878a7 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -41,9 +41,6 @@ ISDCFMetadataDialog::ISDCFMetadataDialog (wxWindow* parent, ISDCFMetadata dm, bo
        add (_("Audio Language (e.g. EN)"), true);
        _audio_language = add (new wxTextCtrl (this, wxID_ANY));
 
-       add (_("Subtitle Language (e.g. FR)"), true);
-       _subtitle_language = add (new wxTextCtrl (this, wxID_ANY));
-
        add (_("Territory (e.g. UK)"), true);
        _territory = add (new wxTextCtrl (this, wxID_ANY));
 
@@ -82,7 +79,6 @@ ISDCFMetadataDialog::ISDCFMetadataDialog (wxWindow* parent, ISDCFMetadata dm, bo
 
        _content_version->SetValue (dm.content_version);
        _audio_language->SetValue (std_to_wx (dm.audio_language));
-       _subtitle_language->SetValue (std_to_wx (dm.subtitle_language));
        _territory->SetValue (std_to_wx (dm.territory));
        _rating->SetValue (std_to_wx (dm.rating));
        _studio->SetValue (std_to_wx (dm.studio));
@@ -104,7 +100,6 @@ ISDCFMetadataDialog::isdcf_metadata () const
 
        dm.content_version = _content_version->GetValue ();
        dm.audio_language = wx_to_std (_audio_language->GetValue ());
-       dm.subtitle_language = wx_to_std (_subtitle_language->GetValue ());
        dm.territory = wx_to_std (_territory->GetValue ());
        dm.rating = wx_to_std (_rating->GetValue ());
        dm.studio = wx_to_std (_studio->GetValue ());
index f8ebdfd42b7caad48ec159caa8bb422758463b05..b1ecb5a36981d0906ee23d2d916fe33607ddbb65 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -36,7 +36,6 @@ public:
 private:
        wxSpinCtrl* _content_version;
        wxTextCtrl* _audio_language;
-       wxTextCtrl* _subtitle_language;
        wxTextCtrl* _territory;
        wxTextCtrl* _rating;
        wxTextCtrl* _studio;
index c65340e1c3e8c7339dc369f694318621983f13d5..8181ffc4307d3b3de439d5181d6f99b2df25bfe8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -32,6 +32,8 @@
 #include "lib/audio_mapping.h"
 #include "lib/ffmpeg_content.h"
 #include "lib/audio_content.h"
+#include "lib/content_factory.h"
+#include "lib/text_content.h"
 #include "test.h"
 #include <iostream>
 
@@ -51,7 +53,6 @@ BOOST_AUTO_TEST_CASE (isdcf_name_test)
        ISDCFMetadata m;
        m.content_version = 1;
        m.audio_language = "EN";
-       m.subtitle_language = "XX";
        m.territory = "UK";
        m.rating = "PG";
        m.studio = "ST";
@@ -68,9 +69,14 @@ BOOST_AUTO_TEST_CASE (isdcf_name_test)
        film->_isdcf_date = boost::gregorian::date (2014, boost::gregorian::Jul, 4);
        film->set_audio_channels (1);
        film->set_resolution (RESOLUTION_4K);
+       shared_ptr<Content> text = content_factory("test/data/subrip.srt").front();
+       BOOST_REQUIRE_EQUAL (text->text.size(), 1);
+       text->text.front()->set_language ("fr");
+       text->text.front()->set_burn (true);
+       film->examine_and_add_content (text);
+       BOOST_REQUIRE (!wait_for_jobs());
        m.content_version = 2;
        m.audio_language = "DE";
-       m.subtitle_language = "FR";
        m.territory = "US";
        m.rating = "R";
        m.studio = "DI";