Remove left-over file.
[dcpomatic.git] / src / lib / film.cc
index aacc5a4ccaa9ba241ba403a3ff9e246b6b016af8..bb210350e6fae4f4dc3baef7e1ee53db6f70be72 100644 (file)
@@ -34,6 +34,8 @@
 #include <libdcp/signer_chain.h>
 #include <libdcp/cpl.h>
 #include <libdcp/signer.h>
+#include <libdcp/util.h>
+#include <libdcp/kdm.h>
 #include "film.h"
 #include "job.h"
 #include "util.h"
@@ -96,10 +98,10 @@ Film::Film (boost::filesystem::path dir)
        , _resolution (RESOLUTION_2K)
        , _scaler (Scaler::from_id ("bicubic"))
        , _with_subtitles (false)
+       , _encrypted (false)
        , _j2k_bandwidth (Config::instance()->default_j2k_bandwidth ())
        , _dci_metadata (Config::instance()->default_dci_metadata ())
        , _video_frame_rate (24)
-       , _encrypted (false)
        , _audio_channels (MAX_AUDIO_CHANNELS)
        , _three_d (false)
        , _sequence_video (true)
@@ -129,7 +131,7 @@ Film::Film (boost::filesystem::path dir)
                }
        }
 
-       set_directory (result.string ());
+       set_directory (result);
        _log.reset (new FileLog (file ("log")));
 
        _playlist->set_sequence_video (_sequence_video);
@@ -311,13 +313,13 @@ Film::encoded_frames () const
 void
 Film::write_metadata () const
 {
-       if (!boost::filesystem::exists (directory())) {
-               boost::filesystem::create_directory (directory());
+       if (!boost::filesystem::exists (directory ())) {
+               boost::filesystem::create_directory (directory ());
        }
        
        LocaleGuard lg;
 
-       boost::filesystem::create_directories (directory());
+       boost::filesystem::create_directories (directory ());
 
        xmlpp::Document doc;
        xmlpp::Element* root = doc.create_root_node ("Metadata");
@@ -346,6 +348,7 @@ Film::write_metadata () const
        root->add_child("SequenceVideo")->add_child_text (_sequence_video ? "1" : "0");
        root->add_child("Interop")->add_child_text (_interop ? "1" : "0");
        root->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
+       root->add_child("Key")->add_child_text (_key.hex ());
        _playlist->as_xml (root->add_child ("Playlist"));
 
        doc.write_to_file_formatted (file ("metadata.xml"));
@@ -395,7 +398,7 @@ Film::read_metadata ()
        _sequence_video = f.bool_child ("SequenceVideo");
        _three_d = f.bool_child ("ThreeD");
        _interop = f.bool_child ("Interop");
-
+       _key = libdcp::Key (f.string_child ("Key"));
        _playlist->set_from_xml (shared_from_this(), f.node_child ("Playlist"));
 
        _dirty = false;
@@ -543,7 +546,7 @@ Film::dcp_name (bool if_created_now) const
 
 
 void
-Film::set_directory (string d)
+Film::set_directory (boost::filesystem::path d)
 {
        _directory = d;
        _dirty = true;
@@ -721,22 +724,30 @@ Film::j2c_path (int f, Eyes e, bool t) const
        return file (p.string ());
 }
 
-/** Make an educated guess as to whether we have a complete DCP
- *  or not.
- *  @return true if we do.
- */
-
-bool
-Film::have_dcp () const
+/** @return List of subdirectories (not full paths) containing DCPs that can be successfully libdcp::DCP::read() */
+list<boost::filesystem::path>
+Film::dcps () const
 {
-       try {
-               libdcp::DCP dcp (dir (dcp_name()));
-               dcp.read ();
-       } catch (...) {
-               return false;
-       }
+       list<boost::filesystem::path> out;
+       
+       boost::filesystem::path const dir = directory ();
+       for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator(dir); i != boost::filesystem::directory_iterator(); ++i) {
+               if (
+                       boost::filesystem::is_directory (*i) &&
+                       i->path().leaf() != "j2c" && i->path().leaf() != "video" && i->path().leaf() != "info" && i->path().leaf() != "analysis"
+                       ) {
 
-       return true;
+                       try {
+                               libdcp::DCP dcp (*i);
+                               dcp.read ();
+                               out.push_back (i->path().leaf ());
+                       } catch (...) {
+
+                       }
+               }
+       }
+       
+       return out;
 }
 
 shared_ptr<Player>
@@ -803,6 +814,18 @@ Film::remove_content (shared_ptr<Content> c)
        _playlist->remove (c);
 }
 
