forked from WWBN/AVideo-Storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.json.php
More file actions
74 lines (70 loc) · 2.89 KB
/
post.json.php
File metadata and controls
74 lines (70 loc) · 2.89 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
<?php
require_once './configuration.php';
require_once './functions.php';
header('Content-Type: application/json');
$obj = new stdClass();
$obj->error = true;
$obj->msg = "";
$obj->aVideoStorageURL = $global['aVideoStorageURL'];
$obj->filename = "";
if (empty($_REQUEST['secret']) || $_REQUEST['secret'] !== $global['secret']) {
$obj->msg = "Invalid secret";
} else if (empty($_REQUEST['video_url'])) {
$obj->msg = "Empty Video URL";
} else {
$url = $_REQUEST['video_url'];
$name = basename($url); // to get file name
$ext = pathinfo($url, PATHINFO_EXTENSION); // to get extension
$name2 = pathinfo($url, PATHINFO_FILENAME); //file name without extension
if (!empty($_REQUEST['source_secret'])) {
$query = parse_url($url, PHP_URL_QUERY);
// Returns a string if the URL has parameters or NULL if not
if ($query) {
$url .= "&secret={$_REQUEST['source_secret']}";
} else {
$url .= "?secret={$_REQUEST['source_secret']}";
}
}
$extParts = explode("?", $ext);
$ext = $extParts[0];
error_log("post.json.php: request extension {$ext} on URL {$_REQUEST['video_url']}");
if (strtolower($ext) === 'mp4' || strtolower($ext) === 'webm') {
error_log("post.json.php: get URL {$url}");
$file = url_get_contents($url); // to get file
error_log("post.json.php: Download done");
if ($file) {
$size = strlen($file);
error_log("post.json.php: is file {$size} = ".humanFileSize($size));
if ($size > 1000) {
$obj->filename = "{$global['videos_directory']}{$name2}.{$ext}";
$destinationSize = @filesize($obj->filename);
if($destinationSize>1000){
$obj->msg = "Error on save file {$obj->filename} is there already {$destinationSize} = ". humanFileSize($destinationSize);
error_log("post.json.php: {$obj->msg}");
}else if (file_put_contents($obj->filename, $file)) {
$obj->error = false;
$obj->msg = "";
} else {
$obj->msg = "Error on save file {$obj->filename}";
error_log("post.json.php: {$obj->msg}");
}
}else{
error_log("post.json.php: file too small: {$file}");
$obj->msg = "Error on download URL {$url}";
}
} else {
error_log("post.json.php: empty file");
$obj->msg = "Error on download URL {$url}";
}
} else if (strtolower($ext) === 'tgz') {
$obj->filename = "{$global['videos_directory']}{$name2}.{$ext}";
error_log("post.json.php: Download HLS {$obj->filename}");
$obj = moveFromSiteToLocalHLS($url, $obj->filename);
} else {
$obj->msg = "Extension Not Allowed {$ext}";
}
}
$json = json_encode($obj);
error_log($json);
die($json);
?>