Skip to content

Commit

Permalink
fix regular expression date matching bug
Browse files Browse the repository at this point in the history
A bug with the matching for dates existed that is now resolved with
updated regex logic.
  • Loading branch information
danb235 committed Dec 31, 2015
1 parent 9728924 commit 7b77407
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/media.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,16 @@ class Media extends Database
)

# if show has date: "Season 2/Show Name - 2014.04.10 - Ep Name.ext"
else if filteredFileName.match(/[1880-2040]{4}\d{4}|\d{4}[1880-2040]{4}/g)
else if filteredFileName.match(/(18\d{2}|19\d{2}|20\d{2})\d{4}/g)
# remove all characters after ####.##.##
seasonAndEpisode = filteredFileName.match(/[1880-2040]{4}\d{4}|\d{4}[1880-2040]{4}/g)[0]
seasonAndEpisode = filteredFileName.match(/(18\d{2}|19\d{2}|20\d{2})\d{4}/g)[0]
regex = new RegExp(seasonAndEpisode + ".*", "gi")
filteredFileName = filteredFileName.replace(regex, seasonAndEpisode)

# if show has date: "Season 2/Show Name - 04.10.2014 - Ep Name.ext"
else if filteredFileName.match(/\d{4}(18\d{2}|19\d{2}|20\d{2})/g)
# remove all characters after ##.##.####
seasonAndEpisode = filteredFileName.match(/\d{4}(18\d{2}|19\d{2}|20\d{2})/g)[0]
regex = new RegExp(seasonAndEpisode + ".*", "gi")
filteredFileName = filteredFileName.replace(regex, seasonAndEpisode)

Expand Down

0 comments on commit 7b77407

Please sign in to comment.