Fix rebase onto 1.0.
[libdcp.git] / test / rewrite_subs.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
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 int
36 main (int argc, char* argv[])
37 {
38         try {
39                 if (argc < 2) {
40                         cerr << "Syntax: " << argv[0] << " <dcp>\n";
41                         exit (EXIT_FAILURE);
42                 }
43                 
44                 DCP* dcp = new DCP (argv[1]);
45                 dcp->read (true);
46                 
47                 list<shared_ptr<CPL> > cpls = dcp->cpls ();
48                 for (list<boost::shared_ptr<CPL> >::iterator i = cpls.begin(); i != cpls.end(); ++i) {
49                         
50                         list<shared_ptr<Reel> > reels = (*i)->reels ();
51                         for (list<shared_ptr<Reel> >::iterator j = reels.begin(); j != reels.end(); ++j) {
52                                 
53                                 if ((*j)->main_subtitle()) {
54                                         (*j)->main_subtitle()->subtitle_asset()->write_xml ((*j)->main_subtitle()->subtitle_asset()->file ());
55                                 }
56                         }
57                 }
58         }
59
60         catch (FileError& e)
61         {
62                 cerr << e.what() << " (" << e.filename() << ") when reading " << argv[1] << "\n";
63                 exit (EXIT_FAILURE);
64         }
65         catch (DCPReadError& e)
66         {
67                 cerr << e.what() << " when reading " << argv[1] << "\n";
68                 exit (EXIT_FAILURE);
69         }
70         
71         return 0;
72 }