8704f627ac39e624b02214d4230d5a17f73fb409
[dcpomatic.git] / src / lib / dkdm_recipient.cc
1 /*
2     Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "dkdm_recipient.h"
22 #include "kdm_with_metadata.h"
23 #include "film.h"
24 #include <dcp/raw_convert.h>
25
26
27 using std::string;
28 using std::vector;
29 using std::shared_ptr;
30 using dcp::raw_convert;
31
32
33 DKDMRecipient::DKDMRecipient (cxml::ConstNodePtr node)
34         : KDMRecipient (node)
35 {
36         for (auto i: node->node_children("Email")) {
37                 emails.push_back (i->content());
38         }
39
40         utc_offset_hour = node->number_child<int>("UTCOffsetHour");
41         utc_offset_minute = node->number_child<int>("UTCOffsetMinute");
42 }
43
44
45 void
46 DKDMRecipient::as_xml (xmlpp::Element* node) const
47 {
48         KDMRecipient::as_xml (node);
49
50         for (auto i: emails) {
51                 node->add_child("Email")->add_child_text(i);
52         }
53
54         node->add_child("UTCOffsetHour")->add_child_text(raw_convert<string>(utc_offset_hour));
55         node->add_child("UTCOffsetMinute")->add_child_text(raw_convert<string>(utc_offset_minute));
56 }
57
58
59 KDMWithMetadataPtr
60 kdm_for_dkdm_recipient (
61         shared_ptr<const Film> film,
62         boost::filesystem::path cpl,
63         shared_ptr<DKDMRecipient> recipient,
64         boost::posix_time::ptime valid_from,
65         boost::posix_time::ptime valid_to
66         )
67 {
68         if (!recipient->recipient) {
69                 return KDMWithMetadataPtr();
70         }
71
72         dcp::LocalTime const begin(valid_from, recipient->utc_offset_hour, recipient->utc_offset_minute);
73         dcp::LocalTime const end  (valid_to,   recipient->utc_offset_hour, recipient->utc_offset_minute);
74
75         dcp::EncryptedKDM const kdm = film->make_kdm (
76                         recipient->recipient.get(),
77                         vector<string>(),
78                         cpl,
79                         begin,
80                         end,
81                         dcp::Formulation::MODIFIED_TRANSITIONAL_1,
82                         true,
83                         0
84                         );
85
86         dcp::NameFormat::Map name_values;
87         name_values['f'] = film->name();
88         name_values['b'] = begin.date() + " " + begin.time_of_day(true, false);
89         name_values['e'] = end.date() + " " + end.time_of_day(true, false);
90         name_values['i'] = kdm.cpl_id();
91
92         return KDMWithMetadataPtr(new KDMWithMetadata(name_values, 0, recipient->emails, kdm));
93 }
94