diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-12-21 23:57:09 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-12-21 23:57:09 +0000 |
| commit | 12b1a3f10ee0e14691e68784bfccc7359d44b0a4 (patch) | |
| tree | 314f5414d4cfdf97417842a8d625bfd324eee897 /src/wx | |
| parent | f37b8122a04c6a7f8a86c77de44ac995b9555d1a (diff) | |
swaroop: check for KDMs when selecting playlist.
Diffstat (limited to 'src/wx')
| -rw-r--r-- | src/wx/swaroop_controls.cc | 67 | ||||
| -rw-r--r-- | src/wx/swaroop_controls.h | 5 |
2 files changed, 72 insertions, 0 deletions
diff --git a/src/wx/swaroop_controls.cc b/src/wx/swaroop_controls.cc index 870ac518b..7eed86743 100644 --- a/src/wx/swaroop_controls.cc +++ b/src/wx/swaroop_controls.cc @@ -27,6 +27,8 @@ #include "lib/player_video.h" #include "lib/dcp_content.h" #include "lib/cross.h" +#include "lib/scoped_temporary.h" +#include "lib/internet.h" #include <dcp/raw_convert.h> #include <wx/listctrl.h> #include <wx/progdlg.h> @@ -317,6 +319,49 @@ SwaroopControls::update_playlist_directory () _selected_playlist = boost::none; } +optional<dcp::EncryptedKDM> +SwaroopControls::get_kdm_from_url (shared_ptr<DCPContent> dcp) +{ + ScopedTemporary temp; + string url = Config::instance()->kdm_server_url(); + boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl()); + optional<dcp::EncryptedKDM> kdm; + if (dcp->cpl() && !get_from_url(url, 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 */ + } + } + return kdm; +} + +optional<dcp::EncryptedKDM> +SwaroopControls::get_kdm_from_directory (shared_ptr<DCPContent> dcp) +{ + using namespace boost::filesystem; + optional<path> kdm_dir = Config::instance()->player_kdm_directory(); + if (!kdm_dir) { + return optional<dcp::EncryptedKDM>(); + } + for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) { + try { + if (file_size(i->path()) < MAX_KDM_SIZE) { + dcp::EncryptedKDM kdm (dcp::file_to_string(i->path())); + if (kdm.cpl_id() == dcp->cpl()) { + return kdm; + } + } + } catch (std::exception& e) { + /* Hey well */ + } + } + return optional<dcp::EncryptedKDM>(); +} + void SwaroopControls::spl_selection_changed () { @@ -342,6 +387,28 @@ SwaroopControls::spl_selection_changed () wxProgressDialog dialog (_("DCP-o-matic"), "Loading playlist"); dialog.Pulse (); + BOOST_FOREACH (SPLEntry const & i, _playlists[selected].get()) { + shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (i.content); + if (dcp && dcp->needs_kdm()) { + optional<dcp::EncryptedKDM> kdm; + kdm = get_kdm_from_url (dcp); + if (!kdm) { + kdm = get_kdm_from_directory (dcp); + } + if (kdm) { + dcp->add_kdm (*kdm); + dcp->examine (_film, shared_ptr<Job>()); + } + if (dcp->needs_kdm()) { + /* We didn't get a KDM for this */ + error_dialog (this, "This playlist cannot be loaded as a KDM is missing."); + _selected_playlist = boost::none; + _spl_view->SetItemState (selected, 0, wxLIST_STATE_SELECTED); + return; + } + } + } + _current_spl_view->DeleteAllItems (); int N = 0; diff --git a/src/wx/swaroop_controls.h b/src/wx/swaroop_controls.h index 077b16fbe..e2c4190b6 100644 --- a/src/wx/swaroop_controls.h +++ b/src/wx/swaroop_controls.h @@ -20,6 +20,8 @@ #include "controls.h" +class DCPContent; + class SwaroopControls : public Controls { public: @@ -56,6 +58,9 @@ private: bool can_do_previous (); bool can_do_next (); + boost::optional<dcp::EncryptedKDM> get_kdm_from_url (boost::shared_ptr<DCPContent> dcp); + boost::optional<dcp::EncryptedKDM> get_kdm_from_directory (boost::shared_ptr<DCPContent> dcp); + wxButton* _play_button; wxButton* _pause_button; wxButton* _stop_button; |
