logger.trace("Chose a default audio track: " + params.aid);
}
}
String currentLang = null;
DLNAMediaSubtitle matchedSub = null;
if (params.aid != null) {
currentLang = params.aid.getLang();
}
if (params.sid != null && params.sid.getId() == -1) {
logger.trace("Don't want subtitles!");
params.sid = null;
return;
}
StringTokenizer st1 = new StringTokenizer(configuration.getAudioSubLanguages(), ";");
while (st1.hasMoreTokens()) {
String pair = st1.nextToken();
if (pair.contains(",")) {
String audio = pair.substring(0, pair.indexOf(","));
String sub = pair.substring(pair.indexOf(",") + 1);
audio = audio.trim();
sub = sub.trim();
logger.trace("Searching for a match for: " + currentLang + " with " + audio + " and " + sub);
if (Iso639.isCodesMatching(audio, currentLang) || (currentLang != null && audio.equals("*"))) {
if (sub.equals("off")) {
matchedSub = new DLNAMediaSubtitle();
matchedSub.setLang("off");
} else {
for (DLNAMediaSubtitle present_sub : media.getSubtitleTracksList()) {
if (present_sub.matchCode(sub) || sub.equals("*")) {
matchedSub = present_sub;
logger.trace("Found a match: " + matchedSub);
break;
}
}
}
if (matchedSub != null) {
break;
}
}
}
}
if (matchedSub != null && params.sid == null) {
if (configuration.isDisableSubtitles() || (matchedSub.getLang() != null && matchedSub.getLang().equals("off"))) {
logger.trace(" Disabled the subtitles: " + matchedSub);
} else {
params.sid = matchedSub;
}
}
if (!configuration.isDisableSubtitles() && params.sid == null && media != null) {
// Check for subtitles again
File video = new File(fileName);
FileUtil.isSubtitlesExists(video, media, false);
if (configuration.isAutoloadExternalSubtitles()) {
boolean forcedSubsFound = false;
// Priority to external subtitles
for (DLNAMediaSubtitle sub : media.getSubtitleTracksList()) {
if (matchedSub !=null && matchedSub.getLang() !=null && matchedSub.getLang().equals("off")) {
StringTokenizer st = new StringTokenizer(configuration.getForcedSubtitleTags(), ",");
while (st != null && sub.getFlavor() != null && st.hasMoreTokens()) {
String forcedTags = st.nextToken();
forcedTags = forcedTags.trim();
if (sub.getFlavor().toLowerCase().indexOf(forcedTags) > -1
&& Iso639.isCodesMatching(sub.getLang(), configuration.getForcedSubtitleLanguage())) {
logger.trace("Forcing preferred subtitles : " + sub.getLang() + "/" + sub.getFlavor());
logger.trace("Forced subtitles track : " + sub);
if (sub.getExternalFile() != null) {
logger.trace("Found external forced file : " + sub.getExternalFile().getAbsolutePath());
}
params.sid = sub;
forcedSubsFound = true;
break;
}
}
if (forcedSubsFound == true) {
break;
}
} else {
logger.trace("Found subtitles track: " + sub);
if (sub.getExternalFile() != null) {
logger.trace("Found external file: " + sub.getExternalFile().getAbsolutePath());
params.sid = sub;
break;
}
}
}
}
if (
matchedSub != null &&
matchedSub.getLang() != null &&
matchedSub.getLang().equals("off")
) {
return;
}
if (params.sid == null) {