+void
+Film::move_content_earlier (shared_ptr<Content> c)
+{
+       _playlist->move_earlier (c);
+}
+
+void
+Film::move_content_later (shared_ptr<Content> c)
+{
+       _playlist->move_later (c);
+}
+
 Time
 Film::length () const
 {
@@ -892,72 +915,46 @@ Film::full_frame () const
        return libdcp::Size ();
 }
 
-void
-Film::make_kdms (
-       list<shared_ptr<Screen> > screens,
+libdcp::KDM
+Film::make_kdm (
+       shared_ptr<libdcp::Certificate> target,
+       boost::filesystem::path dcp_dir,
        boost::posix_time::ptime from,
-       boost::posix_time::ptime until,
-       string directory
+       boost::posix_time::ptime until
        ) const
 {
-       boost::filesystem::path const sd = Config::instance()->signer_chain_directory ();
-       if (boost::filesystem::is_empty (sd)) {
-               libdcp::make_signer_chain (sd);
-       }
-
-       libdcp::CertificateChain chain;
-
-       {
-               boost::filesystem::path p (sd);
-               p /= "ca.self-signed.pem";
-               chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
-       }
-
-       {
-               boost::filesystem::path p (sd);
-               p /= "intermediate.signed.pem";
-               chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
-       }
-
-       {
-               boost::filesystem::path p (sd);
-               p /= "leaf.signed.pem";
-               chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
-       }
+       shared_ptr<const Signer> signer = make_signer ();
 
-       boost::filesystem::path signer_key (sd);
-       signer_key /= "leaf.key";
-
-       shared_ptr<const Signer> signer (new Signer (chain, signer_key));
-
-       /* Find the DCP to make the KDM for */
-       string const dir = this->directory ();
-       list<string> dcps;
-       for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator(dir); i != boost::filesystem::directory_iterator(); ++i) {
-               if (boost::filesystem::is_directory (*i) && i->path().leaf() != "j2c" && i->path().leaf() != "wavs") {
-                       dcps.push_back (i->path().string());
-               }
+       libdcp::DCP dcp (dir (dcp_dir.string ()));
+       
+       try {
+               dcp.read ();
+       } catch (...) {
+               throw KDMError (_("Could not read DCP to make KDM for"));
        }
+       
+       time_t now = time (0);
+       struct tm* tm = localtime (&now);
+       string const issue_date = libdcp::tm_to_string (tm);
+       
+       dcp.cpls().front()->set_mxf_keys (key ());
+       
+       return libdcp::KDM (dcp.cpls().front(), signer, target, from, until, "DCP-o-matic", issue_date);
+}
 
-       if (dcps.empty()) {
-               throw KDMError ("Could not find DCP to make KDM for");
-       } else if (dcps.size() > 1) {
-               throw KDMError ("More than one possible DCP to make KDM for");
-       }
+list<libdcp::KDM>
+Film::make_kdms (
+       list<shared_ptr<Screen> > screens,
+       boost::filesystem::path dcp,
+       boost::posix_time::ptime from,
+       boost::posix_time::ptime until
+       ) const
+{
+       list<libdcp::KDM> kdms;
 
        for (list<shared_ptr<Screen> >::iterator i = screens.begin(); i != screens.end(); ++i) {
-
-               libdcp::DCP dcp (dcps.front ());
-               dcp.read ();
-               
-               /* XXX: single CPL only */
-               shared_ptr<xmlpp::Document> kdm = dcp.cpls().front()->make_kdm (
-                       signer, (*i)->certificate, from, until, _interop, libdcp::MXFMetadata (), Config::instance()->dcp_metadata ()
-                       );
-
-               boost::filesystem::path out = directory;
-               out /= "kdm.xml";
-               kdm->write_to_file_formatted (out.string());
+               kdms.push_back (make_kdm ((*i)->certificate, dcp, from, until));
        }
+
+       return kdms;
 }
-