-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
post_xmbcnfo.groovy
167 lines (160 loc) · 6.69 KB
/
post_xmbcnfo.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
{ source, target, metadata ->
// sanity check, fail when its not an episode and video file
if (type.toString() != "Episode" && !f.video) {
return null
}
def tdir = target.dir
def cse = any{ s } { 0 }
def cep = any{ e } { special }
def tvmapi = 0
def epl = null
try {
if (db.TheTVDB?.id) {
def tvm_url = "https://api.tvmaze.com"
def c1 = curl "$tvm_url/lookup/shows?thetvdb=${db.TheTVDB.id}"
def s1 = c1.id
epl = curl "$tvm_url/shows/$s1/episodebynumber?season=$cse&number=$cep"
tvmapi = epl.id
}
} catch (Exception err) {
// ignore
}
// load ~/.filebotsecrets.json and set tmdb_key
def tmdb_key = ""
def tmdb_lang = "en-US"
def personal = null
def secrets = new File("$home/.filebotsecrets.json")
if (secrets.exists()) {
def udata = new groovy.json.JsonSlurper().parseText(secrets.text)
tmdb_key = udata.tmdb_key
tmdb_lang = udata.language
personal = udata.person_info_dir
}
// get episode info from TMDB
def tmdb_url = "https://api.themoviedb.org/3/tv/$id/season/$cse/episode/$cep"
def acjson = ["accept": "application/json"]
def ep_info = curl(acjson, "$tmdb_url?language=$tmdb_lang&api_key=$tmdb_key")
def ext_ids = curl(acjson, "$tmdb_url/external_ids?api_key=$tmdb_key")
def tcred = curl(acjson, "$tmdb_url/credits?language=$tmdb_lang&api_key=$tmdb_key")
def imgs = curl(acjson, "$tmdb_url/images?include_image_language=en%2Cnull&api_key=$tmdb_key")
// get image url
def img_path = (tdir / target.nameWithoutExtension + "-thumb.jpg").toString()
def img_obj = new File(img_path)
def r_img_obj = new File(img_path.replace("-thumb",""))
if (!(img_obj.exists() || r_img_obj.exists()) && imgs.stills.size() > 0) {
def img_url = "https://image.tmdb.org/t/p/original${imgs.stills[0].file_path}"
system "curl", "-o", tdir / target.nameWithoutExtension + "-thumb.jpg", img_url
}
def cactors = []
(tcred.cast + tcred.guest_stars).eachWithIndex { c, index ->
def download_path = "$personal/${c.name[0]}/${c.name}"
def sord = c.order ?: index + cactors.size()
cactors << [person_name: c.name, crole: c.character, ford: sord, download_path: "${download_path}/folder.jpg"]
if (personal) {
def download_obj = new File(download_path)
if (!download_obj.exists()) {
download_obj.mkdirs()
system "curl", "-o", "${download_path}/folder.jpg", "https://image.tmdb.org/t/p/original${c.profile_path}"
}
}
}
def nfo_path = tdir / target.nameWithoutExtension + ".nfo"
XML(nfo_path) {
mkp.xmlDeclaration(version: "1.0", encoding: "utf-8", standalone: "yes")
episodedetails {
plot(ep_info.overview)
lockdata("false")
// today date on UTC
dateadded(new Date().format("yyyy-MM-dd HH:mm:ss", TimeZone.getTimeZone("UTC")))
title(t)
originaltitle(localize."${languages[0]}".t)
rating(rating)
year(airdate.format("yyyy"))
uniqueid(type: "tmdb", value: episode.id, 'default': "true", episode.id)
tmdbid(episode.id)
if (ext_ids?.imdb_id) {
uniqueid(type: "imdb", value: ext_ids.imdb_id, ext_ids.imdb_id)
imdbid(ext_ids.imdb_id)
}
if (ext_ids?.tvdb_id) {
uniqueid(type: "tvdb", value: ext_ids.tvdb_id, ext_ids.tvdb_id)
tvdbid(ext_ids.tvdb_id)
}
try {
runtime(runtime)
} catch (Exception err) {
// Use local runtime
runtime(minutes)
}
try {
if (db.AniDB?.episode?.id) {
uniqueid(type: "anidb", value: db.AniDB.episode.id, db.AniDB.episode.id)
anidbid(db.AniDB.episode.id)
}
} catch (Exception err) {
// ignore
}
try {
if (tvmapi) {
uniqueid(type: "tvmaze", value: tvmapi, tvmapi)
tvmazeid(tvmapi)
}
} catch (Exception err) {
// ignore
}
if (img_obj.exists()) {
art {
poster(img_path)
}
}
// create list of actors
cactors.each { person -> actor {
name(person.person_name)
role(person.crole)
sortorder(person.ford)
if (personal) { thumb(person.download_path) }
}}
showtitle(n)
episode(cep)
season(cse)
aired(airdate.format("yyyy-MM-dd"))
fileinfo {
streamdetails {
target.mediaInfo.Video.each { vid -> video {
def dur = Float.parseFloat(vid.'Duration')
codec(vid.'Format')
micodec(vid.'Format')
bitrate(vid.'BitRate')
width(vid.'Width')
height(vid.'Height')
aspect(vid.'DisplayAspectRatio/String')
aspectratio(vid.'DisplayAspectRatio/String')
framerate(vid.'FrameRate')
'default'(vid.'Default' == "Yes" ? "True" : "False")
forced(vid.'Forced' == "Yes" ? "True" : "False")
duration(vid.'Duration' ? (int) Math.floor(dur / 60000) : 0)
durationinseconds(vid.'Duration' ? (int) Math.floor(dur / 1000) : 0)
}}
target.mediaInfo.Audio.each { aud -> audio {
codec(aud.'Format')
micodec(aud.'Format')
language(aud.'Language/String3')
channels(aud.'Channel(s)')
samplingrate(aud.'SamplingRate')
'default'(aud.'Default' == "Yes" ? "True" : "False")
forced(aud.'Forced' == "Yes" ? "True" : "False")
}}
target.mediaInfo.Text.each { sbt -> subtitle {
codec(sbt.'Format')
micodec(sbt.'Format')
width('0')
height('0')
language(sbt.'Language/String3')
'default'(sbt.'Default' == "Yes" ? "True" : "False")
forced(sbt.'Forced' == "Yes" ? "True" : "False")
}}
}
}
}
}
}