public String getNewFilename() { switch (this.status) { case ADDED: { return ADDED_PLACEHOLDER_FILENAME; } case DOWNLOADED: case RENAMED: { String showName = ""; String seasonNum = ""; String titleString = ""; Calendar airDate = Calendar.getInstance(); ; try { Show show = ShowStore.getShow(this.showName); showName = show.getName(); Season season = show.getSeason(this.seasonNumber); if (season == null) { seasonNum = String.valueOf(this.seasonNumber); logger.log( Level.SEVERE, "Season #" + this.seasonNumber + " not found for show '" + this.showName + "'"); } else { seasonNum = String.valueOf(season.getNumber()); try { titleString = season.getTitle(this.episodeNumber); airDate.setTime(season.getAirDate(this.episodeNumber)); } catch (EpisodeNotFoundException e) { logger.log(Level.SEVERE, "Episode not found for '" + this.toString() + "'", e); } } } catch (ShowNotFoundException e) { showName = this.showName; logger.log(Level.SEVERE, "Show not found for '" + this.toString() + "'", e); } String newFilename = userPrefs.getRenameReplacementString(); // Ensure that all special characters in the replacement are quoted showName = Matcher.quoteReplacement(showName); showName = GlobalOverrides.getInstance().getShowName(showName); titleString = Matcher.quoteReplacement(titleString); // Make whatever modifications are required String episodeNumberString = new DecimalFormat("##0").format(this.episodeNumber); String episodeNumberWithLeadingZeros = new DecimalFormat("#00").format(this.episodeNumber); String episodeTitleNoSpaces = titleString.replaceAll(" ", "."); String seasonNumberWithLeadingZero = new DecimalFormat("00").format(this.seasonNumber); newFilename = newFilename.replaceAll(ReplacementToken.SHOW_NAME.getToken(), showName); newFilename = newFilename.replaceAll(ReplacementToken.SEASON_NUM.getToken(), seasonNum); newFilename = newFilename.replaceAll( ReplacementToken.SEASON_NUM_LEADING_ZERO.getToken(), seasonNumberWithLeadingZero); newFilename = newFilename.replaceAll(ReplacementToken.EPISODE_NUM.getToken(), episodeNumberString); newFilename = newFilename.replaceAll( ReplacementToken.EPISODE_NUM_LEADING_ZERO.getToken(), episodeNumberWithLeadingZeros); newFilename = newFilename.replaceAll(ReplacementToken.EPISODE_TITLE.getToken(), titleString); newFilename = newFilename.replaceAll( ReplacementToken.EPISODE_TITLE_NO_SPACES.getToken(), episodeTitleNoSpaces); // Date and times newFilename = newFilename.replaceAll( ReplacementToken.DATE_DAY_NUM.getToken(), formatDate(airDate, "d")); newFilename = newFilename.replaceAll( ReplacementToken.DATE_DAY_NUMLZ.getToken(), formatDate(airDate, "dd")); newFilename = newFilename.replaceAll( ReplacementToken.DATE_MONTH_NUM.getToken(), formatDate(airDate, "M")); newFilename = newFilename.replaceAll( ReplacementToken.DATE_MONTH_NUMLZ.getToken(), formatDate(airDate, "MM")); newFilename = newFilename.replaceAll( ReplacementToken.DATE_YEAR_FULL.getToken(), formatDate(airDate, "yyyy")); newFilename = newFilename.replaceAll( ReplacementToken.DATE_YEAR_MIN.getToken(), formatDate(airDate, "yy")); String resultingFilename = newFilename.concat(".").concat(StringUtils.getExtension(file.getName())); return StringUtils.sanitiseTitle(resultingFilename); } case BROKEN: default: return BROKEN_PLACEHOLDER_FILENAME; } }