-#include "lib/film.h"
-#include "lib/cinema.h"
-#include "lib/screen_kdm.h"
-#include "lib/cinema_kdms.h"
-#include "lib/config.h"
-#include "lib/exceptions.h"
-#include "lib/emailer.h"
-#include <dcp/certificate.h>
-#include <getopt.h>
-#include <iostream>
-
-using std::string;
-using std::cout;
-using std::cerr;
-using std::list;
-using std::vector;
-using boost::shared_ptr;
-using boost::optional;
-using boost::bind;
-
-static void
-help ()
-{
- cerr << "Syntax: " << program_name << " [OPTION] [<FILM>]\n"
- " -h, --help show this help\n"
- " -o, --output output file or directory\n"
- " -f, --valid-from valid from time (in local time zone of the cinema) (e.g. \"2013-09-28 01:41:51\") or \"now\"\n"
- " -t, --valid-to valid to time (in local time zone of the cinema) (e.g. \"2014-09-28 01:41:51\")\n"
- " -d, --valid-duration valid duration (e.g. \"1 day\", \"4 hours\", \"2 weeks\")\n"
- " --formulation modified-transitional-1, dci-any or dci-specific [default modified-transitional-1]\n"
- " -z, --zip ZIP each cinema's KDMs into its own file\n"
- " -v, --verbose be verbose\n"
- " -c, --cinema specify a cinema, either by name or email address\n"
- " --cinemas list known cinemas from the DCP-o-matic settings\n"
- " --certificate file containing projector certificate\n\n"
- "For example:\n\n"
- "Create KDMs for my_great_movie to play in all of Fred's Cinema's screens for the next two weeks and zip them up.\n"
- "(Fred's Cinema must have been set up in DCP-o-matic's KDM window)\n\n"
- "\tdcpomatic_kdm -c \"Fred's Cinema\" -f now -d \"2 weeks\" -z my_great_movie\n\n";
-}
-
-static void
-error (string m)
-{
- cerr << program_name << ": " << m << "\n";
- exit (EXIT_FAILURE);
-}
-
-static boost::posix_time::ptime
-time_from_string (string t)
-{
- if (t == "now") {
- return boost::posix_time::second_clock::local_time ();
- }
-
- return boost::posix_time::time_from_string (t);
-}
-
-static boost::posix_time::time_duration
-duration_from_string (string d)
-{
- int N;
- char unit_buf[64] = "\0";
- sscanf (d.c_str(), "%d %63s", &N, unit_buf);
- string const unit (unit_buf);
-
- if (N == 0) {
- cerr << "Could not understand duration \"" << d << "\"\n";
- exit (EXIT_FAILURE);
- }
-
- if (unit == "year" || unit == "years") {
- return boost::posix_time::time_duration (N * 24 * 365, 0, 0, 0);
- } else if (unit == "week" || unit == "weeks") {
- return boost::posix_time::time_duration (N * 24 * 7, 0, 0, 0);
- } else if (unit == "day" || unit == "days") {
- return boost::posix_time::time_duration (N * 24, 0, 0, 0);
- } else if (unit == "hour" || unit == "hours") {
- return boost::posix_time::time_duration (N, 0, 0, 0);
- }
-
- cerr << "Could not understand duration \"" << d << "\"\n";
- exit (EXIT_FAILURE);
-}
-
-static bool
-always_overwrite ()
-{
- return true;
-}
-
-void
-write_files (list<ScreenKDM> screen_kdms, bool zip, boost::filesystem::path output, dcp::NameFormat::Map values, bool verbose)
-{
- if (zip) {
- int const N = CinemaKDMs::write_zip_files (
- CinemaKDMs::collect (screen_kdms),
- output,
- Config::instance()->kdm_container_name_format(),
- Config::instance()->kdm_filename_format(),
- values,
- bind (&always_overwrite)
- );
-
- if (verbose) {
- cout << "Wrote " << N << " ZIP files to " << output << "\n";
- }
- } else {
- int const N = ScreenKDM::write_files (
- screen_kdms, output, Config::instance()->kdm_filename_format(), values,
- bind (&always_overwrite)
- );