Skip to content

Commit

Permalink
consistent subtitles between playutils tile and videoinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
courville committed May 9, 2024
1 parent a44a851 commit aa4f740
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,23 +507,31 @@ public static String getLanguage3(String basename) {
}
}

private static final String SEP = "[\\p{Punct}\\s]++";
// exclude parenthesis and brackets not to match mx (HI) in Rebel.Moon.-.Part.Two.The.Scargiver.2024.1080p.WEBRip.x265.10bit.AAC5.1-[YTS.MX].SDH.eng.HI.srt
private static final String SEP = "[\\p{Punct}&&[^\\[\\]()\\s]]++";
private static final String COUNTRYCODE = "[a-zA-Z]{2,3}";
private static final String HI = "(HI|SDH)";

public static String convertYTSSubNamingExceptions(String name) {
return switch (name.toLowerCase()) {
case "simplified.chi" -> "s_chinese_simplified";
case "traditional.chi" -> "s_traditional_chinese";
case "brazilian.por" -> "s_brazilian";
case "latin american.spa" -> "s_spanish_la";
case "english" -> "eng";
default -> name;
};
String lowercaseName = name.toLowerCase();
if (lowercaseName.endsWith("simplified.chi")) {
return "s_chinese_simplified";
} else if (lowercaseName.endsWith("traditional.chi")) {
return "s_traditional_chinese";
} else if (lowercaseName.endsWith("brazilian.por")) {
return "s_brazilian";
} else if (lowercaseName.endsWith("latin american.spa")) {
return "s_spanish_la";
} else if (lowercaseName.endsWith("english")) {
return "eng";
} else {
return name;
}
}

