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;
	}
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) {
		
			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;
			}
		}
	
		if (!subtitleFiles.isEmpty()) {
			return true;
		}
		return false;
	}
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) { 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; } } if (!subtitlefiles.isempty()) { return true; } return false; }