-
Notifications
You must be signed in to change notification settings - Fork 138
/
artwork.groovy
executable file
·97 lines (79 loc) · 2.37 KB
/
artwork.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env -S filebot -script
def fetchMovieArtwork(movie, language, movieFolder) {
fetchArtwork(movie, 'posters', language, movieFolder / 'poster.jpg')
fetchArtwork(movie, 'backdrops', null, movieFolder / 'backdrop.jpg')
}
def fetchSeriesArtwork(series, language, seriesFolder, seasonFolder) {
if (series.database == 'TheTVDB') {
fetchArtwork(series, 'poster', language, seriesFolder / 'poster.jpg')
fetchArtwork(series, 'series', language, seriesFolder / 'series.jpg')
fetchArtwork(series, 'fanart', language, seriesFolder / 'fanart.jpg')
fetchArtwork(series, 'season', language, seasonFolder / 'season.jpg')
fetchArtwork(series, 'seasonwide', language, seasonFolder / 'seasonwide.jpg')
return
}
if (series.database == 'TheMovieDB::TV') {
fetchArtwork(series, 'posters', language, seriesFolder / 'poster.jpg')
fetchArtwork(series, 'backdrops', null, seriesFolder / 'backdrop.jpg')
return
}
log.warning "Artwork not supported: $series"
return
}
def fetchEpisodeArtwork(episode, episodeFile) {
def thumbnailFile = episodeFile.dir / episodeFile.nameWithoutExtension + '.jpg'
if (thumbnailFile.exists()) {
log.finest "[SKIP] Artwork already exists: $thumbnailFile"
return
}
def i = episode.info
if (i == null) {
log.warning "Artwork not supported: $episode.seriesInfo"
return
}
if (i.image == null) {
log.warning "Artwork not found: $episode [$thumbnailFile]"
return
}
log.fine "Fetch $i.image [$thumbnailFile]"
try {
i.image.saveAs(thumbnailFile)
} catch(e) {
log.severe "Failed to fetch artwork: $e.message"
}
}
def fetchArtwork(object, category, language, file) {
if (file.exists()) {
log.finest "[SKIP] Artwork already exists: $file"
return
}
def artwork = object.getArtwork(category, language)
if (artwork == null || artwork.empty) {
log.warning "Artwork not found: $object [$file]"
return
}
def a = artwork[0]
log.fine "Fetch $a [$file]"
try {
a.url.saveAs(file)
} catch(e) {
log.severe "Failed to fetch artwork: $e.message"
}
}
args.getFiles{ it.video }.each{ f ->
def m = f.metadata
switch(m) {
case Movie:
log.finest "[MOVIE] $m [$f]"
fetchMovieArtwork(m, m.language, f.dir)
break
case Episode:
log.finest "[EPISODE] $m [$f]"
fetchSeriesArtwork(m.seriesInfo, m.seriesInfo.language, f.dir.dir, f.dir)
fetchEpisodeArtwork(m, f)
break;
default:
log.finest "[XATTR NOT FOUND] $f"
break
}
}