2 Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "kdm_with_metadata.h"
25 #include <boost/foreach.hpp>
30 using boost::shared_ptr;
31 using boost::optional;
35 list<KDMWithMetadataPtr> screen_kdms,
36 boost::filesystem::path directory,
37 dcp::NameFormat name_format,
38 dcp::NameFormat::Map name_values,
39 boost::function<bool (boost::filesystem::path)> confirm_overwrite
44 if (directory == "-") {
45 /* Write KDMs to the stdout */
46 BOOST_FOREACH (KDMWithMetadataPtr i, screen_kdms) {
47 cout << i->kdm_as_xml ();
54 if (!boost::filesystem::exists (directory)) {
55 boost::filesystem::create_directories (directory);
58 /* Write KDMs to the specified directory */
59 BOOST_FOREACH (KDMWithMetadataPtr i, screen_kdms) {
60 name_values['i'] = i->kdm_id ();
61 boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml"));
62 if (!boost::filesystem::exists (out) || confirm_overwrite (out)) {
73 KDMWithMetadata::get (char k) const
75 dcp::NameFormat::Map::const_iterator i = _name_values.find (k);
76 if (i == _name_values.end()) {
77 return optional<string>();