+ if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
+ return ii;
+ }
+ }
+ return -2;
+}
+
+gint
+ghb_find_subtitle_track(
+ gint titleindex,
+ const gchar * lang,
+ gboolean burn,
+ gboolean force,
+ gint source,
+ GHashTable * track_indices)
+{
+ hb_list_t * list;
+ hb_title_t * title;
+ hb_subtitle_t * subtitle;
+ gint count, ii;
+ gboolean *used;
+
+ g_debug("find_subtitle_track ()\n");
+ if (strcmp(lang, "auto") == 0)
+ return -1;
+ if (h_scan == NULL) return -1;
+ list = hb_get_titles( h_scan );
+ title = (hb_title_t*)hb_list_item( list, titleindex );
+ if (title != NULL)
+ {
+ count = hb_list_count( title->list_subtitle );
+ used = g_hash_table_lookup(track_indices, lang);
+ if (used == NULL)
+ {
+ used = g_malloc0(count * sizeof(gboolean));
+ g_hash_table_insert(track_indices, g_strdup(lang), used);
+ }
+ // Try to find an item that matches the preferred language and source
+ for (ii = 0; ii < count; ii++)
+ {
+ if (used[ii])
+ continue;
+
+ subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
+ if (source == subtitle->source &&
+ ((strcmp(lang, subtitle->iso639_2) == 0) ||
+ (strcmp(lang, "und") == 0)))
+ {
+ used[ii] = TRUE;
+ return ii;
+ }
+ }
+ // Try to find an item that matches the preferred language
+ for (ii = 0; ii < count; ii++)
+ {
+ if (used[ii])
+ continue;
+
+ subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
+ if ((!(burn || force) || (subtitle->source == VOBSUB)) &&
+ ((strcmp(lang, subtitle->iso639_2) == 0) ||
+ (strcmp(lang, "und") == 0)))
+ {
+ used[ii] = TRUE;