summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-08-22 21:50:00 +0200
committerCarl Hetherington <cth@carlh.net>2025-08-25 08:47:42 +0200
commit99a191c599724ee8bab43146f9ea5da388c10225 (patch)
tree74146db5ab45cec449a396bf6a08b7828fc0e788
parent07efa1af2aafabe6c98098adf2bcfd5cff5f9191 (diff)
Move write_cover_sheet() out to its own file.
-rw-r--r--src/lib/cover_sheet.cc111
-rw-r--r--src/lib/cover_sheet.h35
-rw-r--r--src/lib/writer.cc79
-rw-r--r--src/lib/writer.h1
-rw-r--r--src/lib/wscript1
5 files changed, 149 insertions, 78 deletions
diff --git a/src/lib/cover_sheet.cc b/src/lib/cover_sheet.cc
new file mode 100644
index 000000000..43a749682
--- /dev/null
+++ b/src/lib/cover_sheet.cc
@@ -0,0 +1,111 @@
+/*
+ Copyright (C) 2025 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "config.h"
+#include "cover_sheet.h"
+#include "dcp_content_type.h"
+#include "film.h"
+#include <dcp/file.h>
+#include <dcp/filesystem.h>
+#include <dcp/locale_convert.h>
+#include <boost/algorithm/string.hpp>
+
+#include "i18n.h"
+
+
+using std::shared_ptr;
+using std::string;
+
+
+void
+dcpomatic::write_cover_sheet(shared_ptr<const Film> film, boost::filesystem::path dcp_directory, boost::filesystem::path output)
+{
+ dcp::File file(output, "w");
+ if (!file) {
+ throw OpenFileError(output, file.open_error(), OpenFileError::WRITE);
+ }
+
+ auto text = Config::instance()->cover_sheet();
+ boost::algorithm::replace_all(text, "$CPL_NAME", film->name());
+ auto cpls = film->cpls();
+ if (!cpls.empty()) {
+ boost::algorithm::replace_all(text, "$CPL_FILENAME", cpls[0].cpl_file.filename().string());
+ }
+ boost::algorithm::replace_all(text, "$TYPE", film->dcp_content_type()->pretty_name());
+ boost::algorithm::replace_all(text, "$CONTAINER", film->container().container_nickname());
+
+ auto audio_language = film->audio_language();
+ if (audio_language) {
+ boost::algorithm::replace_all(text, "$AUDIO_LANGUAGE", audio_language->description());
+ } else {
+ boost::algorithm::replace_all(text, "$AUDIO_LANGUAGE", _("None"));
+ }
+
+ auto const subtitle_languages = film->open_text_languages();
+ if (subtitle_languages.first) {
+ boost::algorithm::replace_all(text, "$SUBTITLE_LANGUAGE", subtitle_languages.first->description());
+ } else {
+ boost::algorithm::replace_all(text, "$SUBTITLE_LANGUAGE", _("None"));
+ }
+
+ boost::uintmax_t size = 0;
+ for (
+ auto i = dcp::filesystem::recursive_directory_iterator(dcp_directory);
+ i != dcp::filesystem::recursive_directory_iterator();
+ ++i) {
+ if (dcp::filesystem::is_regular_file(i->path())) {
+ size += dcp::filesystem::file_size(i->path());
+ }
+ }
+
+ if (size > (1000000000L)) {
+ boost::algorithm::replace_all(text, "$SIZE", fmt::format("{}GB", dcp::locale_convert<string>(size / 1000000000.0, 1, true)));
+ } else {
+ boost::algorithm::replace_all(text, "$SIZE", fmt::format("{}MB", dcp::locale_convert<string>(size / 1000000.0, 1, true)));
+ }
+
+ auto ch = audio_channel_types(film->mapped_audio_channels(), film->audio_channels());
+ auto description = fmt::format("{}.{}", ch.first, ch.second);
+
+ if (description == "0.0") {
+ description = _("None");
+ } else if (description == "1.0") {
+ description = _("Mono");
+ } else if (description == "2.0") {
+ description = _("Stereo");
+ }
+ boost::algorithm::replace_all(text, "$AUDIO", description);
+
+ auto const hmsf = film->length().split(film->video_frame_rate());
+ string length;
+ if (hmsf.h == 0 && hmsf.m == 0) {
+ length = fmt::format("{}s", hmsf.s);
+ } else if (hmsf.h == 0 && hmsf.m > 0) {
+ length = fmt::format("{}m{}s", hmsf.m, hmsf.s);
+ } else if (hmsf.h > 0 && hmsf.m > 0) {
+ length = fmt::format("{}h{}m{}s", hmsf.h, hmsf.m, hmsf.s);
+ }
+
+ boost::algorithm::replace_all(text, "$LENGTH", length);
+
+ file.checked_write(text.c_str(), text.length());
+}
+
diff --git a/src/lib/cover_sheet.h b/src/lib/cover_sheet.h
new file mode 100644
index 000000000..7f556737d
--- /dev/null
+++ b/src/lib/cover_sheet.h
@@ -0,0 +1,35 @@
+/*
+ Copyright (C) 2025 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include <boost/filesystem.hpp>
+#include <memory>
+
+
+class Film;
+
+
+namespace dcpomatic {
+
+extern void write_cover_sheet(std::shared_ptr<const Film> film, boost::filesystem::path dcp_directory, boost::filesystem::path output);
+
+}
+
+
diff --git a/src/lib/writer.cc b/src/lib/writer.cc
index 0a664e76b..dd5223670 100644
--- a/src/lib/writer.cc
+++ b/src/lib/writer.cc
@@ -23,6 +23,7 @@
#include "audio_mapping.h"
#include "config.h"
#include "constants.h"
+#include "cover_sheet.h"
#include "cross.h"
#include "dcp_content_type.h"
#include "dcp_video.h"
@@ -711,83 +712,7 @@ Writer::finish()
N_("Wrote {} FULL, {} FAKE, {} REPEAT, {} pushed to disk"), _full_written, _fake_written, _repeat_written, _pushed_to_disk
);
- write_cover_sheet();
-}
-
-
-void
-Writer::write_cover_sheet()
-{
- auto const cover = film()->file("COVER_SHEET.txt");
- dcp::File file(cover, "w");
- if (!file) {
- throw OpenFileError(cover, file.open_error(), OpenFileError::WRITE);
- }
-
- auto text = Config::instance()->cover_sheet();
- boost::algorithm::replace_all(text, "$CPL_NAME", film()->name());
- auto cpls = film()->cpls();
- if (!cpls.empty()) {
- boost::algorithm::replace_all(text, "$CPL_FILENAME", cpls[0].cpl_file.filename().string());
- }
- boost::algorithm::replace_all(text, "$TYPE", film()->dcp_content_type()->pretty_name());
- boost::algorithm::replace_all(text, "$CONTAINER", film()->container().container_nickname());
-
- auto audio_language = film()->audio_language();
- if (audio_language) {
- boost::algorithm::replace_all(text, "$AUDIO_LANGUAGE", audio_language->description());
- } else {
- boost::algorithm::replace_all(text, "$AUDIO_LANGUAGE", _("None"));
- }
-
- auto const subtitle_languages = film()->open_text_languages();
- if (subtitle_languages.first) {
- boost::algorithm::replace_all(text, "$SUBTITLE_LANGUAGE", subtitle_languages.first->description());
- } else {
- boost::algorithm::replace_all(text, "$SUBTITLE_LANGUAGE", _("None"));
- }
-
- boost::uintmax_t size = 0;
- for (
- auto i = dcp::filesystem::recursive_directory_iterator(_output_dir);
- i != dcp::filesystem::recursive_directory_iterator();
- ++i) {
- if (dcp::filesystem::is_regular_file(i->path())) {
- size += dcp::filesystem::file_size(i->path());
- }
- }
-
- if (size > (1000000000L)) {
- boost::algorithm::replace_all(text, "$SIZE", fmt::format("{}GB", dcp::locale_convert<string>(size / 1000000000.0, 1, true)));
- } else {
- boost::algorithm::replace_all(text, "$SIZE", fmt::format("{}MB", dcp::locale_convert<string>(size / 1000000.0, 1, true)));
- }
-
- auto ch = audio_channel_types(film()->mapped_audio_channels(), film()->audio_channels());
- auto description = fmt::format("{}.{}", ch.first, ch.second);
-
- if (description == "0.0") {
- description = _("None");
- } else if (description == "1.0") {
- description = _("Mono");
- } else if (description == "2.0") {
- description = _("Stereo");
- }
- boost::algorithm::replace_all(text, "$AUDIO", description);
-
- auto const hmsf = film()->length().split(film()->video_frame_rate());
- string length;
- if (hmsf.h == 0 && hmsf.m == 0) {
- length = fmt::format("{}s", hmsf.s);
- } else if (hmsf.h == 0 && hmsf.m > 0) {
- length = fmt::format("{}m{}s", hmsf.m, hmsf.s);
- } else if (hmsf.h > 0 && hmsf.m > 0) {
- length = fmt::format("{}h{}m{}s", hmsf.h, hmsf.m, hmsf.s);
- }
-
- boost::algorithm::replace_all(text, "$LENGTH", length);
-
- file.checked_write(text.c_str(), text.length());
+ dcpomatic::write_cover_sheet(film(), _output_dir, film()->file("COVER_SHEET.txt"));
}
diff --git a/src/lib/writer.h b/src/lib/writer.h
index ccb9c6213..eca2c2a9a 100644
--- a/src/lib/writer.h
+++ b/src/lib/writer.h
@@ -140,7 +140,6 @@ private:
bool have_sequenced_image_at_queue_head();
size_t video_reel(int frame) const;
void set_digest_progress(Job* job, int id, int64_t done, int64_t size);
- void write_cover_sheet();
void calculate_referenced_digests(std::function<void (int64_t, int64_t)> set_progress);
void write_hanging_text(ReelWriter& reel);
void calculate_digests();
diff --git a/src/lib/wscript b/src/lib/wscript
index e5ae1a5e2..ce93b5824 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -59,6 +59,7 @@ sources = """
content_factory.cc
combine_dcp_job.cc
copy_dcp_details_to_film.cc
+ cover_sheet.cc
cpu_j2k_encoder_thread.cc
create_cli.cc
crop.cc