From: Carl Hetherington Date: Tue, 2 Apr 2019 23:43:54 +0000 (+0000) Subject: Extract subtitle language from text content rather than ISDCFMetadata (part of #1516). X-Git-Tag: v2.13.142~4 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=698e3ac8863d264237003b49750ae074d612f451 Extract subtitle language from text content rather than ISDCFMetadata (part of #1516). --- diff --git a/src/lib/film.cc b/src/lib/film.cc index 9be048b65..caa95c6be 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -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 i, content()) { - BOOST_FOREACH (shared_ptr j, i->text) { - if (j->type() == TEXT_OPEN_SUBTITLE && j->use() && !j->burn()) { + optional subtitle_language; + bool burnt_in = true; + bool ccap = false; + BOOST_FOREACH (shared_ptr i, content()) { + BOOST_FOREACH (shared_ptr 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"; } diff --git a/src/lib/isdcf_metadata.cc b/src/lib/isdcf_metadata.cc index 1b424c925..5e689ee27 100644 --- a/src/lib/isdcf_metadata.cc +++ b/src/lib/isdcf_metadata.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2019 Carl Hetherington 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 ("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 (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 && diff --git a/src/lib/isdcf_metadata.h b/src/lib/isdcf_metadata.h index 49d204cf4..0c70fb6bc 100644 --- a/src/lib/isdcf_metadata.h +++ b/src/lib/isdcf_metadata.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2019 Carl Hetherington 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; diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 45a74624f..d0f0825f1 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington + Copyright (C) 2012-2019 Carl Hetherington 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 #include #include @@ -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 subtitle_language; + BOOST_FOREACH (shared_ptr i, _film->content()) { + BOOST_FOREACH (shared_ptr 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 ( diff --git a/src/wx/isdcf_metadata_dialog.cc b/src/wx/isdcf_metadata_dialog.cc index 297f54fa1..9226af8b9 100644 --- a/src/wx/isdcf_metadata_dialog.cc +++ b/src/wx/isdcf_metadata_dialog.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington + Copyright (C) 2012-2019 Carl Hetherington 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 ()); diff --git a/src/wx/isdcf_metadata_dialog.h b/src/wx/isdcf_metadata_dialog.h index f8ebdfd42..b1ecb5a36 100644 --- a/src/wx/isdcf_metadata_dialog.h +++ b/src/wx/isdcf_metadata_dialog.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2019 Carl Hetherington 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; diff --git a/test/isdcf_name_test.cc b/test/isdcf_name_test.cc index c65340e1c..8181ffc43 100644 --- a/test/isdcf_name_test.cc +++ b/test/isdcf_name_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2016 Carl Hetherington + Copyright (C) 2014-2019 Carl Hetherington 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 @@ -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 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";