1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-25 17:28:51 -05:00
filebot/build-data/Discover.groovy

39 lines
984 B
Groovy
Raw Normal View History

2016-07-19 07:55:48 -04:00
#!/usr/bin/env filebot -script
def recentMoviesFile = new File('recent-movies.txt')
2016-07-19 14:23:43 -04:00
def recentMoviesIndex = new TreeMap()
if (recentMoviesFile.exists()) {
recentMoviesFile.splitEachLine('\t', 'UTF-8') { line ->
recentMoviesIndex.put(line[0] as int, line)
}
}
2016-07-19 07:55:48 -04:00
2016-07-20 03:45:26 -04:00
def updateMovieIndex = { m ->
2016-07-19 14:23:43 -04:00
if (!recentMoviesIndex.containsKey(m.tmdbId)) {
2016-07-20 03:45:26 -04:00
def i = TheMovieDB.getMovieInfo(m, Locale.ENGLISH, false)
2016-07-19 14:23:43 -04:00
if (i.imdbId == null)
return
def row = [i.id.pad(6), i.imdbId.pad(7), i.released.year as String, i.name]
2016-07-20 03:45:26 -04:00
log.finest "$row"
2016-07-19 07:55:48 -04:00
2016-07-19 14:23:43 -04:00
recentMoviesIndex.put(row[0] as int, row)
2016-07-19 07:55:48 -04:00
}
}
2016-07-20 03:45:26 -04: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 14:23:43 -04:00
recentMoviesIndex.values()*.join('\t').join('\n').saveAs(recentMoviesFile)