-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathdrive.php
133 lines (122 loc) · 4 KB
/
drive.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
define("base_url", "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
define("googledrive_key", "AIzaSyD739-eb6NzS_KbVJq1K8ZAxnrMfkIqPyw");
//Create folder if it doesn't already exist
if (!file_exists('cache')) {
mkdir('cache', 0777, true);
}
function GoogleDrive($gid){
$iframeid = my_simple_crypt($gid);
$title = gdTitle($gid);
$image = sprintf('https://drive.google.com/thumbnail?id=%s&authuser=0&sz=w640-h360-n-k-rw', $gid);
$streaming_vid = Drive($gid);
$output = ['id' => $gid, 'title' => $title, 'image' => $image, 'label' => 'HD', 'file' => $streaming_vid, 'type' => 'video/mp4', 'embed_id' => $iframeid];
$output = json_encode($output, JSON_PRETTY_PRINT);
return $output;
}
function Drive($gid) {
$timeout = 900;
$file_name = md5('GD'.$gid.'player');
if(file_exists('cache/'.$file_name.'.cache')) {
$fopen = file_get_contents('cache/'.$file_name.'.cache');
$data = explode('@@', $fopen);
$now = gmdate('Y-m-d H:i:s', time() + 3600*(+7+date('I')));
$times = strtotime($now) - $data[0];
if($times >= $timeout) {
$json_api = file_get_contents(sprintf('https://filedeo.com/api?id=%1$s&api=%2$s', $gid, googledrive_key));
$source = json_decode($json_api, true);
$source = $source['source'];
$create_cache = gdrive_cache($gid, $source);
$arrays = explode('|', $create_cache);
$cache = $arrays[0];
} else {
$cache = $data[1];
}
} else {
$json_api = file_get_contents(sprintf('https://filedeo.com/api?id=%1$s&api=%2$s', $gid, googledrive_key));
$source = json_decode($json_api, true);
$source = $source['source'];
$create_cache = gdrive_cache($gid, $source);
$arrays = explode('|', $create_cache);
$cache = $arrays[0];
}
return $cache;
}
function gdrive_cache($gid, $source) {
$time = gmdate('Y-m-d H:i:s', time() + 3600*(+7+date('I')));
$file_name = md5('GD'.$gid.'player');
$string = strtotime($time).'@@'.$source;
$file = fopen("cache/".$file_name.".cache",'w');
fwrite($file,$string);
fclose($file);
if(file_exists('cache/'.$file_name.'.cache')) {
$msn = $source;
} else {
$msn = $source;
}
return $msn;
}
function get_drive_id($string) {
if (strpos($string, "/edit")) {
$string = str_replace("/edit", "/view", $string);
} else if (strpos($string, "?id=")) {
$parts = parse_url($string);
parse_str($parts['query'], $query);
return $query['id'];
} else if (!strpos($string, "/view")) {
$string = $string . "/view";
}
$start = "file/d/";
if(strpos($string, "/preview")){
$end = "/preview";
}elseif(strpos($string, "/view")){
$end = "/view";
}
$string = " " . $string;
$ini = strpos($string, $start);
if ($ini == 0) {
return null;
}
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
function gdTitle($gid) {
$title = file_get_contents('https://content.googleapis.com/drive/v2/files/'.$gid.'?key='.googledrive_key);
$title = json_decode($title, true);
return $title['title'];
}
function fetch_value($str, $find_start = '', $find_end = ''){
if ($find_start == '') {
return '';
}
$start = strpos($str, $find_start);
if ($start === false) {
return '';
}
$length = strlen($find_start);
$substr = substr($str, $start + $length);
if ($find_end == '') {
return $substr;
}
$end = strpos($substr, $find_end);
if ($end === false) {
return $substr;
}
return substr($substr, 0, $end);
}
function my_simple_crypt( $string, $action = 'e' ) {
$secret_key = 'drivekey';
$secret_iv = 'google';
$output = false;
$encrypt_method = "AES-256-CBC";
$key = hash( 'sha256', $secret_key );
$iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
if( $action == 'e' ) {
$output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
}else if( $action == 'd' ){
$output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
}
return $output;
}
?>