Still more licence fixups.
[libdcp.git] / test / rewrite_subs.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
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.
10
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.
15
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/>.
18 */
19
20 #include <iostream>
21 #include "dcp.h"
22 #include "cpl.h"
23 #include "reel.h"
24 #include "subtitle_asset.h"
25 #include "reel_subtitle_asset.h"
26 #include "exceptions.h"
27
28 using std::cout;
29 using std::cerr;
30 using std::list;
31 using std::string;
32 using boost::shared_ptr;
33 using namespace dcp;
34
35 /** Load a DCP then re-write its subtitle XML or MXF in-place */
36 int
37 main (int argc, char* argv[])
38 {
39         try {
40                 if (argc < 2) {
41                         cerr << "Syntax: " << argv[0] << " <dcp>\n";
42                         exit (EXIT_FAILURE);
43                 }
44
45                 DCP* dcp = new DCP (argv[1]);
46                 dcp->read (true);
47
48                 list<shared_ptr<CPL> > cpls = dcp->cpls ();
49                 for (list<boost::shared_ptr<CPL> >::iterator i = cpls.begin(); i != cpls.end(); ++i) {
50
51                         list<shared_ptr<Reel> > reels = (*i)->reels ();
52                         for (list<shared_ptr<Reel> >::iterator j = reels.begin(); j != reels.end(); ++j) {
53
54                                 if ((*j)->main_subtitle()) {
55                                         (*j)->main_subtitle()->asset()->write ((*j)->main_subtitle()->asset()->file ());
56                                 }
57                         }
58                 }
59         }
60
61         catch (FileError& e)
62         {
63                 cerr << e.what() << " (" << e.filename() << ") when reading " << argv[1] << "\n";
64                 exit (EXIT_FAILURE);
65         }
66         catch (DCPReadError& e)
67         {
68                 cerr << e.what() << " when reading " << argv[1] << "\n";
69                 exit (EXIT_FAILURE);
70         }
71
72         return 0;
73 }