forked from filebot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artwork.tmdb.groovy
54 lines (43 loc) · 1.48 KB
/
artwork.tmdb.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Fetch movie artwork. The movie is determined using the parent folders name.
*
* Usage: filebot -script fn:artwork.tmdb /path/to/movies/
*/
def override = _args.conflict == 'override'
include('lib/htpc')
args.eachMediaFolder{ dir ->
// fetch only missing artwork by default
if (!override && dir.hasFile{it.name == 'movie.nfo'} && dir.hasFile{it.name == 'poster.jpg'} && dir.hasFile{it.name == 'fanart.jpg'}) {
println "Skipping $dir"
return
}
def videos = dir.listFiles{ it.isVideo() }
def query = _args.query
def options = []
if (query) {
// manual search
options = TheMovieDB.searchMovie(query, _args.locale)
// sort by relevance
options = options.sortBySimilarity(query, { it.name })
} else {
// auto-detection
options = MediaDetection.detectMovie(videos[0], null, TheMovieDB, _args.locale, true)
}
if (options.isEmpty()) {
println "Movie not found: $query"
return
}
// auto-select movie
def movie = options[0]
// maybe require user input
if (options.size() != 1 && !_args.nonStrict && !java.awt.GraphicsEnvironment.headless) {
movie = javax.swing.JOptionPane.showInputDialog(null, 'Please select Movie:', dir.path, 3, null, options.toArray(), movie)
if (movie == null) return null
}
println "$dir => $movie"
try {
fetchMovieArtworkAndNfo(dir, movie, dir.getFiles{ it.isVideo() }.sort{ it.length() }.reverse().findResult{ it }, true, override, _args.locale ?: Locale.ENGLISH)
} catch(e) {
println "${e.class.simpleName}: ${e.message}"
}
}