forked from filebot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artwork.tmdb.groovy
54 lines (41 loc) · 1.28 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
#!/usr/bin/env filebot -script
// sanity checks
if (args.size() == 0) {
die "Illegal usage: no input"
}
include('lib/htpc')
args.eachMediaFolder{ dir ->
// fetch only missing artwork by default
if (dir.hasFile{it.name == 'movie.nfo'} && dir.hasFile{it.name == 'poster.jpg'} && dir.hasFile{it.name == 'fanart.jpg'}) {
log.finest "Skipping $dir"
return
}
def videos = dir.listFiles{ it.isVideo() }
def query = _args.query
def locale = any{ _args.language.locale }{ Locale.ENGLISH }
def options = []
if (query) {
// manual search & sort by relevance
options = TheMovieDB.searchMovie(query, locale).sortBySimilarity(query, { it.name })
} else if (videos.size() > 0) {
// run movie auto-detection for video files
options = MediaDetection.detectMovie(videos[0], TheMovieDB, locale, true)
}
if (options.isEmpty()) {
log.warning "$dir ${videos.name} => movie not found"
return
}
// auto-select movie
def movie = options[0]
// maybe require user input
if (options.size() > 1 && _args.strict) {
movie = showInputDialog(options, dir.name, 'Select Movie')
}
if (movie == null) {
return null
}
log.fine "$dir => $movie"
tryLogCatch {
fetchMovieArtworkAndNfo(dir, movie, dir.getFiles{ it.isVideo() }.sort{ it.length() }.reverse().findResult{ it }, false, locale)
}
}