Support download of KDMs from a web service in swaroop profile.
[dcpomatic.git] / src / tools / dcpomatic_player.cc
index 497182dde2a63abf6b3f586960ab9a0d7a17b82a..8329f1d8655393df71e50d8dd8bc16d3ef38b86d 100644 (file)
@@ -31,6 +31,7 @@
 #include "lib/cross.h"
 #include "lib/config.h"
 #include "lib/util.h"
+#include "lib/internet.h"
 #include "lib/update_checker.h"
 #include "lib/compose.hpp"
 #include "lib/dcp_content.h"
@@ -45,6 +46,7 @@
 #include "lib/examine_content_job.h"
 #include "lib/server.h"
 #include "lib/dcpomatic_socket.h"
+#include "lib/scoped_temporary.h"
 #include <wx/wx.h>
 #include <wx/stdpaths.h>
 #include <wx/splash.h>
@@ -315,6 +317,50 @@ public:
                        return;
                }
 
+               /* The DCP has been examined and loaded */
+
+               optional<boost::filesystem::path> kdm_dir = Config::instance()->player_kdm_directory();
+               if (dcp->needs_kdm() && kdm_dir) {
+                       /* Look for a KDM */
+
+                       optional<dcp::EncryptedKDM> kdm;
+
+                       ScopedTemporary temp;
+                       string url = Config::instance()->kdm_server_url();
+                       boost::algorithm::replace_all (url, "{CPL}", "%1");
+                       if (dcp->cpl() && !get_from_url(String::compose(url, *dcp->cpl()), false, temp)) {
+                               try {
+                                       kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
+                                       if (kdm->cpl_id() != dcp->cpl()) {
+                                               kdm = boost::none;
+                                       }
+                               } catch (std::exception& e) {
+                                       /* Hey well */
+                               }
+                       }
+
+                       if (!kdm) {
+                               using namespace boost::filesystem;
+                               for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
+                                       if (file_size(i->path()) < MAX_KDM_SIZE) {
+                                               try {
+                                                       kdm = dcp::EncryptedKDM(dcp::file_to_string(i->path()));
+                                                       if (kdm->cpl_id() == dcp->cpl()) {
+                                                               break;
+                                                       }
+                                               } catch (std::exception& e) {
+                                                       /* Hey well */
+                                               }
+                                       }
+                               }
+                       }
+
+                       if (kdm) {
+                               dcp->add_kdm (*kdm);
+                               dcp->examine (shared_ptr<Job>());
+                       }
+               }
+
                setup_from_dcp (dcp);
 
                if (dcp->three_d()) {
@@ -344,6 +390,8 @@ public:
                        j->Check(!dcp->cpl() || i->id() == *dcp->cpl());
                        ++id;
                }
+
+               _controls->log (wxString::Format(_("Load DCP %s"), dir.filename().string().c_str()));
        }
 
 private:
@@ -585,7 +633,7 @@ private:
        void setup_screen ()
        {
                _controls->Show (_mode != Config::PLAYER_MODE_FULL);
-               _controls->show_dcp_directory (_mode == Config::PLAYER_MODE_DUAL);
+               _controls->show_extended_player_controls (_mode == Config::PLAYER_MODE_DUAL);
                _info->Show (_mode != Config::PLAYER_MODE_FULL);
                _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
                ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);