diff --git a/build-data/BuildData.groovy b/build-data/BuildData.groovy index 006b2d85..7e6d264e 100755 --- a/build-data/BuildData.groovy +++ b/build-data/BuildData.groovy @@ -184,7 +184,7 @@ omdb.each{ m -> } tmdb*.join('\t').join('\n').saveAs(tmdb_txt) -movies = tmdb.findResults{ +def movies = tmdb.findResults{ def ity = it[1..3] // imdb id, tmdb id, year def names = getNamePermutations(it[4..-1]).findAll{ isValidMovieName(it) } if (ity[0].toInteger() > 0 && ity[1].toInteger() > 0 && names.size() > 0) diff --git a/build-data/Discover.groovy b/build-data/Discover.groovy index f045fc07..8cb7d6d3 100755 --- a/build-data/Discover.groovy +++ b/build-data/Discover.groovy @@ -1,15 +1,30 @@ #!/usr/bin/env filebot -script def recentMoviesFile = new File('recent-movies.txt') -def recentMoviesIndex = (recentMoviesFile.exists() ? recentMoviesFile.readLines('UTF-8') : []) as TreeSet +def recentMoviesIndex = new TreeMap() -def toDate = LocalDate.now() -def fromDate = LocalDate.now().minus(Period.ofDays(30)) - -TheMovieDB.discover(fromDate, toDate, Locale.ENGLISH).each{ m -> - if (recentMoviesIndex.add([m.tmdbId.pad(6), m.year, m.name].join('\t'))) { - println m +if (recentMoviesFile.exists()) { + recentMoviesFile.splitEachLine('\t', 'UTF-8') { line -> + recentMoviesIndex.put(line[0] as int, line) } } -recentMoviesIndex.join('\n').saveAs(recentMoviesFile) +def toDate = LocalDate.now() +def fromDate = LocalDate.now().minus(Period.ofDays(30)) +def locale = Locale.ENGLISH + +TheMovieDB.discover(fromDate, toDate, locale).each{ m -> + if (!recentMoviesIndex.containsKey(m.tmdbId)) { + def i = TheMovieDB.getMovieInfo(m, locale, false) + + if (i.imdbId == null) + return + + def row = [i.id.pad(6), i.imdbId.pad(7), i.released.year as String, i.name] + println row + + recentMoviesIndex.put(row[0] as int, row) + } +} + +recentMoviesIndex.values()*.join('\t').join('\n').saveAs(recentMoviesFile)