Use signals2 rather than sigc++
[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 #include "sound_asset.h"
9 #include "picture_asset.h"
10 #include "subtitle_asset.h"
11
12 using std::string;
13 using std::cerr;
14 using std::cout;
15 using std::list;
16 using boost::shared_ptr;
17 using namespace libdcp;
18
19 static void
20 help (string n)
21 {
22         cerr << "Syntax: " << n << " [options] <DCP>\n"
23              << "  -s, --subtitles  list all subtitles\n";
24 }
25
26 int
27 main (int argc, char* argv[])
28 {
29         bool subtitles = false;
30         
31         int option_index = 0;
32         while (1) {
33                 static struct option long_options[] = {
34                         { "version", no_argument, 0, 'v'},
35                         { "help", no_argument, 0, 'h'},
36                         { "subtitles", no_argument, 0, 's'},
37                         { 0, 0, 0, 0 }
38                 };
39
40                 int c = getopt_long (argc, argv, "vhs", long_options, &option_index);
41
42                 if (c == -1) {
43                         break;
44                 }
45
46                 switch (c) {
47                 case 'v':
48                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
49                         exit (EXIT_SUCCESS);
50                 case 'h':
51                         help (argv[0]);
52                         exit (EXIT_SUCCESS);
53                 case 's':
54                         subtitles = true;
55                         break;
56                 }
57         }
58
59         if (argc <= optind || argc > (optind + 1)) {
60                 help (argv[0]);
61                 exit (EXIT_FAILURE);
62         }
63
64         if (!boost::filesystem::exists (argv[optind])) {
65                 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
66                 exit (EXIT_FAILURE);
67         }
68
69         DCP* dcp = 0;
70         try {
71                 dcp = new DCP (argv[optind]);
72                 dcp->read (false);
73         } catch (FileError& e) {
74                 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
75                 exit (EXIT_FAILURE);
76         }
77
78         cout << "DCP: " << argv[optind] << "\n";
79
80         list<shared_ptr<const CPL> > cpls = dcp->cpls ();
81
82         for (list<shared_ptr<const CPL> >::iterator i = cpls.begin(); i != cpls.end(); ++i) {
83                 cout << "  CPL: " << (*i)->name() << "\n"
84                      << "    Length: " << (*i)->length() << "\n"
85                      << "    Frames per second: " << (*i)->frames_per_second() << "\n";
86                 
87                 list<shared_ptr<const Reel> > reels = (*i)->reels ();
88
89                 int R = 1;
90                 for (list<shared_ptr<const Reel> >::const_iterator j = reels.begin(); j != reels.end(); ++j) {
91                         cout << "    Reel " << R << "\n";
92                         
93                         if ((*j)->main_picture()) {
94                                 cout << "      Picture:  " << (*j)->main_picture()->width() << "x" << (*j)->main_picture()->height() << "\n";
95                         }
96                         if ((*j)->main_sound()) {
97                                 cout << "      Sound:    " << (*j)->main_sound()->channels() << " channels at " << (*j)->main_sound()->sampling_rate() << "Hz\n";
98                         }
99                         if ((*j)->main_subtitle()) {
100                                 list<shared_ptr<Subtitle> > subs = (*j)->main_subtitle()->subtitles ();
101                                 cout << "      Subtitle: " << subs.size() << " subtitles in " << (*j)->main_subtitle()->language() << "\n";
102                                 if (subtitles) {
103                                         for (list<shared_ptr<Subtitle> >::const_iterator k = subs.begin(); k != subs.end(); ++k) {
104                                                 cout << "        " << (*k)->text() << "\n";
105                                                 cout << "          "
106                                                      << "font:" << (*k)->font() << "; "
107                                                      << "italic:" << (*k)->italic() << "; "
108                                                      << "color:" << (*k)->color() << "; "
109                                                      << "in:" << (*k)->in() << "; "
110                                                      << "out:" << (*k)->out() << "; "
111                                                      << "v_position:" << (*k)->v_position() << "; "
112                                                      << "v_align:" << (*k)->v_align() << "; "
113                                                      << "effect:" << (*k)->effect() << "; "
114                                                      << "effect_color:" << (*k)->effect_color() << "; "
115                                                      << "fade_up_time:" << (*k)->fade_up_time() << "; "
116                                                      << "fade_down_time:" << (*k)->fade_down_time() << "; "
117                                                      << "size: " << (*k)->size() << "\n";
118                                         }
119                                 }
120                         }
121                         ++R;
122                 }
123         }
124
125         return 0;
126 }