diff options
Diffstat (limited to 'src/tools/dcpomatic_kdm.cc')
| -rw-r--r-- | src/tools/dcpomatic_kdm.cc | 89 |
1 files changed, 74 insertions, 15 deletions
diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc index 294248697..fb2243464 100644 --- a/src/tools/dcpomatic_kdm.cc +++ b/src/tools/dcpomatic_kdm.cc @@ -20,28 +20,40 @@ #include <getopt.h> #include <libdcp/certificates.h> #include "lib/film.h" +#include "lib/cinema.h" +#include "lib/kdm.h" +#include "lib/config.h" +#include "lib/exceptions.h" using std::string; +using std::cout; using std::cerr; +using std::list; using boost::shared_ptr; static void help (string n) { - cerr << "Syntax: " << n << " [OPTION] <FILM>\n" + cerr << "Syntax: " << n << " [OPTION] [<FILM>]\n" << " -h, --help show this help\n" - << " -o, --output output filename\n" + << " -o, --output output file or directory\n" << " -f, --valid-from valid from time (e.g. \"2013-09-28 01:41:51\")\n" << " -t, --valid-to valid to time (e.g. \"2014-09-28 01:41:51\")\n" - << " -c, --certificate file containing projector certificate\n"; + << " -c, --certificate file containing projector certificate\n" + << " -z, --zip ZIP each cinema's KDMs into its own file\n" + << " --cinema specify a cinema, either by name or email address\n" + << " --cinemas list known cinemas from the DCP-o-matic settings\n"; } int main (int argc, char* argv[]) { - string output; - string valid_from; - string valid_to; + boost::filesystem::path output; + boost::posix_time::ptime valid_from; + boost::posix_time::ptime valid_to; string certificate_file; + bool zip = false; + string cinema_name; + bool cinemas = false; int option_index = 0; while (1) { @@ -51,10 +63,13 @@ int main (int argc, char* argv[]) { "valid-from", required_argument, 0, 'f'}, { "valid-to", required_argument, 0, 't'}, { "certificate", required_argument, 0, 'c' }, + { "cinema", required_argument, 0, 'A' }, + { "cinemas", no_argument, 0, 'B' }, + { "zip", no_argument, 0, 'z' }, { 0, 0, 0, 0 } }; - int c = getopt_long (argc, argv, "ho:f:t:c:", long_options, &option_index); + int c = getopt_long (argc, argv, "ho:f:t:c:A:Bz", long_options, &option_index); if (c == -1) { break; @@ -68,15 +83,32 @@ int main (int argc, char* argv[]) output = optarg; break; case 'f': - valid_from = optarg; + valid_from = boost::posix_time::time_from_string (optarg); break; case 't': - valid_to = optarg; + valid_to = boost::posix_time::time_from_string (optarg); break; case 'c': certificate_file = optarg; break; + case 'A': + cinema_name = optarg; + break; + case 'B': + cinemas = true; + break; + case 'z': + zip = true; + break; + } + } + + if (cinemas) { + list<boost::shared_ptr<Cinema> > cinemas = Config::instance()->cinemas (); + for (list<boost::shared_ptr<Cinema> >::const_iterator i = cinemas.begin(); i != cinemas.end(); ++i) { + cout << (*i)->name << " (" << (*i)->email << ")\n"; } + exit (EXIT_SUCCESS); } if (optind >= argc) { @@ -84,6 +116,11 @@ int main (int argc, char* argv[]) exit (EXIT_FAILURE); } + if (cinema_name.empty() && certificate_file.empty()) { + cerr << argv[0] << ": you must specify either a cinema, a screen or a certificate file\n"; + exit (EXIT_FAILURE); + } + string const film_dir = argv[optind]; dcpomatic_setup (); @@ -97,12 +134,34 @@ int main (int argc, char* argv[]) exit (EXIT_FAILURE); } - cerr << "reading " << certificate_file << "\n"; - shared_ptr<libdcp::Certificate> certificate (new libdcp::Certificate (boost::filesystem::path (certificate_file))); - libdcp::KDM kdm = film->make_kdm ( - certificate, boost::posix_time::time_from_string (valid_from), boost::posix_time::time_from_string (valid_to) - ); + if (cinema_name.empty ()) { + shared_ptr<libdcp::Certificate> certificate (new libdcp::Certificate (boost::filesystem::path (certificate_file))); + libdcp::KDM kdm = film->make_kdm (certificate, valid_from, valid_to); + kdm.as_xml (output); + } else { + + list<shared_ptr<Cinema> > cinemas = Config::instance()->cinemas (); + list<shared_ptr<Cinema> >::const_iterator i = cinemas.begin(); + while (i != cinemas.end() && (*i)->name != cinema_name && (*i)->email != cinema_name) { + ++i; + } + + if (i == cinemas.end ()) { + cerr << argv[0] << ": could not find cinema \"" << cinema_name << "\"\n"; + exit (EXIT_FAILURE); + } + + try { + if (zip) { + write_kdm_zip_files (film, (*i)->screens(), valid_from, valid_to, output); + } else { + write_kdm_files (film, (*i)->screens(), valid_from, valid_to, output); + } + } catch (FileError& e) { + cerr << argv[0] << ": " << e.what() << " (" << e.file().string() << ")\n"; + exit (EXIT_FAILURE); + } + } - kdm.as_xml (output); return 0; } |
