From: Carl Hetherington Date: Tue, 21 Apr 2020 21:32:42 +0000 (+0200) Subject: Allow DCP content to store and serialise metadata. X-Git-Tag: v2.15.53~1^2~1 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=5f3a88d3ab1e9c1a13d7e61fc37a0c4cef8df9a5 Allow DCP content to store and serialise metadata. --- diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 6c2db91d3..4280ad13a 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -151,6 +151,12 @@ DCPContent::DCPContent (cxml::ConstNodePtr node, int version) BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children("Marker")) { _markers[dcp::marker_from_string(i->string_attribute("type"))] = ContentTime(raw_convert(i->content())); } + + BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children("Rating")) { + _ratings.push_back (dcp::Rating(i)); + } + + _content_version = node->optional_string_child("ContentVersion").get_value_or(""); } void @@ -249,6 +255,8 @@ DCPContent::examine (shared_ptr film, shared_ptr job) for (map::const_iterator i = markers.begin(); i != markers.end(); ++i) { _markers[i->first] = ContentTime(i->second.as_editable_units(DCPTime::HZ)); } + _ratings = examiner->ratings (); + _content_version = examiner->content_version (); } if (old_texts == texts) { @@ -354,6 +362,13 @@ DCPContent::as_xml (xmlpp::Node* node, bool with_paths) const marker->set_attribute("type", dcp::marker_to_string(i->first)); marker->add_child_text(raw_convert(i->second.get())); } + + BOOST_FOREACH (dcp::Rating i, _ratings) { + xmlpp::Element* rating = node->add_child("Rating"); + i.as_xml (rating); + } + + node->add_child("ContentVersion")->add_child_text (_content_version); } DCPTime diff --git a/src/lib/dcp_content.h b/src/lib/dcp_content.h index 8658ac5ed..6d707670f 100644 --- a/src/lib/dcp_content.h +++ b/src/lib/dcp_content.h @@ -158,6 +158,14 @@ public: Resolution resolution () const; + std::vector ratings () const { + return _ratings; + } + + std::string content_version () const { + return _content_version; + } + private: friend class reels_test5; @@ -205,6 +213,8 @@ private: /** List of the lengths of the reels in this DCP */ std::list _reel_lengths; std::map _markers; + std::vector _ratings; + std::string _content_version; }; #endif diff --git a/src/lib/dcp_examiner.cc b/src/lib/dcp_examiner.cc index a7d451eca..d04dacdd6 100644 --- a/src/lib/dcp_examiner.cc +++ b/src/lib/dcp_examiner.cc @@ -23,6 +23,7 @@ #include "exceptions.h" #include "image.h" #include "config.h" +#include "util.h" #include #include #include @@ -236,6 +237,8 @@ DCPExaminer::DCPExaminer (shared_ptr content, bool tolerant) _standard = cpl->standard().get(); _three_d = !cpl->reels().empty() && cpl->reels().front()->main_picture() && dynamic_pointer_cast (cpl->reels().front()->main_picture()->asset()); + _ratings = list_to_vector (cpl->ratings()); + _content_version = cpl->content_version_label_text (); _cpl = cpl->id (); } diff --git a/src/lib/dcp_examiner.h b/src/lib/dcp_examiner.h index c1ba54dee..21aa8d3ab 100644 --- a/src/lib/dcp_examiner.h +++ b/src/lib/dcp_examiner.h @@ -123,6 +123,14 @@ public: return _markers; } + std::vector ratings () const { + return _ratings; + } + + std::string content_version () const { + return _content_version; + } + private: boost::optional _video_frame_rate; boost::optional _video_size; @@ -146,4 +154,6 @@ private: std::string _cpl; std::list _reel_lengths; std::map _markers; + std::vector _ratings; + std::string _content_version; }; diff --git a/test/import_dcp_test.cc b/test/import_dcp_test.cc index 4c227ac34..83dd0c6de 100644 --- a/test/import_dcp_test.cc +++ b/test/import_dcp_test.cc @@ -152,3 +152,47 @@ BOOST_AUTO_TEST_CASE (import_dcp_markers_test) BOOST_REQUIRE(markers.find(dcp::LFMC) != markers.end()); BOOST_CHECK(markers[dcp::LFMC] == dcpomatic::ContentTime(960000)); } + + +/** Check that DCP metadata (ratings and content version) are imported correctly */ +BOOST_AUTO_TEST_CASE (import_dcp_metadata_test) +{ + /* Make a DCP with some ratings and a content version */ + shared_ptr film = new_test_film2 ("import_dcp_metadata_test"); + shared_ptr content = content_factory("test/data/flat_red.png").front(); + film->examine_and_add_content (content); + BOOST_REQUIRE (!wait_for_jobs()); + + content->video->set_length (10); + + std::vector ratings; + ratings.push_back (dcp::Rating("BBFC", "15")); + ratings.push_back (dcp::Rating("MPAA", "NC-17")); + film->set_ratings (ratings); + + film->set_content_version ("Fred"); + + film->make_dcp (); + BOOST_REQUIRE (!wait_for_jobs()); + + /* Import the DCP to a new film and check the metadata */ + shared_ptr film2 = new_test_film2 ("import_dcp_metadata_test2"); + shared_ptr imported (new DCPContent(film->dir(film->dcp_name()))); + film2->examine_and_add_content (imported); + BOOST_REQUIRE (!wait_for_jobs()); + film2->write_metadata (); + + BOOST_CHECK (imported->ratings() == ratings); + BOOST_CHECK_EQUAL (imported->content_version(), "Fred"); + + /* Load that film and check that the metadata has been loaded */ + shared_ptr film3(new Film(boost::filesystem::path("build/test/import_dcp_metadata_test2"))); + film3->read_metadata (); + BOOST_REQUIRE (film3->content().size() == 1); + shared_ptr reloaded = dynamic_pointer_cast(film3->content().front()); + BOOST_REQUIRE (reloaded); + + BOOST_CHECK (reloaded->ratings() == ratings); + BOOST_CHECK_EQUAL (reloaded->content_version(), "Fred"); +} +