2 Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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 libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
36 #include "exceptions.h"
37 #include "asset_factory.h"
38 #include "reel_asset.h"
40 #include <libxml++/libxml++.h>
41 #include <boost/filesystem.hpp>
42 #include <boost/foreach.hpp>
49 using boost::shared_ptr;
50 using boost::optional;
55 cerr << "Syntax: " << n << " [OPTION] <DCP>]\n"
56 << " -h, --help show this help\n"
57 << " -o, --output output DCP directory\n";
60 void progress (float f)
62 cout << (f * 100) << "% \r";
66 main (int argc, char* argv[])
71 optional<boost::filesystem::path> output;
73 struct option long_options[] = {
74 { "help", no_argument, 0, 'h' },
75 { "output", required_argument, 0, 'o' },
79 int c = getopt_long (argc, argv, "ho:", long_options, &option_index);
100 boost::filesystem::path dcp_dir = argv[optind];
102 /* Try to read it and report errors */
104 dcp::DCP dcp (dcp_dir);
105 list<dcp::VerificationNote> notes;
107 dcp.read (¬es, true);
108 } catch (dcp::ReadError& e) {
109 cout << "Error:" << e.what() << "\n";
112 BOOST_FOREACH (dcp::VerificationNote i, notes) {
113 cout << "Error: " << dcp::note_to_string(i) << "\n";
118 shared_ptr<dcp::CPL> cpl;
119 for (boost::filesystem::directory_iterator i(dcp_dir); i != boost::filesystem::directory_iterator(); ++i) {
120 if (i->path().extension() == ".xml") {
122 cpl.reset(new dcp::CPL(i->path()));
123 } catch (dcp::ReadError& e) {
124 cout << "Error: " << e.what() << "\n";
125 } catch (xmlpp::parse_error& e) {
126 cout << "Error: " << e.what() << "\n";
132 cout << "Got a CPL!\n";
135 cerr << "No output directory specified.\n";
139 /* Read all MXF assets */
140 list<shared_ptr<dcp::Asset> > assets;
141 for (boost::filesystem::directory_iterator i(dcp_dir); i != boost::filesystem::directory_iterator(); ++i) {
142 if (i->path().extension() == ".mxf") {
144 shared_ptr<dcp::Asset> asset = dcp::asset_factory(i->path(), true);
145 asset->set_file (*output / i->path().filename());
146 cout << "Hashing " << i->path().filename() << "\n";
147 asset->hash (&progress);
149 assets.push_back (asset);
150 } catch (dcp::ReadError& e) {
151 cout << "Error: " << e.what() << "\n";
156 dcp::DCP fixed (*output);
158 fixed.resolve_refs (assets);
159 fixed.write_xml (dcp::INTEROP);
160 cout << "Fixed XML files written to " << output->string() << "\n";