summaryrefslogtreecommitdiff
path: root/src/lib/film.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-03-23 00:50:11 +0100
committerCarl Hetherington <cth@carlh.net>2021-03-31 22:48:53 +0200
commite0a70cd5cfb11fc2de167f3146acdd437a6faa82 (patch)
tree022ceef78d7daa12bccf519ebab0db5e23a3feb6 /src/lib/film.cc
parent8640da877450479a85c73b2a921897d83b478c84 (diff)
Put subtitle language back into content from the film (#1930).
This also adds the main/additional language flag. Of all the considerations about how to specify subtitle language, the most important seems to be that the language specification happens for the content where the language is; i.e. in the content text tab.
Diffstat (limited to 'src/lib/film.cc')
-rw-r--r--src/lib/film.cc94
1 files changed, 27 insertions, 67 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 46074e2ad..763af8f8a 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -496,9 +496,6 @@ Film::metadata (bool with_content_paths) const
}
root->add_child("UserExplicitContainer")->add_child_text(_user_explicit_container ? "1" : "0");
root->add_child("UserExplicitResolution")->add_child_text(_user_explicit_resolution ? "1" : "0");
- for (auto i: _subtitle_languages) {
- root->add_child("SubtitleLanguage")->add_child_text(i.to_string());
- }
_playlist->as_xml (root->add_child ("Playlist"), with_content_paths);
return doc;
@@ -680,10 +677,6 @@ Film::read_metadata (optional<boost::filesystem::path> path)
_user_explicit_container = f.optional_bool_child("UserExplicitContainer").get_value_or(true);
_user_explicit_resolution = f.optional_bool_child("UserExplicitResolution").get_value_or(true);
- for (auto i: f.node_children("SubtitleLanguage")) {
- _subtitle_languages.push_back (dcp::LanguageTag(i->content()));
- }
-
list<string> notes;
_playlist->set_from_xml (shared_from_this(), f.node_child ("Playlist"), _state_version, notes);
@@ -692,41 +685,6 @@ Film::read_metadata (optional<boost::filesystem::path> path)
set_backtrace_file (file ("backtrace.txt"));
}
- /* Around 2.15.108 we removed subtitle language state from the text content and the ISDCF
- * metadata and put it into the Film instead. If we've loaded an old Film let's try and fish
- * out the settings from where they were so that they don't get lost.
- */
-
- optional<dcp::LanguageTag> found_language;
-
- for (auto i: f.node_child("Playlist")->node_children("Content")) {
- auto text = i->optional_node_child("Text");
- if (text && text->optional_string_child("Language") && !found_language) {
- try {
- found_language = dcp::LanguageTag(text->string_child("Language"));
- } catch (...) {}
- }
- }
-
- if (_state_version >= 9) {
- auto isdcf_language = f.node_child("ISDCFMetadata")->optional_string_child("SubtitleLanguage");
- if (isdcf_language && !found_language) {
- try {
- found_language = dcp::LanguageTag(*isdcf_language);
- } catch (...) {
- try {
- found_language = dcp::LanguageTag(boost::algorithm::to_lower_copy(*isdcf_language));
- } catch (...) {
-
- }
- }
- }
- }
-
- if (found_language) {
- _subtitle_languages.push_back (*found_language);
- }
-
_dirty = false;
return notes;
}
@@ -793,6 +751,30 @@ Film::mapped_audio_channels () const
return mapped;
}
+
+pair<optional<dcp::LanguageTag>, vector<dcp::LanguageTag>>
+Film::subtitle_languages () const
+{
+ pair<optional<dcp::LanguageTag>, vector<dcp::LanguageTag>> result;
+ for (auto i: content()) {
+ for (auto j: i->text) {
+ if (j->use() && j->type() == TextType::OPEN_SUBTITLE && j->language()) {
+ if (j->language_is_additional()) {
+ result.second.push_back (j->language().get());
+ } else {
+ result.first = j->language().get();
+ }
+ }
+ }
+ }
+
+ std::sort (result.second.begin(), result.second.end());
+ auto last = std::unique (result.second.begin(), result.second.end());
+ result.second.erase (last, result.second.end());
+ return result;
+}
+
+
/** @return a ISDCF-compliant name for a DCP of this film */
string
Film::isdcf_name (bool if_created_now) const
@@ -924,8 +906,9 @@ Film::isdcf_name (bool if_created_now) const
}
}
- if (!_subtitle_languages.empty()) {
- auto lang = _subtitle_languages.front().language().get_value_or("en").subtag();
+ auto sublangs = subtitle_languages();
+ if (sublangs.first && sublangs.first->language()) {
+ auto lang = sublangs.first->language()->subtag();
if (burnt_in) {
transform (lang.begin(), lang.end(), lang.begin(), ::tolower);
} else {
@@ -2038,29 +2021,6 @@ Film::set_luminance (optional<dcp::Luminance> l)
void
-Film::set_subtitle_language (dcp::LanguageTag language)
-{
- set_subtitle_languages ({language});
-}
-
-
-void
-Film::unset_subtitle_language ()
-{
- FilmChangeSignaller ch (this, Property::SUBTITLE_LANGUAGES);
- _subtitle_languages.clear();
-}
-
-
-void
-Film::set_subtitle_languages (vector<dcp::LanguageTag> languages)
-{
- FilmChangeSignaller ch (this, Property::SUBTITLE_LANGUAGES);
- _subtitle_languages = languages;
-}
-
-
-void
Film::set_facility (optional<string> f)
{
FilmChangeSignaller ch (this, Property::FACILITY);