Skip to content

Commit 80f5a2f

Browse files
authored
Merge pull request #981 from jas14/jas14/multiple-movie-regexes
Add support for multiple movie regexes
2 parents c8bc877 + f3ae861 commit 80f5a2f

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

grails-app/services/streama/BulkCreateService.groovy

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import grails.transaction.NotTransactional
44
import grails.transaction.Transactional
55

66
import java.util.regex.Matcher
7+
import java.util.regex.Pattern
78

89
@Transactional
910
class BulkCreateService {
@@ -35,20 +36,21 @@ class BulkCreateService {
3536

3637

3738
def movieRegex = regexConfig?.movies ?: STD_MOVIE_REGEX
39+
def movieRegexList = movieRegex instanceof List ? movieRegex : [movieRegex]
3840
def tvShowRegex = regexConfig?.shows ?: STD_TVSHOW_REGEX
3941
def tvShowRegexList = tvShowRegex instanceof List ? tvShowRegex : [tvShowRegex]
4042

4143
def result = []
4244

4345
files.each { file ->
44-
def fileResult = matchSingleFile(file, movieRegex, tvShowRegexList)
46+
def fileResult = matchSingleFile(file, movieRegexList, tvShowRegexList)
4547
result.add(fileResult)
4648
}
4749

4850
return result
4951
}
5052

51-
private matchSingleFile(file, movieRegex, List tvShowRegexList) {
53+
private matchSingleFile(file, List<Pattern> movieRegexList, List<Pattern> tvShowRegexList) {
5254
def fileResult = [file: file.path]
5355
def foundMatch = false
5456

@@ -67,12 +69,19 @@ class BulkCreateService {
6769
return fileResult
6870
}
6971

70-
def movieMatcher = fileName =~ '(?i)' + movieRegex
71-
if (movieMatcher.matches()) {
72-
matchMovieFromFile(movieMatcher, fileResult, movieRegex)
73-
foundMatch = true
74-
return fileResult
75-
}
72+
foundMatch = movieRegexList.any { movieRegex ->
73+
def movieMatcher = fileName =~ '(?i)' + movieRegex
74+
75+
if (movieMatcher.matches()) {
76+
matchMovieFromFile(movieMatcher, fileResult, movieRegex)
77+
return true
78+
return fileResult
79+
}
80+
}
81+
82+
if (foundMatch) {
83+
return fileResult
84+
}
7685

7786
fileResult.status = MATCHER_STATUS.NO_MATCH
7887
fileResult.message = 'No match found'

0 commit comments

Comments
 (0)