-
Notifications
You must be signed in to change notification settings - Fork 159
/
substation.js
123 lines (113 loc) · 2.4 KB
/
substation.js
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
var substation = require('ass-stringify')
var merge = require('lodash.merge')
var msTime = require('./mstime')
var captionParams = {
'Marked': 'Marked=0',
'Start': '0:00:01.18',
'End': '0:00:06.85',
'Style': 'DefaultVCD',
'Name': 'NTP',
'MarginL': '0000',
'MarginR': '0000',
'MarginV': '0000',
'Effect': null,
'Text': null
}
var defaultParams = {
'Script Info': {
'Title': 'Videoshow video',
'ScriptType': 'v4',
'Collisions': 'Normal',
'PlayResY': '600',
'PlayDepth': '0',
'Timer': '100,0000'
},
'Empty': {},
'V4 Styles': {
'Format': [
'Name',
'Fontname',
'Fontsize',
'PrimaryColour',
'SecondaryColour',
'TertiaryColour',
'BackColour',
'Bold',
'Italic',
'BorderStyle',
'Outline',
'Shadow',
'Alignment',
'MarginL',
'MarginR',
'MarginV',
'AlphaLevel',
'Encoding'
],
'Style': {
'Name': 'DefaultVCD',
'Fontname': 'Arial',
'Fontsize': '28',
'PrimaryColour': '11861244',
'SecondaryColour': '11861244',
'TertiaryColour': '11861244',
'BackColour': '-2147483640',
'Bold': '-1',
'Italic': '0',
'BorderStyle': '1',
'Outline': '1',
'Shadow': '2',
'Alignment': '2',
'MarginL': '30',
'MarginR': '30',
'MarginV': '30',
'AlphaLevel': '0',
'Encoding': '0'
}
},
'Events': {
'Format': [
'Marked',
'Start',
'End',
'Style',
'Name',
'MarginL',
'MarginR',
'MarginV',
'Effect',
'Text'
]
}
}
exports.stringify = function (captions, styles) {
var params = mergeParams(styles)
captions.forEach(function (caption) {
var subtitle = merge({}, captionParams, {
Start: msTime.substation(+caption.startTime),
End: msTime.substation(+caption.endTime),
Text: caption.text
})
var body = params[params.length - 1].body
body.push({
key: 'Dialogue',
value: subtitle
})
})
return substation(params)
}
function mergeParams(styles) {
var params = merge({}, defaultParams)
merge(params['V4 Styles'].Style, styles)
return Object.keys(params).map(function (key) {
var body = params[key]
var map = { section: key }
map.body = Object.keys(body).map(function (prop) {
return {
key: prop,
value: body[prop]
}
})
return map
})
}