forked from filebot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfo.groovy
218 lines (185 loc) · 4.18 KB
/
nfo.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env filebot -script
def fetchMovieNfo(m, f) {
def nfoFile = f.dir / f.nameWithoutExtension + '.nfo'
if (nfoFile.exists()) {
log.finest "[SKIP] NFO already exists: $nfoFile"
return
}
log.info "Generate Movie NFO: $m [$nfoFile]"
def i = m.info
def xml = XML {
movie {
title(i.name)
originaltitle(i.originalName)
set(i.collection)
year(i.released?.year)
rating(i.rating)
votes(i.votes)
mpaa(i.certification)
plot(i.overview)
tagline(i.tagline)
runtime(i.runtime)
id(i.id)
i.genres.each{ g ->
genre(g)
}
i.keywords.each{ k ->
tag(k)
}
i.productionCountries.each{ c ->
country(c)
}
i.productionCompanies.each{ c ->
studio(c)
}
crewFragment(delegate, i.crew)
fileFragment(delegate, f)
if (i.imdbId) {
imdb(id:'tt' + i.imdbId.pad(7), 'https://www.imdb.com/title/tt' + i.imdbId.pad(7))
}
tmdb(id:i.id, 'https://www.themoviedb.org/movie/' + i.id)
}
}
// write movie nfo file
xml.saveAs(nfoFile)
}
def fetchSeriesNfo(m, f) {
def seriesFolder = f.dir.dir
def nfoFile = seriesFolder / seriesFolder.name + '.nfo'
if (nfoFile.exists()) {
log.finest "[SKIP] NFO already exists: $nfoFile"
return
}
log.info "Generate Series NFO: $m.seriesInfo [$nfoFile]"
def s = m.seriesInfo.details
def xml = XML {
tvshow {
if (s.database == 'TheTVDB') {
uniqueid(type:'tvdb', s.id)
}
if (s.database == 'TheMovieDB::TV') {
uniqueid(type:'tmdb', s.id)
}
title(s.name)
year(s.startDate?.year)
rating(s.rating)
votes(s.ratingCount)
plot(s.overview)
runtime(s.runtime)
mpaa(s.certification)
premiered(s.startDate)
status(s.status)
studio(s.network)
episodeguide(s.id)
id(s.id)
s.genres.each{ g ->
genre(g)
}
crewFragment(delegate, s.crew)
}
}
// write series nfo file
xml.saveAs(nfoFile)
}
def fetchEpisodeNfo(m, f) {
def nfoFile = f.dir / f.nameWithoutExtension + '.nfo'
if (nfoFile.exists()) {
log.finest "[SKIP] NFO already exists: $nfoFile"
return
}
log.info "Generate Episode NFO: $m [$nfoFile]"
def s = m.seriesInfo
def xml = XML {
m.each{ episodePart ->
// retrieve episode information for each episode or multi-episode component
def e = episodePart.info
if (e == null) {
return
}
episodedetails {
if (s.database == 'TheTVDB') {
uniqueid(type:'tvdb', e.id)
}
if (s.database == 'TheMovieDB::TV') {
uniqueid(type:'tmdb', e.id)
}
title(e.title)
season(e.season)
episode(e.episode)
aired(e.airdate)
plot(e.overview)
thumb(aspect:'thumb', e.image)
crewFragment(delegate, e.crew)
fileFragment(delegate, f)
}
}
}
if (xml.empty) {
log.warning "Episode NFO not supported: $s"
return
}
// write episode nfo file
xml.saveAs(nfoFile)
}
def crewFragment(element, crew) {
crew.each{ p ->
if (p.director) {
element.director(p.name)
} else if (p.writer) {
element.credits(p.name)
} else if (p.actor) {
element.actor {
name(p.name)
role(p.character)
}
} else if (p.department == 'Writing') {
element.credits("$p.name ($p.job)")
}
}
}
def fileFragment(element, file) {
element.fileinfo {
streamdetails {
MediaInfo.snapshot(file).each{ kind, streams ->
def section = kind.toString().toLowerCase()
streams.each{ s ->
if (section == 'video') {
video {
codec((s.'Encoded_Library/Name' ?: s.'CodecID/Hint' ?: s.'Format').replaceAll(/[ ].+/, '').trim())
aspect(s.'DisplayAspectRatio')
width(s.'Width')
height(s.'Height')
}
}
if (section == 'audio') {
audio {
codec((s.'CodecID/Hint' ?: s.'Format').replaceAll(/\p{Punct}/, '').trim())
language(s.'Language/String3')
channels(s.'Channel(s)_Original' ?: s.'Channel(s)')
}
}
if (section == 'text') {
subtitle { language(s.'Language/String3') }
}
}
}
}
}
}
args.getFiles{ it.video }.each{ f ->
def m = f.metadata
switch(m) {
case Movie:
log.finest "[MOVIE] $m [$f]"
fetchMovieNfo(m, f)
break
case Episode:
log.finest "[EPISODE] $m [$f]"
fetchSeriesNfo(m, f)
fetchEpisodeNfo(m, f)
break;
default:
log.finest "[XATTR NOT FOUND] $f"
break
}
}