+ auto cpls = dcp::find_and_resolve_cpls (content->directories(), tolerant);
+
+ if (content->cpl ()) {
+ /* Use the CPL that was specified, or that the content was using before */
+ auto iter = std::find_if(cpls.begin(), cpls.end(), [content](shared_ptr<dcp::CPL> cpl) { return cpl->id() == content->cpl().get(); });
+ if (iter == cpls.end()) {
+ throw CPLNotFoundError(content->cpl().get());
+ }
+ cpl = *iter;
+ } else {
+ /* Choose the CPL with the fewest unsatisfied references */
+
+ int least_unsatisfied = INT_MAX;
+
+ for (auto i: cpls) {
+ int unsatisfied = 0;
+ for (auto j: i->reels()) {
+ if (j->main_picture() && !j->main_picture()->asset_ref().resolved()) {
+ ++unsatisfied;
+ }
+ if (j->main_sound() && !j->main_sound()->asset_ref().resolved()) {
+ ++unsatisfied;
+ }
+ if (j->main_subtitle() && !j->main_subtitle()->asset_ref().resolved()) {
+ ++unsatisfied;
+ }
+ if (j->atmos() && !j->atmos()->asset_ref().resolved()) {
+ ++unsatisfied;
+ }
+ }
+
+ if (unsatisfied < least_unsatisfied) {
+ least_unsatisfied = unsatisfied;
+ cpl = i;
+ }
+ }
+ }
+
+ if (!cpl) {