Skip to content

Commit ee0dee0

Browse files
author
dularion
committed
add year handling for movies during bulkCreate
so that "Aladdin.1992.mp4" actually matches the old aladdin and not the 2019 one.
1 parent 943d651 commit ee0dee0

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

grails-app/conf/application.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ grails:
152152

153153
streama:
154154
regex:
155-
movies: ^(?<Name>.*)?[._ \(]+\d{4}.*
155+
movies: ^(?<Name>.*)?[._ \(]+(?<Year>\d{4}).*
156156
shows:
157157
- ^(?<Name>.+)[._ ][Ss](?<Season>\d{2})[Ee](?<Episode>\d{2,3}).* # example: "House.MD.S03E04.h264.mp4"
158158
- ^(?<Name>.+)[._ ](?<Season>\d{1,2})x(?<Episode>\d{2,3}).* # example: "House.MD.03x04.h264.mp4"

grails-app/services/streama/BulkCreateService.groovy

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class BulkCreateService {
6767

6868
def movieMatcher = fileName =~ '(?i)' + movieRegex
6969
if (movieMatcher.matches()) {
70-
matchMovieFromFile(movieMatcher, fileResult)
70+
matchMovieFromFile(movieMatcher, fileResult, movieRegex)
7171
foundMatch = true
7272
return fileResult
7373
}
@@ -78,12 +78,13 @@ class BulkCreateService {
7878
}
7979

8080

81-
private void matchMovieFromFile(Matcher movieMatcher, LinkedHashMap<String, Object> fileResult) {
81+
private void matchMovieFromFile(Matcher movieMatcher, LinkedHashMap<String, Object> fileResult, movieRegex) {
8282
def name = movieMatcher.group('Name').replaceAll(/[._]/, " ")
83+
def year = movieRegex.contains('<Year>') ? movieMatcher.group('Year') : null
8384
def type = "movie"
8485

8586
try {
86-
def json = theMovieDbService.searchForEntry(type, name)
87+
def json = theMovieDbService.searchForEntry(type, name, year)
8788
def movieDbResults = json?.results
8889

8990
if (movieDbResults) {

grails-app/services/streama/TheMovieDbService.groovy

+5-2
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ class TheMovieDbService {
137137
return new JsonSlurper().parseText(JsonContent)
138138
}
139139

140-
def searchForEntry(type, name) {
140+
def searchForEntry(type, name, String year = null) {
141141

142142
def cachedApiData = apiCacheData."$type:$name"
143-
if(cachedApiData){
143+
if(false && cachedApiData){
144144
return cachedApiData
145145
}
146146
def query = URLEncoder.encode(name, "UTF-8")
@@ -155,6 +155,9 @@ class TheMovieDbService {
155155
}
156156
def JsonContent = url.getText("UTF-8")
157157
def data = new JsonSlurper().parseText(JsonContent)
158+
if(data.results?.size() > 1 && year){
159+
data.results = data.results.findAll{it.release_date.take(4) == year}
160+
}
158161
apiCacheData["$type:$name"] = data
159162

160163
return data

0 commit comments

Comments
 (0)