// FIXME : this last test will accept any subtitle file without checking the language
public static boolean isAlreadySubtitled( Downloadable videoDownloadable, Language subtitlesLanguage ) throws IOException, InterruptedException {
		List<DownloadableFile> allFiles = DownloadableManager.getInstance().getAllFiles( videoDownloadable.getId() );
		Path mainVideoFilePath;
		String filename;
		Optional<Path> optPath = selectMainVideoFile( allFiles );
		if (optPath.isPresent()) {
			mainVideoFilePath = optPath.get();
			filename = mainVideoFilePath.getFileName().toString();
		} else {
			ErrorManager.getInstance().reportError(String.format("No video file found for %s", videoDownloadable.toString()));
			return false;
		}
		if (subtitlesLanguage == null) {
			return true;
		}
		if (subtitlesLanguage.getSubTokens() != null) {
			// Test if the filename contains an indication of the subtitles (VOSTFR, ...)
			for (String subToken : subtitlesLanguage.getSubTokens()) {
				if ( StringUtils.containsIgnoreCase( filename, subToken) ) {
					return true;
				}
			}
		}
		VideoMetaData metaData = getInstance().getMetaData(videoDownloadable, mainVideoFilePath);
		if (metaData.getSubtitleLanguages() != null) {
			for (Locale locale : metaData.getSubtitleLanguages()) {
				if (locale.getLanguage().equals( subtitlesLanguage.getLocale().getLanguage() )) {
					return true;
				}
			}
		}
		List<DownloadableFile> subtitleFiles =
				allFiles.stream()
				.filter( file -> SubtitlesFileFilter.getInstance().accept( file.getFilePath() ) )
				.collect( Collectors.toList() );
		String filenameWithoutExtension = filename; 
		if ( filenameWithoutExtension.lastIndexOf('.') > 0 ) {
			filenameWithoutExtension = filenameWithoutExtension.substring( 0, filenameWithoutExtension.lastIndexOf('.'));
		}
		String targetFileNameRegExp = filenameWithoutExtension + "." + subtitlesLanguage.getShortName() + "\\.srt";
		for (DownloadableFile subTitleFile : subtitleFiles) {
			String subtitleFileName = subTitleFile.getFilePath().getFileName().toString();
			if (RegExp.matches(subtitleFileName, targetFileNameRegExp )) {
				return true;
			}
		}
		// FIXME : this last test will accept any subtitle file without checking the language
		if (!subtitleFiles.isEmpty()) {
			return true;
		}
		return false;
	}
}
}
// FIXME : this last test will accept any subtitle file without checking the language
if (!subtitleFiles.isEmpty()) {
return true;
if ( filenameWithoutExtension.lastIndexOf('.') > 0 ) {
filenameWithoutExtension = filenameWithoutExtension.substring( 0, filenameWithoutExtension.lastIndexOf('.'));
}
String targetFileNameRegExp = filenameWithoutExtension + "." + subtitlesLanguage.getShortName() + "\\.srt";
for (DownloadableFile subTitleFile : subtitleFiles) {
String subtitleFileName = subTitleFile.getFilePath().getFileName().toString();
if (RegExp.matches(subtitleFileName, targetFileNameRegExp )) {
return true;
}
}
// FIXME : this last test will accept any subtitle file without checking the language
if (!subtitleFiles.isEmpty()) {
return true;
}
return false;
}
if (locale.getLanguage().equals( subtitlesLanguage.getLocale().getLanguage() )) {
return true;
}
}
}
List<DownloadableFile> subtitleFiles =
allFiles.stream()
.filter( file -> SubtitlesFileFilter.getInstance().accept( file.getFilePath() ) )
.collect( Collectors.toList() );
String filenameWithoutExtension = filename;
if ( filenameWithoutExtension.lastIndexOf('.') > 0 ) {
filenameWithoutExtension = filenameWithoutExtension.substring( 0, filenameWithoutExtension.lastIndexOf('.'));
}
String targetFileNameRegExp = filenameWithoutExtension + "." + subtitlesLanguage.getShortName() + "\\.srt";
for (DownloadableFile subTitleFile : subtitleFiles) {
String subtitleFileName = subTitleFile.getFilePath().getFileName().toString();
if (RegExp.matches(subtitleFileName, targetFileNameRegExp )) {
return true;
}
}
// FIXME : this last test will accept any subtitle file without checking the language
if (!subtitleFiles.isEmpty()) {
return true;
}
return false;
}