continue;
}
_logManager.debug(String.format("%s: Found %s SubTitles on %s", movieFileVO.getFileName(), listaSubTitle.size(), downloadHandler.getDescription()));
// Escolhe a melhor legenda nesse handler
SubTitleVO chosenSubTitle = downloadHandler.chooseOneSubTitle(movieFileVO, listaSubTitle);
_logManager.debug(String.format("%s: Downloading %s...", movieFileVO.getFileName(), chosenSubTitle.getFileName()));
InputStream subTitleStream = null;
try {
subTitleStream = downloadHandler.getSubTitleFile(chosenSubTitle);
} catch (Exception e) {
_logManager.fatal(String.format("%s: Error downloading subtitle %s from %s: %s",
movieFileVO.getFileName(), chosenSubTitle.getFileName(), downloadHandler.getDescription(), e.getMessage()), e);
_listaVideoError.put(movieFileVO, e);
}
if (subTitleStream != null) {
String subtitleFileName = FileUtils.changeExtension(movieFileVO.getFileName(), FileUtils.getExtension(chosenSubTitle.getFileName()));
if (_configManager.getUseLanguageOnSubtitle()) {
String newExtension = SubTitleLanguage.getCodeISO639_2(_configManager.getLanguageOnSubtitle()) + "." +
FileUtils.getExtension(chosenSubTitle.getFileName());
subtitleFileName = FileUtils.changeExtension(subtitleFileName, newExtension);
}
File file = new File(movieFileVO.getPathDir(), subtitleFileName);
try {
FileOutputStream stream = new FileOutputStream(file);
StreamUtils.copyThenClose(subTitleStream, stream);
} catch (IOException ex) {
String message = "Error writing subtitle file: " + ex.getMessage();
_logManager.fatal(message, ex);
throw new RuntimeException(message, ex);
}
chosenSubTitle.setFileName(subtitleFileName);
_logManager.debug(String.format("%s: Subtitle file %s saved on %s", movieFileVO.getFileName(), subtitleFileName, movieFileVO.getPathDir()));
_listaVideoSaved.add(movieFileVO);
movieFileVO.setSubTitleVO(chosenSubTitle);