Discover recent/popular movies

This commit is contained in:
Reinhard Pointner 2016-07-20 02:23:43 +08:00
parent 002740d551
commit d79e4bba1d
2 changed files with 24 additions and 9 deletions

View File

@ -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)

View File

@ -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)