Skip to content

Commit

Permalink
Merge pull request #981 from jas14/jas14/multiple-movie-regexes
Browse files Browse the repository at this point in the history
Add support for multiple movie regexes
  • Loading branch information
dularion committed May 13, 2020
2 parents c8bc877 + f3ae861 commit 80f5a2f
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions grails-app/services/streama/BulkCreateService.groovy
Expand Up @@ -4,6 +4,7 @@ import grails.transaction.NotTransactional
import grails.transaction.Transactional

import java.util.regex.Matcher
import java.util.regex.Pattern

@Transactional
class BulkCreateService {
Expand Down Expand Up @@ -35,20 +36,21 @@ class BulkCreateService {


def movieRegex = regexConfig?.movies ?: STD_MOVIE_REGEX
def movieRegexList = movieRegex instanceof List ? movieRegex : [movieRegex]
def tvShowRegex = regexConfig?.shows ?: STD_TVSHOW_REGEX
def tvShowRegexList = tvShowRegex instanceof List ? tvShowRegex : [tvShowRegex]

def result = []

files.each { file ->
def fileResult = matchSingleFile(file, movieRegex, tvShowRegexList)
def fileResult = matchSingleFile(file, movieRegexList, tvShowRegexList)
result.add(fileResult)
}

return result
}

private matchSingleFile(file, movieRegex, List tvShowRegexList) {
private matchSingleFile(file, List<Pattern> movieRegexList, List<Pattern> tvShowRegexList) {
def fileResult = [file: file.path]
def foundMatch = false

Expand All @@ -67,12 +69,19 @@ class BulkCreateService {
return fileResult
}

def movieMatcher = fileName =~ '(?i)' + movieRegex
if (movieMatcher.matches()) {
matchMovieFromFile(movieMatcher, fileResult, movieRegex)
foundMatch = true
return fileResult
}
foundMatch = movieRegexList.any { movieRegex ->
def movieMatcher = fileName =~ '(?i)' + movieRegex

if (movieMatcher.matches()) {
matchMovieFromFile(movieMatcher, fileResult, movieRegex)
return true
return fileResult
}
}

if (foundMatch) {
return fileResult
}

fileResult.status = MATCHER_STATUS.NO_MATCH
fileResult.message = 'No match found'
Expand Down

0 comments on commit 80f5a2f

Please sign in to comment.