Make subtitle asset filename obey custom settings (#2260).
authorCarl Hetherington <cth@carlh.net>
Fri, 3 Jun 2022 18:07:57 +0000 (20:07 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 3 Jun 2022 20:40:59 +0000 (22:40 +0200)
src/lib/reel_writer.cc
src/lib/util.cc
src/lib/util.h
test/file_naming_test.cc

index 94920b95bce0cd82232e94c9aca0e9275ccf70c1..d64cfb81a4a6b553778fcef43bafa3aa0d7233fc 100644 (file)
@@ -459,6 +459,9 @@ maybe_add_text (
        shared_ptr<dcp::SubtitleAsset> asset,
        int64_t picture_duration,
        shared_ptr<dcp::Reel> reel,
+       int reel_index,
+       int reel_count,
+       optional<string> content_summary,
        list<ReferencedReelAsset> const & refs,
        vector<FontData> const & fonts,
        dcp::ArrayData default_font,
@@ -481,7 +484,7 @@ maybe_add_text (
                if (auto interop = dynamic_pointer_cast<dcp::InteropSubtitleAsset>(asset)) {
                        auto directory = output_dcp / interop->id ();
                        boost::filesystem::create_directories (directory);
-                       interop->write (directory / ("sub_" + interop->id() + ".xml"));
+                       interop->write (directory / subtitle_asset_filename(asset, reel_index, reel_count, content_summary));
                        reel_asset = make_shared<Interop> (
                                interop,
                                dcp::Fraction(film->video_frame_rate(), 1),
@@ -496,7 +499,7 @@ maybe_add_text (
                        */
                        smpte->set_intrinsic_duration(picture_duration);
                        smpte->write (
-                               output_dcp / ("sub_" + asset->id() + ".mxf")
+                               output_dcp / subtitle_asset_filename(asset, reel_index, reel_count, content_summary)
                                );
                        reel_asset = make_shared<SMPTE> (
                                smpte,
@@ -643,7 +646,7 @@ ReelWriter::create_reel_text (
        ) const
 {
        auto subtitle = maybe_add_text<dcp::ReelInteropSubtitleAsset, dcp::ReelSMPTESubtitleAsset, dcp::ReelSubtitleAsset> (
-               _subtitle_asset, duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only
+               _subtitle_asset, duration, reel, _reel_index, _reel_count, _content_summary, refs, fonts, _default_font, film(), _period, output_dcp, _text_only
                );
 
        if (subtitle) {
@@ -657,6 +660,9 @@ ReelWriter::create_reel_text (
                        empty_text_asset(TextType::OPEN_SUBTITLE, optional<DCPTextTrack>(), true),
                        duration,
                        reel,
+                       _reel_index,
+                       _reel_count,
+                       _content_summary,
                        refs,
                        fonts,
                        _default_font,
@@ -669,7 +675,7 @@ ReelWriter::create_reel_text (
 
        for (auto const& i: _closed_caption_assets) {
                auto a = maybe_add_text<dcp::ReelInteropClosedCaptionAsset, dcp::ReelSMPTEClosedCaptionAsset, dcp::ReelClosedCaptionAsset> (
-                       i.second, duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only
+                       i.second, duration, reel, _reel_index, _reel_count, _content_summary, refs, fonts, _default_font, film(), _period, output_dcp, _text_only
                        );
                DCPOMATIC_ASSERT (a);
                a->set_annotation_text (i.first.name);
@@ -683,7 +689,19 @@ ReelWriter::create_reel_text (
        /* Make empty tracks for anything we've been asked to ensure but that we haven't added */
        for (auto i: ensure_closed_captions) {
                auto a = maybe_add_text<dcp::ReelInteropClosedCaptionAsset, dcp::ReelSMPTEClosedCaptionAsset, dcp::ReelClosedCaptionAsset> (
-                       empty_text_asset(TextType::CLOSED_CAPTION, i, true), duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only
+                       empty_text_asset(TextType::CLOSED_CAPTION, i, true),
+                       duration,
+                       reel,
+                       _reel_index,
+                       _reel_count,
+                       _content_summary,
+                       refs,
+                       fonts,
+                       _default_font,
+                       film(),
+                       _period,
+                       output_dcp,
+                       _text_only
                        );
                DCPOMATIC_ASSERT (a);
                a->set_annotation_text (i.name);
index e1eb7323c4363e1ec5aa601c8961172bca4f26be..2c38257b4bafabf1447cc1824956e62da36e953d 100644 (file)
@@ -735,6 +735,13 @@ audio_asset_filename (shared_ptr<dcp::SoundAsset> asset, int reel_index, int ree
 }
 
 
+string
+subtitle_asset_filename (shared_ptr<dcp::SubtitleAsset> asset, int reel_index, int reel_count, optional<string> summary)
+{
+       return asset_filename(asset, "sub", reel_index, reel_count, summary);
+}
+
+
 string
 atmos_asset_filename (shared_ptr<dcp::AtmosAsset> asset, int reel_index, int reel_count, optional<string> summary)
 {
index 233b3cb2a9bc7c698685ad83744ff634782c0968..cd5a1c2c56c2a0fa7c113ce4ad28f3ba5404a1c1 100644 (file)
@@ -49,6 +49,7 @@
 namespace dcp {
        class PictureAsset;
        class SoundAsset;
+       class SubtitleAsset;
 }
 
 /** The maximum number of audio channels that we can have in a DCP */
@@ -107,6 +108,7 @@ extern void set_backtrace_file (boost::filesystem::path);
 extern std::map<std::string, std::string> split_get_request (std::string url);
 extern std::string video_asset_filename (std::shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
 extern std::string audio_asset_filename (std::shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
+extern std::string subtitle_asset_filename (std::shared_ptr<dcp::SubtitleAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
 extern std::string atmos_asset_filename (std::shared_ptr<dcp::AtmosAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
 extern float relaxed_string_to_float (std::string);
 extern std::string careful_string_filter (std::string);
index 0b76952a8a72e61e83a34e8febd32823495cd590..4f6d66fe6da7743f104e0d9f0731bae435c55ac2 100644 (file)
 
 #include "test.h"
 #include "lib/config.h"
-#include "lib/film.h"
-#include "lib/ffmpeg_content.h"
+#include "lib/content_factory.h"
 #include "lib/dcp_content_type.h"
+#include "lib/ffmpeg_content.h"
+#include "lib/film.h"
 #include "lib/video_content.h"
 #ifdef DCPOMATIC_WINDOWS
 #include <boost/locale.hpp>
@@ -38,9 +39,9 @@
 #include <boost/regex.hpp>
 
 
-using std::string;
-using std::shared_ptr;
 using std::make_shared;
+using std::shared_ptr;
+using std::string;
 
 
 class Keep
@@ -170,3 +171,34 @@ BOOST_AUTO_TEST_CASE (file_naming_test2)
                BOOST_CHECK (got[i] == 2);
        }
 }
+
+
+BOOST_AUTO_TEST_CASE (subtitle_file_naming)
+{
+       Keep keep;
+
+       Config::instance()->set_dcp_asset_filename_format(dcp::NameFormat("%t ostrabagalous %c"));
+
+       auto content = content_factory("test/data/15s.srt");
+       auto film = new_test_film2("subtitle_file_naming", { content.front() });
+       film->set_interop(false);
+
+       make_and_verify_dcp (
+               film,
+               {
+                       dcp::VerificationNote::Code::MISSING_CPL_METADATA,
+                       dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
+                       dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
+               });
+
+       int got = 0;
+
+       for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
+               if (boost::regex_match(i.path().filename().string(), boost::regex("sub_ostrabagalous_15s.*\\.mxf"))) {
+                       ++got;
+               }
+       }
+
+       BOOST_CHECK_EQUAL(got, 1);
+}
+