+
+ write_cover_sheet (output_dcp);
+}
+
+
+void
+Writer::write_cover_sheet (boost::filesystem::path output_dcp)
+{
+ auto const cover = film()->file("COVER_SHEET.txt");
+ auto f = fopen_boost (cover, "w");
+ if (!f) {
+ throw OpenFileError (cover, errno, OpenFileError::WRITE);
+ }
+
+ auto text = Config::instance()->cover_sheet ();
+ boost::algorithm::replace_all (text, "$CPL_NAME", film()->name());
+ 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 subtitle_languages = film()->subtitle_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 = boost::filesystem::recursive_directory_iterator(output_dcp);
+ i != boost::filesystem::recursive_directory_iterator();
+ ++i) {
+ if (boost::filesystem::is_regular_file (i->path())) {
+ size += boost::filesystem::file_size (i->path());
+ }
+ }
+
+ if (size > (1000000000L)) {
+ boost::algorithm::replace_all (text, "$SIZE", String::compose("%1GB", dcp::locale_convert<string>(size / 1000000000.0, 1, true)));
+ } else {
+ boost::algorithm::replace_all (text, "$SIZE", String::compose("%1MB", dcp::locale_convert<string>(size / 1000000.0, 1, true)));
+ }
+
+ auto ch = audio_channel_types (film()->mapped_audio_channels(), film()->audio_channels());
+ auto description = String::compose("%1.%2", 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 = String::compose("%1s", hmsf.s);
+ } else if (hmsf.h == 0 && hmsf.m > 0) {
+ length = String::compose("%1m%2s", hmsf.m, hmsf.s);
+ } else if (hmsf.h > 0 && hmsf.m > 0) {
+ length = String::compose("%1h%2m%3s", hmsf.h, hmsf.m, hmsf.s);
+ }
+
+ boost::algorithm::replace_all (text, "$LENGTH", length);
+
+ checked_fwrite (text.c_str(), text.length(), f, cover);
+ fclose (f);