Look for subtitle assets more sensibly.
[libdcp.git] / src / dcp.cc
index 767ab401c8e62f250fef76a44702b36b42947c49..aa937de52d095d712a0376279cea63a6706fa8e3 100644 (file)
@@ -278,17 +278,17 @@ DCP::DCP (string directory)
                _fps = p->frame_rate.numerator;
                _length += p->duration;
 
-               string n = pkl->asset_from_id (p->id)->original_file_name;
-               if (n.empty ()) {
-                       n = p->annotation_text;
-               }
-               
                shared_ptr<PictureAsset> picture;
                shared_ptr<SoundAsset> sound;
                shared_ptr<SubtitleAsset> subtitle;
                
                if ((*i)->asset_list->main_picture) {
 
+                       string n = pkl->asset_from_id (p->id)->original_file_name;
+                       if (n.empty ()) {
+                               n = p->annotation_text;
+                       }
+               
                        picture.reset (new MonoPictureAsset (
                                               _directory,
                                               n,
@@ -299,6 +299,11 @@ DCP::DCP (string directory)
                        
                } else if ((*i)->asset_list->main_stereoscopic_picture) {
                        
+                       string n = pkl->asset_from_id (p->id)->original_file_name;
+                       if (n.empty ()) {
+                               n = p->annotation_text;
+                       }
+                       
                        picture.reset (new StereoPictureAsset (
                                               _directory,
                                               n,
@@ -311,7 +316,7 @@ DCP::DCP (string directory)
                
                if ((*i)->asset_list->main_sound) {
                        
-                       n = pkl->asset_from_id ((*i)->asset_list->main_sound->id)->original_file_name;
+                       string n = pkl->asset_from_id ((*i)->asset_list->main_sound->id)->original_file_name;
                        if (n.empty ()) {
                                n = (*i)->asset_list->main_sound->annotation_text;
                        }
@@ -325,13 +330,20 @@ DCP::DCP (string directory)
                                );
                }
 
-               assert (files.subtitles.size() < 2);
+               if ((*i)->asset_list->main_subtitle) {
 
-               if (!files.subtitles.empty ()) {
-                       string const l = files.subtitles.front().substr (_directory.length ());
-                       subtitle.reset (new SubtitleAsset (_directory, l));
+                       string n = pkl->asset_from_id ((*i)->asset_list->main_subtitle->id)->original_file_name;
+                       if (n.empty ()) {
+                               n = (*i)->asset_list->main_subtitle->annotation_text;
+                       }
+                       
+                       subtitle.reset (new SubtitleAsset (
+                                            _directory,
+                                            n
+                                            )
+                               );
                }
-
+                       
                _reels.push_back (shared_ptr<Reel> (new Reel (picture, sound, subtitle)));
        }
 }