forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hls.php
100 lines (93 loc) · 4.12 KB
/
hls.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
<?php
global $global, $config;
if (!isset($global['systemRootPath'])) {
$configFile = '../videos/configuration.php';
if (!file_exists($configFile)) {
$configFile = '../../videos/configuration.php';
}
require_once $configFile;
}
//_error_log("HLS.php: session_id = ". session_id()." IP = ". getRealIpAddr()." URL = ".($actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"));
session_write_close();
if (empty($_GET['videoDirectory'])) {
forbiddenPage("No directory set");
}
$global['disableGeoblock'] = 1;
$video = Video::getVideoFromFileName($_GET['videoDirectory'], true);
$filename = Video::getPathToFile("{$_GET['videoDirectory']}".DIRECTORY_SEPARATOR."index.m3u8");
if (empty($video) || !file_exists($filename)) {
header("Content-Type: text/plain");
if (empty($video)) {
$msg = "HLS.php: Video Not found videoDirectory=({$_GET['videoDirectory']})";
error_log($msg);
//echo $msg;
}
if (!file_exists($filename)) {
$msg = "HLS.php: Video file do not exists ({$filename})";
error_log($msg);
//echo $msg;
}
echo "#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=300000
{$global['webSiteRootURL']}plugin/Live/view/loopBGHLS/res240/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=600000
{$global['webSiteRootURL']}plugin/Live/view/loopBGHLS/res360/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1000000
{$global['webSiteRootURL']}plugin/Live/view/loopBGHLS/res480/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2000000
{$global['webSiteRootURL']}plugin/Live/view/loopBGHLS/res720/index.m3u8";
exit;
} else {
if (filesize($filename) < 20) {
Video::clearCache($video['id']);
}
}
$_GET['file'] = Video::getPathToFile("{$_GET['videoDirectory']}".DIRECTORY_SEPARATOR."index.m3u8");
//var_dump($_GET['file']);exit;
$cachedPath = explode(DIRECTORY_SEPARATOR, $_GET['videoDirectory']);
if (empty($_SESSION['user']['sessionCache']['hls'][$cachedPath[0]]) && empty($_GET['download'])) {
AVideoPlugin::xsendfilePreVideoPlay();
$_SESSION['user']['sessionCache']['hls'][$cachedPath[0]] = 1;
}
$tokenIsValid = false;
if (!empty($_GET['token'])) {
$secure = AVideoPlugin::loadPluginIfEnabled('SecureVideosDirectory');
if ($secure) {
$filenameParts = explode(".DIRECTORY_SEPARATOR.", $_GET['videoDirectory']);
$fname = $filenameParts[0];
$tokenIsValid = $secure->isTokenValid($_GET['token'], $fname, $_GET['videoDirectory']);
}
} elseif (!empty($_GET['globalToken'])) {
$tokenIsValid = verifyToken($_GET['globalToken']);
}
$newContent = '';
// if is using a CDN I can not check if the user is logged
if (isAVideoEncoderOnSameDomain() || $tokenIsValid || !empty($advancedCustom->videosCDN) || User::canWatchVideo($video['id']) || User::canWatchVideoWithAds($video['id']) || isCDN()) {
if (!empty($_GET['download'])) {
downloadHLS($_GET['file']);
} elseif (!empty($_GET['playHLSasMP4'])) {
playHLSasMP4($_GET['file']);
} else {
if (@filesize($_GET['file'])>20) {
$filename = $_GET['file'];
} else {
$filename = pathToRemoteURL($filename);
}
$content = file_get_contents($filename);
$newContent = str_replace('{$pathToVideo}', "{$global['webSiteRootURL']}videos/{$_GET['videoDirectory']}/../", $content);
if (!empty($_GET['token'])) {
$newContent = str_replace('/index.m3u8', "/index.m3u8?token={$_GET['token']}", $newContent);
} elseif (!empty($_GET['globalToken'])) {
$newContent = str_replace('/index.m3u8', "/index.m3u8?globalToken={$_GET['globalToken']}", $newContent);
}
}
} else {
$newContent = "HLS.php Can not see video [{$video['id']}] ({$_GET['videoDirectory']}) ";
$newContent .= $tokenIsValid ? "" : " tokenInvalid";
$newContent .= User::canWatchVideo($video['id']) ? "" : " cannot watch ({$video['id']})";
$newContent .= " " . date("Y-m-d H:i:s");
}
header("Content-Type: text/plain");
//header('Content-Type:');
echo $newContent;