+
+ write_cover_sheet (output_dcp);
+}
+
+void
+Writer::write_cover_sheet (boost::filesystem::path output_dcp)
+{
+ boost::filesystem::path const cover = film()->file("COVER_SHEET.txt");
+ FILE* f = fopen_boost (cover, "w");
+ if (!f) {
+ throw OpenFileError (cover, errno, OpenFileError::WRITE);
+ }
+
+ string 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());
+ boost::algorithm::replace_all (text, "$AUDIO_LANGUAGE", film()->isdcf_metadata().audio_language);
+
+ vector<dcp::LanguageTag> subtitle_languages = film()->subtitle_languages();
+ if (subtitle_languages.empty()) {
+ boost::algorithm::replace_all (text, "$SUBTITLE_LANGUAGE", "None");
+ } else {
+ boost::algorithm::replace_all (text, "$SUBTITLE_LANGUAGE", subtitle_languages.front().description());
+ }
+
+ boost::uintmax_t size = 0;
+ for (
+ boost::filesystem::recursive_directory_iterator 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)));
+ }
+
+ pair<int, int> ch = audio_channel_types (film()->mapped_audio_channels(), film()->audio_channels());
+ string 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);
+
+ int h, m, s, fr;
+ film()->length().split(film()->video_frame_rate(), h, m, s, fr);
+ string length;
+ if (h == 0 && m == 0) {
+ length = String::compose("%1s", s);
+ } else if (h == 0 && m > 0) {
+ length = String::compose("%1m%2s", m, s);
+ } else if (h > 0 && m > 0) {
+ length = String::compose("%1h%2m%3s", h, m, s);
+ }
+
+ boost::algorithm::replace_all (text, "$LENGTH", length);
+
+ checked_fwrite (text.c_str(), text.length(), f, cover);
+ fclose (f);