Supporters update.
[dcpomatic.git] / src / lib / dcp_transcode_job.cc
1 /*
2     Copyright (C) 2021-2022 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
22 #include "config.h"
23 #include "dcp_content.h"
24 #include "dcp_digest_file.h"
25 #include "dcp_transcode_job.h"
26 #include "film.h"
27 #include "job_manager.h"
28 #include "upload_job.h"
29 #include <dcp/cpl.h>
30 #include <dcp/search.h>
31
32
33 using std::dynamic_pointer_cast;
34 using std::make_shared;
35 using std::shared_ptr;
36 using std::vector;
37
38
39 DCPTranscodeJob::DCPTranscodeJob (shared_ptr<const Film> film, ChangedBehaviour changed)
40         : TranscodeJob (film, changed)
41 {
42
43 }
44
45
46 void
47 DCPTranscodeJob::post_transcode ()
48 {
49         if (Config::instance()->upload_after_make_dcp()) {
50                 JobManager::instance()->add(make_shared<UploadJob>(_film));
51         }
52
53         /* The first directory is the project's DCP, so the first CPL will also be from the project
54          * (not from one of the DCPs imported into the project).
55          */
56         vector<boost::filesystem::path> all_directories = { _film->dir(_film->dcp_name()) };
57
58         vector<dcp::EncryptedKDM> all_kdms;
59         for (auto content: _film->content()) {
60                 if (auto dcp_content = dynamic_pointer_cast<DCPContent>(content)) {
61                         auto directories = dcp_content->directories();
62                         std::copy (directories.begin(), directories.end(), std::back_inserter(all_directories));
63                         if (dcp_content->kdm()) {
64                                 all_kdms.push_back (dcp_content->kdm().get());
65                         }
66                 }
67         }
68
69         auto cpls = dcp::find_and_resolve_cpls (all_directories, true);
70         DCPOMATIC_ASSERT (!cpls.empty());
71         auto cpl = cpls.front ();
72
73         for (auto const& kdm: all_kdms) {
74                 cpl->add (decrypt_kdm_with_helpful_error(kdm));
75         }
76
77         write_dcp_digest_file (_film->file(cpl->annotation_text().get_value_or(cpl->id()) + ".dcpdig"), cpl, _film->key().hex());
78 }
79