3b177b2184588d497715f324a8f970aa2a557e06
[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_content.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 boost::shared_ptr;
32 using namespace dcp;
33
34 int
35 main (int argc, char* argv[])
36 {
37         try {
38                 if (argc < 2) {
39                         cerr << "Syntax: " << argv[0] << " <dcp>\n";
40                         exit (EXIT_FAILURE);
41                 }
42                 
43                 DCP* dcp = new DCP (argv[1]);
44                 dcp->read ();
45                 
46                 list<shared_ptr<CPL> > cpls = dcp->cpls ();
47                 for (list<boost::shared_ptr<CPL> >::iterator i = cpls.begin(); i != cpls.end(); ++i) {
48                         
49                         list<shared_ptr<Reel> > reels = (*i)->reels ();
50                         for (list<shared_ptr<Reel> >::iterator j = reels.begin(); j != reels.end(); ++j) {
51                                 
52                                 if ((*j)->main_subtitle()) {
53                                         (*j)->main_subtitle()->subtitle_content()->write_xml ();
54                                 }
55                         }
56                 }
57         }
58
59         catch (FileError& e)
60         {
61                 cerr << e.what() << " (" << e.filename() << ") when reading " << argv[1] << "\n";
62                 exit (EXIT_FAILURE);
63         }
64         catch (DCPReadError& e)
65         {
66                 cerr << e.what() << " when reading " << argv[1] << "\n";
67                 exit (EXIT_FAILURE);
68         }
69         
70         return 0;
71 }