-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
254 lines (206 loc) · 6.7 KB
/
build.gradle.kts
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import myaa.subkt.ass.*
import myaa.subkt.tasks.*
import myaa.subkt.tasks.Mux.*
import myaa.subkt.tasks.Nyaa.*
import java.awt.Color
import java.time.*
plugins {
id("myaa.subkt")
}
// Retrieve the script's playRes values
fun ASSFile.getPlayRes(): Pair<Int?, Int?> {
return this.scriptInfo.playResX to this.scriptInfo.playResY
}
fun Provider<String>.getPlayRes(): Pair<Int?, Int?> {
return ASSFile(File(this.get())).getPlayRes()
}
// Check whether a string contains parts of a ktemplate
fun String.isKaraTemplate(): Boolean {
return this.startsWith("code") || this.startsWith("template") || this.startsWith("mixin")
}
// Check whether a line is part of a ktemplate
fun EventLine.isKaraTemplate(): Boolean {
return this.effect.isKaraTemplate()
}
// Check if a line is entirely blank (no text, actor, or effect)
fun EventLine.isBlank(): Boolean {
return this.text.isEmpty() && this.actor.isEmpty() && this.effect.isEmpty()
}
subs {
readProperties("sub.properties")
episodes(getList("episodes"))
// Merge all the individual script components
merge {
from(get("dialogue"))
if (propertyExists("OP")) {
from(get("OP")) {
syncSourceLine("sync")
syncTargetLine("opsync")
}
}
if (propertyExists("ED")) {
from(get("ED")) {
syncSourceLine("sync")
syncTargetLine("edsync")
}
}
fromIfPresent(get("extra"), ignoreMissingFiles = true)
fromIfPresent(getList("INS"), ignoreMissingFiles = true)
fromIfPresent(getList("TS"), ignoreMissingFiles = true)
fromIfPresent(get("render_warning"), ignoreMissingFiles = true)
includeExtraData(false)
includeProjectGarbage(false)
// Try to set the LayoutRes values from the playRes values of the dialogue file.
// Falls back to 1920x1080 if not found
val (resX, resY) = get("dialogue").getPlayRes()
scriptInfo {
title = get("group").get()
scaledBorderAndShadow = true
wrapStyle = WrapStyle.NO_WRAP
values["LayoutResX"] = resX ?: 1920
values["LayoutResY"] = resY ?: 1080
}
}
// Remove ktemplate and empty lines from the final output
val cleanmerge by task<ASS> {
from(merge.item())
// ass { events.lines.removeIf { it.isKaraTemplate() or it.isBlank() } }
ass { events.lines.removeIf { it.isBlank() } }
}
// Generate chapters from dialogue file
chapters {
from(get("chapters"))
chapterMarker("chapter")
}
// Run swapper script for honorifics and other swaps
swap {
from(cleanmerge.item())
styles(Regex("Main|Default|Alt"))
}
// Finally, mux following the conventions listed here: https://thewiki.moe/advanced/muxing/#correct-tagging
mux {
title(get("title"))
// Optionally specify mkvmerge version to use
if (propertyExists("mkvmerge")) {
mkvmerge(get("mkvmerge"))
}
from(get("premux")) {
tracks {
include(track.type == TrackType.VIDEO || track.type == TrackType.AUDIO)
}
video {
lang("und")
name(get("vtrack"))
default(true)
}
audio {
lang("jpn")
name(get("atrack"))
default(true)
forced(false)
}
includeChapters(false)
attachments { include(false) }
}
from(cleanmerge.item()) {
tracks {
lang("eng")
name(get("strack_reg"))
default(true)
forced(false)
compression(CompressionType.ZLIB)
}
}
from(swap.item()) {
subtitles {
lang("enm")
name(get("strack_hono"))
default(true)
forced(false)
compression(CompressionType.ZLIB)
}
}
chapters(chapters.item()) { lang("eng") }
// Fonts handling
skipUnusedFonts(true)
attach(get("common_fonts")) {
includeExtensions("ttf", "otf")
}
attach(get("fonts")) {
includeExtensions("ttf", "otf")
}
// Get OP/ED fonts if necessary
if (propertyExists("OP")) {
attach(get("opfonts")) {
includeExtensions("ttf", "otf")
}
}
if (propertyExists("ED")) {
attach(get("edfonts")) {
includeExtensions("ttf", "otf")
}
}
out(get("muxout"))
}
// =================================================================================================================
// NCOP/EDs
tasks(getList("ncs")) {
merge {
from(get("ncsubs"))
includeExtraData(false)
includeProjectGarbage(false)
scriptInfo {
title = get("group").get()
originalScript = get("group").get()
scaledBorderAndShadow = true
}
}
val cleanncmerge by task<ASS> {
from(merge.item())
// ass { events.lines.removeIf { it.isKaraTemplate() or it.isBlank() } }
ass { events.lines.removeIf { it.isBlank() } }
}
chapters {
from(cleanncmerge.item())
chapterMarker("ncchapter")
}
mux {
title(get("title"))
from(get("ncpremux")) {
tracks {
include(track.type == TrackType.VIDEO || track.type == TrackType.AUDIO)
}
video {
lang("jpn")
name(get("vtrack"))
default(true)
}
audio {
lang("jpn")
name(get("atrack"))
default(true)
}
includeChapters(false)
attachments { include(false) }
}
from(cleanncmerge.item()) {
tracks {
lang("eng")
name(get("strack_reg"))
default(true)
forced(false)
compression(CompressionType.ZLIB)
}
}
chapters(chapters.item()) { lang("eng") }
skipUnusedFonts(true)
attach(get("ncfonts")) {
includeExtensions("ttf", "otf")
}
attach(get("common_fonts")) {
includeExtensions("ttf", "otf")
}
out(get("ncmuxout"))
}
}
}