filebot/build-data/Discover.groovy

39 lines
997 B
Groovy
Raw Normal View History

2016-07-19 11:55:48 +00:00
#!/usr/bin/env filebot -script
def recentMoviesFile = new File('recent-movies.txt')
2016-07-19 18:23:43 +00:00
def recentMoviesIndex = new TreeMap()
if (recentMoviesFile.exists()) {
recentMoviesFile.splitEachLine('\t', 'UTF-8') { line ->
recentMoviesIndex.put(line[0] as int, line)
}
}
2016-07-19 11:55:48 +00:00
2016-07-20 07:45:26 +00:00
def updateMovieIndex = { m ->
2016-07-19 18:23:43 +00:00
if (!recentMoviesIndex.containsKey(m.tmdbId)) {
2016-07-20 07:45:26 +00:00
def i = TheMovieDB.getMovieInfo(m, Locale.ENGLISH, false)
2016-07-19 18:23:43 +00:00
if (i == null || i.imdbId == null)
2016-07-19 18:23:43 +00:00
return
def row = [i.id.pad(6), i.imdbId.pad(7), i.released.year as String, i.name]
2016-07-20 07:45:26 +00:00
log.finest "$row"
2016-07-19 11:55:48 +00:00
2016-07-19 18:23:43 +00:00
recentMoviesIndex.put(row[0] as int, row)
2016-07-19 11:55:48 +00:00
}
}
2016-07-20 07:45:26 +00:00
def to = LocalDate.now()
def from = to.minus(Period.ofDays(30))
def year = from.year
log.fine "Discover Recent [$from to $to]"
TheMovieDB.discover(from, to, Locale.ENGLISH).each{ updateMovieIndex(it) }
log.fine "Discover Best of Year [$year]"
TheMovieDB.discover(year, Locale.ENGLISH).each{ updateMovieIndex(it) }
2016-07-19 18:23:43 +00:00
recentMoviesIndex.values()*.join('\t').join('\n').saveAs(recentMoviesFile)