-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_time_code.php
More file actions
executable file
·69 lines (50 loc) · 1.59 KB
/
fix_time_code.php
File metadata and controls
executable file
·69 lines (50 loc) · 1.59 KB
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
<?php
declare(strict_types=1);
class FixTimeCode {
protected array $data = array();
const VIDEO = "https://youtu.be/Nh19f_2fWLc";
public function __construct() {
$this->Main();
}
protected function Main() {
$fullPathName = __DIR__."/highlight_in.md";
printf("\n>> %s\n\n", $fullPathName);
$this->data = file( $fullPathName);
$nn = count($this->data);
for( $i = 0; $i < $nn; $i++) {
if( $begin = stripos($this->data[$i], "[t=")) {
if($end = stripos($this->data[$i], "s]")) {
$old_tag = substr($this->data[$i], $begin, $end-$begin+2);
$tc = substr($this->data[$i], $begin+3, $end-$begin-3);
if( stripos($tc, ":")) {
$x = explode(":", $tc);
$sec = (int)$x[0]*3600 + (int)$x[1]*60 + (int)$x[2];
if( (int)$x[0] <= 0) {
$new_tc = $x[1].":".$x[2];
} else {
$new_tc = $tc;
}
} else {
$sec = intval($tc);
$new_tc = ( $sec < 3600)? gmdate('i:s', ($sec)): gmdate('H:i:s', ($sec));
}
$new_tag = sprintf("[%s](%s?t=%d)", $new_tc, self::VIDEO, $sec);
printf("(%s)\t>%s<\t>%s<\t%s\n", $i, $sec, $old_tag, $new_tag);
$tmp = str_replace($old_tag, $new_tag, $this->data[$i]);
$tmp = str_replace("Section Overview: ", "**Section Overview:** ", $tmp);
$this->data[$i] = $tmp;
}
}
}
$this->GenerateMd();
}
protected function GenerateMd() {
$fd = fopen( __DIR__."/highlight_out.md", "w");
foreach($this->data as $row) {
fprintf( $fd, "%s", $row);
}
fclose( $fd);
}
}
$sd = new FixTimeCode();
?>