-
Notifications
You must be signed in to change notification settings - Fork 138
/
artwork.tvdb.groovy
executable file
·68 lines (52 loc) · 1.6 KB
/
artwork.tvdb.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env -S filebot -script
// require at least 1 input folder
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 == 'poster.jpg' }) {
log.finest "Skip [$dir] because [poster.jpg] already exists"
return
}
def videos = dir.listFiles{ it.isVideo() }
def sxe = videos.findResult{ parseEpisodeNumber(it) }
def locale = _args.language.locale
// use --q option value
def query = _args.query
// use series detection
if (!query) {
def s = detectSeries(videos)
if (s) {
query = (s.getExternalId('TheTVDB') as String) ?: s.name
}
}
// use series folder name
if (!query) {
query = dir.dir.hasFile{ it.name =~ /Season/ && it.isDirectory() } ? dir.dir.name : dir.name
}
log.finest "$dir => Lookup by $query"
def options = TheTVDB.lookup(query, locale)
if (options.isEmpty()) {
log.warning "TV Series not found: $query"
return
}
// sort by relevance
options = options.sortBySimilarity(query){ it.name }
// auto-select series
def id = options.first()
// maybe require user input
if (options.size() > 1 && _args.strict) {
id = showInputDialog(options, query, 'Select TV Series')
}
if (id == null) {
return null
}
// auto-detect structure
def seriesInfo = TheTVDB.getSeriesInfo(id, locale)
def seriesDir = [dir.dir, dir].sortBySimilarity(seriesInfo.name){ it.name }.first()
def season = sxe && sxe.season > 0 ? sxe.season : 1
log.fine "$dir => $seriesInfo.name [$seriesInfo]"
fetchSeriesArtworkAndNfo(seriesDir, dir, seriesInfo, season, false, locale)
}