Support download of KDMs from a web service in swaroop profile. v2.13.56
authorCarl Hetherington <cth@carlh.net>
Wed, 26 Sep 2018 22:18:51 +0000 (23:18 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 26 Sep 2018 22:18:51 +0000 (23:18 +0100)
src/lib/config.cc
src/lib/config.h
src/lib/internet.cc
src/lib/internet.h
src/tools/dcpomatic_player.cc
src/wx/player_config_dialog.cc

index b61b1d054db99b9badb5299d4fb2449750399fa1..abb775be8ec33e066de2caa0140260d4f2fa2d01 100644 (file)
@@ -171,6 +171,7 @@ Config::set_defaults ()
        _player_kdm_directory = boost::none;
 #ifdef DCPOMATIC_VARIANT_SWAROOP
        _player_background_image = boost::none;
+       _kdm_server_url = "http://localhost:8000/{CPL}";
 #endif
 
        _allowed_dcp_frame_rates.clear ();
@@ -506,6 +507,7 @@ try
        _player_kdm_directory = f.optional_string_child("PlayerKDMDirectory");
 #ifdef DCPOMATIC_VARIANT_SWAROOP
        _player_background_image = f.optional_string_child("PlayerBackgroundImage");
+       _kdm_server_url = f.optional_string_child("KDMServerURL").get_value_or("http://localhost:8000/{CPL}");
 #endif
 
        /* Replace any cinemas from config.xml with those from the configured file */
@@ -908,6 +910,7 @@ Config::write_config () const
        if (_player_background_image) {
                root->add_child("PlayerBackgroundImage")->add_child_text(_player_background_image->string());
        }
+       root->add_child("KDMServerURL")->add_child_text(_kdm_server_url);
 #endif
 
        try {
index 2ebfef84d5a9d8a7c196cb04ca57e7b8919ae979..378272ff0a84159cdc524870d6dfb246e0e165ae 100644 (file)
@@ -497,6 +497,10 @@ public:
        boost::optional<boost::filesystem::path> player_background_image () const {
                return _player_background_image;
        }
+
+       std::string kdm_server_url () const {
+               return _kdm_server_url;
+       }
 #endif
 
        /* SET (mostly) */
@@ -957,6 +961,10 @@ public:
                _player_background_image = boost::none;
                changed (PLAYER_BACKGROUND_IMAGE);
        }
+
+       void set_kdm_server_url (std::string s) {
+               maybe_set (_kdm_server_url, s);
+       }
 #endif
 
        void changed (Property p = OTHER);
@@ -1153,6 +1161,7 @@ private:
        boost::optional<boost::filesystem::path> _player_kdm_directory;
 #ifdef DCPOMATIC_VARIANT_SWAROOP
        boost::optional<boost::filesystem::path> _player_background_image;
+       std::string _kdm_server_url;
 #endif
 
        static int const _current_version;
index 846dbf7cae3fa7849e97e59ed6b126a1eba68281..662a82443623ed256af0394c75dbfa6b8a505972 100644 (file)
@@ -46,7 +46,6 @@ get_from_url_data (void* buffer, size_t size, size_t nmemb, void* stream)
        return fwrite (buffer, size, nmemb, f);
 }
 
-static
 optional<string>
 get_from_url (string url, bool pasv, ScopedTemporary& temp)
 {
index 15746a44af8cf726cce096f1bb4e8b24b10f725d..101eaeae969bf3ae50d1cf4af3a5c75fd18c89d0 100644 (file)
@@ -22,5 +22,8 @@
 #include <boost/function.hpp>
 #include <boost/filesystem.hpp>
 
+class ScopedTemporary;
+
+boost::optional<std::string> get_from_url (std::string url, bool pasv, ScopedTemporary& temp);
 boost::optional<std::string> get_from_url (std::string url, bool pasv, boost::function<void (boost::filesystem::path)> load);
 boost::optional<std::string> get_from_zip_url (std::string url, std::string file, bool pasv, boost::function<void (boost::filesystem::path)> load);
index db9b21d925958cd04f07c98f53a981ce60d6ad01..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>
@@ -320,20 +322,43 @@ public:
                optional<boost::filesystem::path> kdm_dir = Config::instance()->player_kdm_directory();
                if (dcp->needs_kdm() && kdm_dir) {
                        /* Look for a 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 {
-                                               dcp::EncryptedKDM kdm(dcp::file_to_string(i->path()));
-                                               if (kdm.cpl_id() == dcp->cpl()) {
-                                                       dcp->add_kdm (kdm);
-                                                       dcp->examine (shared_ptr<Job>());
+
+                       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 */
                                                }
-                                       } catch (...) {
-                                               /* Hey well */
                                        }
                                }
                        }
+
+                       if (kdm) {
+                               dcp->add_kdm (*kdm);
+                               dcp->examine (shared_ptr<Job>());
+                       }
                }
 
                setup_from_dcp (dcp);
index 768459e0a1b4298c5fe6b34c3c404a5d8aab42b3..0a6985bd1d2244dc552126dbc0e629aecaf5b8c9 100644 (file)
@@ -125,6 +125,11 @@ private:
                _background_image = new FilePickerCtrl (_panel, _("Select image file"), "*.png;*.jpg;*.jpeg;*.tif;*.tiff", true);
                table->Add (_background_image, wxGBPosition (r, 1));
                ++r;
+
+               add_label_to_sizer (table, _panel, _("KDM server URL"), true, wxGBPosition(r, 0));
+               _kdm_server_url = new wxTextCtrl (_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(400, -1));
+               table->Add (_kdm_server_url, wxGBPosition (r, 1));
+               ++r;
 #endif
 
                _player_mode->Bind (wxEVT_CHOICE, bind(&PlayerGeneralPage::player_mode_changed, this));
@@ -135,6 +140,7 @@ private:
                _kdm_directory->Bind (wxEVT_DIRPICKER_CHANGED, bind(&PlayerGeneralPage::kdm_directory_changed, this));
 #ifdef DCPOMATIC_VARIANT_SWAROOP
                _background_image->Bind (wxEVT_FILEPICKER_CHANGED, bind(&PlayerGeneralPage::background_image_changed, this));
+               _kdm_server_url->Bind (wxEVT_TEXT, bind(&PlayerGeneralPage::kdm_server_url_changed, this));
 #endif
        }
 
@@ -171,6 +177,7 @@ private:
                if (config->player_background_image()) {
                        checked_set (_background_image, *config->player_background_image());
                }
+               checked_set (_kdm_server_url, config->kdm_server_url());
 #endif
        }
 
@@ -220,6 +227,11 @@ private:
        {
                Config::instance()->set_player_background_image(wx_to_std(_background_image->GetPath()));
        }
+
+       void kdm_server_url_changed ()
+       {
+               Config::instance()->set_kdm_server_url(wx_to_std(_kdm_server_url->GetValue()));
+       }
 #endif
 
        wxChoice* _player_mode;
@@ -230,6 +242,7 @@ private:
        wxDirPickerCtrl* _kdm_directory;
 #ifdef DCPOMATIC_VARIANT_SWAROOP
        FilePickerCtrl* _background_image;
+       wxTextCtrl* _kdm_server_url;
 #endif
 };