2 Copyright (C) 2013 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.
21 #include <libdcp/certificates.h>
23 #include "lib/cinema.h"
25 #include "lib/config.h"
26 #include "lib/exceptions.h"
32 using boost::shared_ptr;
37 cerr << "Syntax: " << n << " [OPTION] [<FILM>]\n"
38 << " -h, --help show this help\n"
39 << " -o, --output output file or directory\n"
40 << " -f, --valid-from valid from time (e.g. \"2013-09-28 01:41:51\")\n"
41 << " -t, --valid-to valid to time (e.g. \"2014-09-28 01:41:51\")\n"
42 << " -c, --certificate file containing projector certificate\n"
43 << " -z, --zip ZIP each cinema's KDMs into its own file\n"
44 << " --cinema specify a cinema, either by name or email address\n"
45 << " --cinemas list known cinemas from the DCP-o-matic settings\n";
48 int main (int argc, char* argv[])
50 boost::filesystem::path output;
51 boost::posix_time::ptime valid_from;
52 boost::posix_time::ptime valid_to;
53 string certificate_file;
60 static struct option long_options[] = {
61 { "help", no_argument, 0, 'h'},
62 { "output", required_argument, 0, 'o'},
63 { "valid-from", required_argument, 0, 'f'},
64 { "valid-to", required_argument, 0, 't'},
65 { "certificate", required_argument, 0, 'c' },
66 { "cinema", required_argument, 0, 'A' },
67 { "cinemas", no_argument, 0, 'B' },
68 { "zip", no_argument, 0, 'z' },
72 int c = getopt_long (argc, argv, "ho:f:t:c:A:Bz", long_options, &option_index);
86 valid_from = boost::posix_time::time_from_string (optarg);
89 valid_to = boost::posix_time::time_from_string (optarg);
92 certificate_file = optarg;
107 list<boost::shared_ptr<Cinema> > cinemas = Config::instance()->cinemas ();
108 for (list<boost::shared_ptr<Cinema> >::const_iterator i = cinemas.begin(); i != cinemas.end(); ++i) {
109 cout << (*i)->name << " (" << (*i)->email << ")\n";
114 if (optind >= argc) {
119 if (cinema_name.empty() && certificate_file.empty()) {
120 cerr << argv[0] << ": you must specify either a cinema, a screen or a certificate file\n";
124 string const film_dir = argv[optind];
128 shared_ptr<Film> film;
130 film.reset (new Film (film_dir));
131 film->read_metadata ();
132 } catch (std::exception& e) {
133 cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n";
137 if (cinema_name.empty ()) {
138 shared_ptr<libdcp::Certificate> certificate (new libdcp::Certificate (boost::filesystem::path (certificate_file)));
139 libdcp::KDM kdm = film->make_kdm (certificate, valid_from, valid_to);
143 list<shared_ptr<Cinema> > cinemas = Config::instance()->cinemas ();
144 list<shared_ptr<Cinema> >::const_iterator i = cinemas.begin();
145 while (i != cinemas.end() && (*i)->name != cinema_name && (*i)->email != cinema_name) {
149 if (i == cinemas.end ()) {
150 cerr << argv[0] << ": could not find cinema \"" << cinema_name << "\"\n";
156 write_kdm_zip_files (film, (*i)->screens(), valid_from, valid_to, output);
158 write_kdm_files (film, (*i)->screens(), valid_from, valid_to, output);
160 } catch (FileError& e) {
161 cerr << argv[0] << ": " << e.what() << " (" << e.file().string() << ")\n";