- private static Episode extractEpisode(TorrentFile torrentFile) {
- Matcher matcher = episodePattern.matcher(torrentFile.name());
- if (!matcher.find()) {
- return null;
- }
- String seasonString = matcher.group(1);
- String episodeString = matcher.group(2);
- if ((seasonString == null) && (episodeString == null)) {
- seasonString = matcher.group(3);
- episodeString = matcher.group(4);
+ private static Optional<Episode> extractEpisode(TorrentFile torrentFile) {
+ logger.debug(String.format("Extracting episode from %s...", torrentFile));
+ for (Pattern episodePattern : episodePatterns) {
+ Matcher matcher = episodePattern.matcher(torrentFile.name());
+ if (!matcher.find() || matcher.groupCount() < 2) {
+ continue;
+ }
+ String seasonString = matcher.group(1);
+ String episodeString = matcher.group(2);
+ logger.debug(String.format("Parsing %s and %s as season and episode...", seasonString, episodeString));
+ int season = Integer.valueOf(seasonString);
+ int episode = Integer.valueOf(episodeString);
+ return Optional.of(new Episode(season, episode));