public static String getSubLanguageFromSubPath(Context context, String path) {
String subFilenameWithoutExtension = stripExtensionFromName(getName(path));
log.debug("getSubLanguageFromSubPath: " + path + " -> " + subFilenameWithoutExtension);
if (subFilenameWithoutExtension == null) return path;
// get 2 or 3 letter code for language
String lang = convertYTSSubNamingExceptions(subFilenameWithoutExtension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
import static com.archos.mediacenter.utils.ISO639codes.isLanguageInString;
import static com.archos.mediacenter.video.browser.subtitlesmanager.ISO639codes.replaceLanguageCodeInString;
import static com.archos.mediacenter.video.browser.subtitlesmanager.SubtitleManager.getLanguage3;
import static com.archos.mediacenter.video.browser.subtitlesmanager.SubtitleManager.getSubLanguageFromSubPath;
import static com.archos.mediacenter.video.utils.MiscUtils.isEmulator;
import static com.archos.mediacenter.video.utils.VideoPreferencesCommon.DEFAULT_MAX_IFRAME_SIZE;
import static com.archos.mediacenter.video.utils.VideoPreferencesCommon.DEFAULT_STREAM_BUFFER_SIZE;
Expand Down Expand Up @@ -3611,22 +3612,40 @@ public void onSubtitleMetadataUpdated(VideoMetadata vMetadata, int newSubtitleTr
for (int i = 0; i < nbTrack; ++i) {
// name comes from IMediaPlayer (avos) and if not internal it says SRT thus if name="SRT" infer the name from path
// infer language from path if path is provided
// FIXME: vMetadata.getSubtitleTrack(i).name sometimes is "hi" but bad parsing from filename because not Hindi but hearing impaired. Cannot locate where it has been set :-( to fix at source
// hint: probably it is part of privatePrefetchSub that triggers a scraping that puts info in MediaDb
if (vMetadata.getSubtitleTrack(i).name != null && (vMetadata.getSubtitleTrack(i).name.equals("SRT") || vMetadata.getSubtitleTrack(i).name.equals("hi") || vMetadata.getSubtitleTrack(i).name.isEmpty()) && vMetadata.getSubtitleTrack(i).path != null) {
String subFilenameWithoutExtension = stripExtensionFromName(getName(vMetadata.getSubtitleTrack(i).path));
lang = getLanguage3(subFilenameWithoutExtension);
log.debug("onSubtitleMetadataUpdated: name={}, path={}, isExternal={} -> subFilenameWithoutExtension={} -> lang={}", vMetadata.getSubtitleTrack(i).name, vMetadata.getSubtitleTrack(i).path, vMetadata.getSubtitleTrack(i).isExternal, subFilenameWithoutExtension, lang);
lang = getSubLanguageFromSubPath(mContext, getName(vMetadata.getSubtitleTrack(i).path));
log.debug("onSubtitleMetadataUpdated: name={}, path={}, isExternal={}, langFromPath={}", vMetadata.getSubtitleTrack(i).name, vMetadata.getSubtitleTrack(i).path, vMetadata.getSubtitleTrack(i).isExternal, lang);
if (vMetadata.getSubtitleTrack(i).name == null || vMetadata.getSubtitleTrack(i).name.isEmpty()) {
if (lang != null) {
// add hearing impaired indication if present
if (vMetadata.getSubtitleTrack(i).name.equals("hi") && !lang.equals("hi")) {
mSubtitleInfoController.addTrack(replaceLanguageCodeInString(mContext, lang) + " (HI)");
} else
mSubtitleInfoController.addTrack(replaceLanguageCodeInString(mContext, lang));
} else mSubtitleInfoController.addTrack(replaceLanguageCodeInString(mContext, vMetadata.getSubtitleTrack(i).name));
} else {
log.debug("onSubtitleMetadataUpdated: no path, path={}, isExternal={} -> name={}", vMetadata.getSubtitleTrack(i).path, vMetadata.getSubtitleTrack(i).isExternal, replaceLanguageCodeInString(mContext, vMetadata.getSubtitleTrack(i).name));
mSubtitleInfoController.addTrack(replaceLanguageCodeInString(mContext, vMetadata.getSubtitleTrack(i).name));
log.debug("onSubtitleMetadataUpdated: name is null set track name to lang=" + lang);
mSubtitleInfoController.addTrack(lang);
} else {
log.debug("onSubtitleMetadataUpdated: name and lang are null, set track name to unknown");
mSubtitleInfoController.addTrack(getText(R.string.unknown_track_name));
}
} else { // name is not null
if (vMetadata.getSubtitleTrack(i).name.equals("SRT") || vMetadata.getSubtitleTrack(i).name.equals("hi")) {
// name is not meaningful, use path
if (lang != null) {
log.debug("onSubtitleMetadataUpdated: set track name to lang=" + lang);
mSubtitleInfoController.addTrack(lang);
} else {
log.debug("onSubtitleMetadataUpdated: lang is null, set track name to name=" + vMetadata.getSubtitleTrack(i).name);
mSubtitleInfoController.addTrack(replaceLanguageCodeInString(mContext, vMetadata.getSubtitleTrack(i).name));
}
} else { // name can be meaningful add it only if not external
if (lang != null) {
if (vMetadata.getSubtitleTrack(i).isExternal) {
log.debug("onSubtitleMetadataUpdated: ext sub set track name to lang=" + lang);
mSubtitleInfoController.addTrack(lang);
} else {
log.debug("onSubtitleMetadataUpdated: int sub set track name to name+lang=" + vMetadata.getSubtitleTrack(i).name + " " + lang);
mSubtitleInfoController.addTrack(replaceLanguageCodeInString(mContext, vMetadata.getSubtitleTrack(i).name) + " " + lang);
}
} else {
log.debug("onSubtitleMetadataUpdated: lang is null, set track name to name=" + vMetadata.getSubtitleTrack(i).name);
mSubtitleInfoController.addTrack(replaceLanguageCodeInString(mContext, vMetadata.getSubtitleTrack(i).name));
}
}
}
}

Expand Down

0 comments on commit aa4f740

Please sign in to comment.