-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.php
50 lines (44 loc) · 1.39 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
<?php
# YouTube Transcriber
# http://techleadpro.com/ytcaption/
function encodeURIComponent($str) {
# https://stackoverflow.com/questions/1734250/what-is-the-equivalent-of-javascripts-encodeuricomponent-in-php
$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
return strtr(rawurlencode($str), $revert);
}
$code = <<<EOF
var regexp = new RegExp(/playerCaptionsTracklistRenderer.*?(youtube.com\/api\/timedtext.*?)"/);
var match = regexp.exec(document.body.innerHTML);
if (!match) {
alert ("No captions found");
return;
}
var url = regexp.exec(document.body.innerHTML)[1];
open("http://techleadpro.com/ytcaption/caption.php?url=" + encodeURIComponent(url));
EOF;
$code = encodeURIComponent($code);
print <<<EOF
<head>
<title> YouTube Transcriber</title>
<style>
body {
font-family:arial;
padding: 16px;
}
</style>
</head>
<body>
<h3> YouTube Transcriber Bookmarklet</h3>
Drag the below "link" into the bookmark bar in any browser.
Then when you're viewing a YouTube video, click it to view the transcription of the video.
<BR/>
<table style='border-radius:8px;font-size:15px;border:1px #ccc solid; background-color:#fafafa;padding:8px;margin:8px'>
<tr>
<TD>
<a href="javascript:(function(){ $code })()">📺 Transcribe</a> (Drag to bookmark bar)
</td>
</tr>
</table>
<li> Bug notes - The video page needs to be refreshed for subsequent videos.
</body>
EOF;