diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-01-04 01:21:10 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-01-04 01:21:10 +0100 |
| commit | 1c1395154a67ddad9c576d613138897b39851e08 (patch) | |
| tree | 7349957e8787e854ae755fc20ec79dcc2e78a532 | |
| parent | 6b4da63ac591334aa83cd2539ca8a888da212406 (diff) | |
Allow specification of map CPLs by ID (#2702).
| -rw-r--r-- | src/lib/map_cli.cc | 37 | ||||
| -rw-r--r-- | test/map_cli_test.cc | 32 |
2 files changed, 58 insertions, 11 deletions
diff --git a/src/lib/map_cli.cc b/src/lib/map_cli.cc index e38af69cf..b158499a8 100644 --- a/src/lib/map_cli.cc +++ b/src/lib/map_cli.cc @@ -56,7 +56,7 @@ using boost::optional; static void help(std::function<void (string)> out) { - out(String::compose("Syntax: %1 [OPTION} <cpl-file> [<cpl-file> ... ]", program_name)); + out(String::compose("Syntax: %1 [OPTION} <cpl-file|ID> [<cpl-file|ID> ... ]", program_name)); out(" -V, --version show libdcp version"); out(" -h, --help show this help"); out(" -o, --output output directory"); @@ -138,12 +138,12 @@ map_cli(int argc, char* argv[], std::function<void (string)> out) State::override_path = *config_dir; } - vector<boost::filesystem::path> cpl_filenames; + vector<string> cpl_filenames_or_ids; for (int i = optind; i < argc; ++i) { - cpl_filenames.push_back(argv[i]); + cpl_filenames_or_ids.push_back(argv[i]); } - if (cpl_filenames.empty()) { + if (cpl_filenames_or_ids.empty()) { return string{"No CPL specified."}; } @@ -181,13 +181,28 @@ map_cli(int argc, char* argv[], std::function<void (string)> out) /* Find all the CPLs */ vector<shared_ptr<dcp::CPL>> cpls; - for (auto filename: cpl_filenames) { - try { - auto cpl = make_shared<dcp::CPL>(filename); - cpl->resolve_refs(assets); - cpls.push_back(cpl); - } catch (std::exception& e) { - return String::compose("Could not read CPL %1: %2", filename, e.what()); + for (auto filename_or_id: cpl_filenames_or_ids) { + if (boost::filesystem::exists(filename_or_id)) { + try { + auto cpl = make_shared<dcp::CPL>(filename_or_id); + cpl->resolve_refs(assets); + cpls.push_back(cpl); + } catch (std::exception& e) { + return String::compose("Could not read CPL %1: %2", filename_or_id, e.what()); + } + } else { + auto cpl_iter = std::find_if(assets.begin(), assets.end(), [filename_or_id](shared_ptr<dcp::Asset> asset) { + return asset->id() == filename_or_id; + }); + if (cpl_iter == assets.end()) { + return String::compose("Could not find CPL with ID %1", filename_or_id); + } + if (auto cpl = dynamic_pointer_cast<dcp::CPL>(*cpl_iter)) { + cpl->resolve_refs(assets); + cpls.push_back(cpl); + } else { + return String::compose("Could not find CPL with ID %1", filename_or_id); + } } } diff --git a/test/map_cli_test.cc b/test/map_cli_test.cc index 5505a197b..5a774b6a4 100644 --- a/test/map_cli_test.cc +++ b/test/map_cli_test.cc @@ -116,6 +116,38 @@ BOOST_AUTO_TEST_CASE(map_simple_dcp_copy) } +/** Map a single DCP into a new DCP, referring to the CPL by ID */ +BOOST_AUTO_TEST_CASE(map_simple_dcp_copy_by_id) +{ + string const name = "map_simple_dcp_copy_by_id"; + string const out = String::compose("build/test/%1_out", name); + + auto content = content_factory("test/data/flat_red.png"); + auto film = new_test_film2(name + "_in", content); + make_and_verify_dcp(film); + + dcp::CPL cpl(find_cpl(film->dir(film->dcp_name()))); + + vector<string> const args = { + "map_cli", + "-o", out, + "-d", film->dir(film->dcp_name()).string(), + cpl.id() + }; + + boost::filesystem::remove_all(out); + + vector<string> output_messages; + auto error = run(args, output_messages); + BOOST_CHECK(!error); + + verify_dcp(out, {}); + + BOOST_CHECK(boost::filesystem::is_regular_file(find_prefix(out, "j2c_"))); + BOOST_CHECK(boost::filesystem::is_regular_file(find_prefix(out, "pcm_"))); +} + + /** Map a single DCP into a new DCP using the symlink option */ BOOST_AUTO_TEST_CASE(map_simple_dcp_copy_with_symlinks) { |
