diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-09-26 23:18:51 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-09-26 23:18:51 +0100 |
| commit | 39a7a8be0bdb499423f96aa23ed3bffdc7d6c912 (patch) | |
| tree | 847ea6e5b055f94e33bcc0a91ad4ba4d29a81d8a | |
| parent | 2d48fee30e323dfea9cc331f881637d91ee0895a (diff) | |
Support download of KDMs from a web service in swaroop profile.v2.13.56
| -rw-r--r-- | src/lib/config.cc | 3 | ||||
| -rw-r--r-- | src/lib/config.h | 9 | ||||
| -rw-r--r-- | src/lib/internet.cc | 1 | ||||
| -rw-r--r-- | src/lib/internet.h | 3 | ||||
| -rw-r--r-- | src/tools/dcpomatic_player.cc | 45 | ||||
| -rw-r--r-- | src/wx/player_config_dialog.cc | 13 |
6 files changed, 63 insertions, 11 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index b61b1d054..abb775be8 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -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 { diff --git a/src/lib/config.h b/src/lib/config.h index 2ebfef84d..378272ff0 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -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; diff --git a/src/lib/internet.cc b/src/lib/internet.cc index 846dbf7ca..662a82443 100644 --- a/src/lib/internet.cc +++ b/src/lib/internet.cc @@ -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) { diff --git a/src/lib/internet.h b/src/lib/internet.h index 15746a44a..101eaeae9 100644 --- a/src/lib/internet.h +++ b/src/lib/internet.h @@ -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); diff --git a/src/tools/dcpomatic_player.cc b/src/tools/dcpomatic_player.cc index db9b21d92..8329f1d86 100644 --- a/src/tools/dcpomatic_player.cc +++ b/src/tools/dcpomatic_player.cc @@ -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); diff --git a/src/wx/player_config_dialog.cc b/src/wx/player_config_dialog.cc index 768459e0a..0a6985bd1 100644 --- a/src/wx/player_config_dialog.cc +++ b/src/wx/player_config_dialog.cc @@ -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 }; |
