forked from amereservant/phpffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefreshQueue.php
More file actions
80 lines (71 loc) · 3.13 KB
/
Copy pathrefreshQueue.php
File metadata and controls
80 lines (71 loc) · 3.13 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
70
71
72
73
74
75
76
77
78
79
80
<?php
require 'database.php';
require 'config.php';
require 'functions.php';
echo import_streams_to_db($pdo);
echo "\n";
$sql = 'SELECT 1 from streams WHERE status = "Downloading" OR status = "Converting" LIMIT 1';
$stmt = $pdo->prepare($sql);
$stmt->execute();
if ($stmt->fetchColumn())
//echo('There is already a stream being downloaded at the moment.');
die('There is already a stream being downloaded at the moment.');
$sql = 'SELECT * from streams WHERE status = "Not Downloaded" AND id not IN (select * from (SELECT id from streams WHERE status = "Not Downloaded" ORDER BY date DESC LIMIT 1) temp_tab) ORDER BY date ASC LIMIT 1';
$stmt = $pdo->query($sql);
$streams = $stmt->fetchAll(PDO::FETCH_ASSOC);
$twitch_url = TWITCH_URLS[0];
foreach ($streams as $stream) {
$twitch_server_num = 0;
foreach (TWITCH_IDS as $twitch_id) {
if(validImage("https://static-cdn.jtvnw.net/cf_vods/" . $twitch_id . '/' . $stream['id'] . "/thumb/thumb0-320x180.jpg'></td>")){
$twitch_url = TWITCH_URLS[$twitch_server_num];
break;
}
$twitch_server_num++;
}
$downloadURL = '';
$params = '';
if(getStatus($stream['id'],'720p30') == 'HTTP/1.1 200 OK') {
$downloadURL = $twitch_url . $stream['id'] . '/720p30/index-dvr.m3u8';
$params = '-threads 1 -movflags +faststart -crf 24 -pix_fmt yuv420p -vcodec libx264 -b:v 0k -c:a copy -bsf:a aac_adtstoasc -max_muxing_queue_size 4096 -y';
} elseif(getStatus($stream['id'],'720p60') == 'HTTP/1.1 200 OK') {
$downloadURL = $twitch_url . $stream['id'] . '/720p60/index-dvr.m3u8';
$params = '-threads 1 -movflags +faststart -crf 24 -pix_fmt yuv420p -vcodec libx264 -b:v 0k -c:a copy -bsf:a aac_adtstoasc -r 30000/1001 -max_muxing_queue_size 4096 -y';
} else {
$downloadURL = $twitch_url . $stream['id'] . '/chunked/index-dvr.m3u8';
$params = '-threads 1 -movflags +faststart -crf 24 -pix_fmt yuv420p -vcodec libx264 -b:v 0k -s 1280x720 -c:a copy -bsf:a aac_adtstoasc -r 30000/1001 -max_muxing_queue_size 4096 -y';
}
$fkey = hash('crc32', $stream['id'], false);
$data = [
'title' => $stream['date'] . " - " . $stream['title'],
'filename' => $downloadURL,
'fkey' => $fkey,
'type' => 'convert',
'params' => $params
];
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$status = file_get_contents(POST_URL, true, $context);
print_r($status);
if ($status) {
echo "Queued: " . $stream['title'];
}
}
function getStatus($id, $res) {
$twitch_server_num = 0;
//global TWITCH_IDS, TWITCH_URLS;
foreach (TWITCH_IDS as $twitch_id) {
if(validImage("https://static-cdn.jtvnw.net/cf_vods/" . $twitch_id . '/' . $id . "/thumb/thumb0-320x180.jpg'></td>")){
$twitch_url = TWITCH_URLS[$twitch_server_num];
break;
}
$twitch_server_num++;
}
return get_headers($twitch_url . $id . '/'.$res.'/index-dvr.m3u8', 1)[0];
}