Add a test corpus for XML.
[libdcp.git] / tools / dcpinfo.cc
1 #include <iostream>
2 #include <cstdlib>
3 #include <boost/filesystem.hpp>
4 #include <getopt.h>
5 #include "dcp.h"
6 #include "exceptions.h"
7 #include "reel.h"
8
9 using namespace std;
10 using namespace boost;
11 using namespace libdcp;
12
13 static void
14 help (string n)
15 {
16         cerr << "Syntax: " << n << " <DCP>\n";
17 }
18
19 int
20 main (int argc, char* argv[])
21 {
22         int option_index = 0;
23         while (1) {
24                 static struct option long_options[] = {
25                         { "version", no_argument, 0, 'v'},
26                         { "help", no_argument, 0, 'h'},
27                         { 0, 0, 0, 0 }
28                 };
29
30                 int c = getopt_long (argc, argv, "vh", long_options, &option_index);
31
32                 if (c == -1) {
33                         break;
34                 }
35
36                 switch (c) {
37                 case 'v':
38                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
39                         exit (EXIT_SUCCESS);
40                 case 'h':
41                         help (argv[0]);
42                         exit (EXIT_SUCCESS);
43                 }
44         }
45
46         if (argc <= optind || argc > (optind + 1)) {
47                 help (argv[0]);
48                 exit (EXIT_FAILURE);
49         }
50
51         if (!filesystem::exists (argv[optind])) {
52                 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
53                 exit (EXIT_FAILURE);
54         }
55
56         list<string> missing_mxfs;
57
58         DCP* dcp = 0;
59         try {
60                 dcp = new DCP (argv[optind], false);
61         } catch (FileError& e) {
62                 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
63                 exit (EXIT_FAILURE);
64         }
65
66         cout << "DCP: " << argv[optind] << "\n"
67              << "\tLength: " << dcp->length() << "\n"
68              << "\tFrames per second: " << dcp->frames_per_second() << "\n";
69
70         if (!missing_mxfs.empty ()) {
71                 cout << "\tmissing MXFs: ";
72                 for (list<string>::const_iterator i = missing_mxfs.begin(); i != missing_mxfs.end(); ++i) {
73                         cout << *i << " " ;
74                 }
75                 cout << "\n";
76         }
77
78         list<shared_ptr<const Reel> > reels = dcp->reels ();
79
80         int R = 1;
81         for (list<shared_ptr<const Reel> >::const_iterator i = reels.begin(); i != reels.end(); ++i) {
82                 cout << "Reel " << R << "\n";
83                 cout << "\tContains: ";
84                 if ((*i)->main_picture()) {
85                         cout << "picture ";
86                 }
87                 if ((*i)->main_sound()) {
88                         cout << "sound ";
89                 }
90                 if ((*i)->main_subtitle()) {
91                         cout << "subtitle ";
92                 }
93                 cout << "\n";
94                 ++R;
95         }
96
97         return 0;
98 }