-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
195 lines (169 loc) · 5.51 KB
/
index.php
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
<!doctype html>
<html lang="en">
<?php
/**
* Author: Michal Schweichler
* email: michal.schweichler[at]gmail.com
* www: http://michalschweichler.co.uk
*
* Date: 13/06/14
* Time: 15:00
*/
?>
<head>
<meta charset="UTF-8">
<title>Timecode converter</title>
<style>
form {
float: left;
}
textarea {
width: 400px;
height: 300px;
border: 1px solid rgb(167, 167, 167);
display: block;
float: left;
padding: 2px;
margin: 0;
/*resize: none;*/
outline-offset: 0;
font-family: monospace;
font-size: 14px;
}
input#convert {
display: block;
float: left;
margin: 120px 5px;
width: 80px;
height: 30px;
padding: 0;
}
div#wrapper {
width: 406px;
float: left;
}
</style>
</head>
<body>
<?php
function convHtml($string)
{
return htmlentities($string, ENT_QUOTES | ENT_IGNORE, "UTF-8");
}
$fileHeader =
convHtml('@ This is a DS Subtitles file') . '<br>' .
convHtml('@ Creator: Belle Nuit Subtitler 1.7.8') . '<br>' .
convHtml('@ Date: 23.07.2011') . '<br>' . '<br>' .
convHtml('@ Header') . '<br>' . '<br>' .
convHtml('<font> Arial') . '<br>' .
convHtml('<font size> 36') . '<br>' .
convHtml('<kerning> 1') . '<br>' .
convHtml('<leading> 2') . '<br>' .
convHtml('<alignment> center') . '<br>' . '<br>' .
convHtml('<use face> on') . '<br>' .
convHtml('<face color> 92 92 92') . '<br>' .
convHtml('<face opacity> 100') . '<br>' .
convHtml('<face softness> 0') . '<br>' . '<br>' .
convHtml('<use edge> on') . '<br>' .
convHtml('<edge color> 6 6 6') . '<br>' .
convHtml('<face opacity> 1') . '<br>' .
convHtml('<edge opacity> 1') . '<br>' .
convHtml('<edge softness> 60') . '<br>' .
convHtml('<edge width> 3') . '<br>' . '<br>' .
convHtml('<use shadow> on') . '<br>' .
convHtml('<shadow color> 50 50 50') . '<br>' .
convHtml('<shadow opacity> 100') . '<br>' .
convHtml('<shadow softness> 40') . '<br>' .
convHtml('<shadow offset> 3') . '<br>' .
convHtml('<shadow angle> 45') . '<br>' . '<br>' . '<br>' .
convHtml('@ Subtitles') . '<br>' . '<br>' .
convHtml('<begin subtitles>') . '<br>' . '<br>';
$outputLines[] = $fileHeader;
if (!empty($_POST['input'])) {
$inputLines = explode("\n", str_replace("\r", "", $_POST['input']));
$output = array();
foreach ($inputLines as $line) {
preg_match('/([0-9]*):([0-9]*):([0-9]*) (.*)/', $line, $match);
if ($match) {
$m = $match[1];
$s = $match[2];
$f = $match[3];
$text = $match[4];
$newH = floor($m / 60);
$newM = $m % 60;
$newS = $s;
$newF = $f;
$newText = $text;
if (count($output) == 0) {
$output[0]['start'] = ($newS - 5 <= 0) ? '00:00:00:00' : sprintf(
'%1$02d:%2$02d:%3$02d:%4$02d',
$newH,
$newM,
($newS - 5),
$newF
);
$output[0]['end'] = sprintf('%1$02d:%2$02d:%3$02d:%4$02d', $newH, $newM, $newS, $newF);
$output[0]['text'] = $newText;
} else {
$length = count($output);
$output[$length]['start'] = $output[$length - 1]['end'];
$output[$length]['end'] = sprintf('%1$02d:%2$02d:%3$02d:%4$02d', $newH, $newM, $newS, $newF);
$output[$length]['text'] = $newText;
}
}
}
foreach ($output as $key => $newLine) {
$time = $newLine['start'] . ' ' . $newLine['end'];
$text = $newLine['text'];
$string = convHtml($time) . '<br>' . convHtml($text) . '<br><br>';
$outputLines[] = $string;
}
}
$fileFooter = convHtml('<end subtitles>');
$outputLines[] = $fileFooter;
if (!empty($_POST['input'])) {
echo
'<form action="" method="post">' .
'<h3>Input:</h3>' .
'<textarea name="input" id="input" cols="50" rows="20">' . $_POST['input'] . '</textarea>' .
'<input type="submit" id="convert" value="convert ->" />' .
'</form>';
echo
'<div id="wrapper">' .
'<h3>Output:</h3>' .
'<textarea id="test">';
foreach ($outputLines as $item) {
echo str_replace(
'<br>',
' ',
$item
); // change br to \r\n /firstly output was echo'ed in div, now it's in textarea/
}
echo
'</textarea>' .
'</div>';
} else {
echo
'<form action="" method="post">' .
'<h3>Input:</h3>' .
'<textarea name="input" id="input" cols="50" rows="20">' .
'0:10:00 First subtitle bla bla bla' . ' ' .
'0:20:00 Second subtitle bla bla bla' . ' ' .
'0:33:00 Third subtitle bla bla bla' . ' ' .
'1:10:00 First subtitle bla bla bla' . ' ' .
'20:20:00 Fourth subtitle bla bla bla' . ' ' .
'61:13:00 Sixth subtitle bla bla bla' . ' ' .
'78:33:00 Seventh subtitle bla bla bla' . ' ' .
'</textarea>' .
'<input type="submit" id="convert" value="convert ->" />' .
'</form>';
echo
'<div id="wrapper">' .
'<h3>Output:</h3>' .
'<textarea id="test">' .
'</textarea>' .
'</div>';
}
?>
</body>
</html>