2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
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.
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.
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.
23 #include <dcp/version.h>
25 #include "lib/filter.h"
26 #include "lib/transcode_job.h"
27 #include "lib/job_manager.h"
29 #include "lib/version.h"
30 #include "lib/cross.h"
31 #include "lib/config.h"
33 #include "lib/signal_manager.h"
34 #include "lib/server_finder.h"
35 #include "lib/json_server.h"
43 using boost::shared_ptr;
44 using boost::optional;
49 cerr << "Syntax: " << n << " [OPTION] <FILM>\n"
50 << " -v, --version show DCP-o-matic version\n"
51 << " -h, --help show this help\n"
52 << " -f, --flags show flags passed to C++ compiler on build\n"
53 << " -n, --no-progress do not print progress to stdout\n"
54 << " -r, --no-remote do not use any remote servers\n"
55 << " -j, --json <port> run a JSON server on the specified port\n"
56 << " -k, --keep-going keep running even when the job is complete\n"
58 << "<FILM> is the film directory.\n";
62 main (int argc, char* argv[])
66 bool no_remote = false;
67 optional<int> json_port;
68 bool keep_going = false;
72 static struct option long_options[] = {
73 { "version", no_argument, 0, 'v'},
74 { "help", no_argument, 0, 'h'},
75 { "flags", no_argument, 0, 'f'},
76 { "no-progress", no_argument, 0, 'n'},
77 { "no-remote", no_argument, 0, 'r'},
78 { "json", required_argument, 0, 'j'},
79 { "keep-going", no_argument, 0, 'k' },
83 int c = getopt_long (argc, argv, "vhfnrj:k", long_options, &option_index);
91 cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
97 cout << dcpomatic_cxx_flags << "\n";
106 json_port = atoi (optarg);
114 if (optind >= argc) {
119 film_dir = argv[optind];
122 signal_manager = new SignalManager ();
125 ServerFinder::instance()->disable ();
129 new JSONServer (json_port.get ());
132 shared_ptr<Film> film;
134 film.reset (new Film (film_dir));
135 film->read_metadata ();
136 } catch (std::exception& e) {
137 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
141 ContentList content = film->content ();
142 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
143 vector<boost::filesystem::path> paths = (*i)->paths ();
144 for (vector<boost::filesystem::path>::const_iterator j = paths.begin(); j != paths.end(); ++j) {
145 if (!boost::filesystem::exists (*j)) {
146 cerr << argv[0] << ": content file " << *j << " not found.\n";
153 cout << "\nMaking DCP for " << film->name() << "\n";
158 bool should_stop = false;
161 while (!should_stop) {
165 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
167 if (!first && progress) {
168 cout << "\033[" << jobs.size() << "A";
175 int finished_in_error = 0;
177 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
179 cout << (*i)->name() << ": ";
181 if ((*i)->progress ()) {
182 cout << (*i)->status() << " \n";
184 cout << ": Running \n";
188 if (!(*i)->finished ()) {
192 if ((*i)->finished_in_error ()) {
197 if (!progress && (*i)->finished_in_error ()) {
198 /* We won't see this error if we haven't been showing progress,
201 cout << (*i)->status() << "\n";
205 if (unfinished == 0 || finished_in_error != 0) {
212 dcpomatic_sleep (3600);
216 /* This is just to stop valgrind reporting leaks due to JobManager
217 indirectly holding onto codecs.
221 ServerFinder::drop ();
223 return error ? EXIT_FAILURE : EXIT_SUCCESS;