-
Notifications
You must be signed in to change notification settings - Fork 3
/
all_vids.php
224 lines (169 loc) · 6.21 KB
/
all_vids.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
require_once('./config.php');
$activatehtmlcache=true;
ob_start();
$myhtmlcache=null;
require_once('./crero-lib.php');
$willhavetocache=false;
if ($activatehtmlcache){
$myhtmlcache=new creroHtmlCache($htmlcacheexpires);
}
$cachingkey='key:';
$_GET['all_vids']='1';//necessary if cache enabled
$get_keys=array_keys($_GET);
$whitelist= array ('a', 'b', 'all_vids');
foreach ($get_keys as $get_key){
//EXPECT crazy behaviors if target[] count more than one single elements. For now this is not a problem, cause the the sole target[] is array ('radio') and has only one element
if (in_array($get_key, $whitelist)){
$cachingkey.=$get_key."\n".$_GET[$get_key];
}
}
if ($activatehtmlcache&&!isset($_POST['validateemail'])&&!isset($_GET['pingstat'])){
if ($_SERVER['HTTP_USER_AGENT']==''){
http_response_code(403);
exit(0);
}
if ($myhtmlcache->hasPageExpired($cachingkey)){
$willhavetocache=true;
}
else {
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) <= date(DATE_RFC822, $myhtmlcache->getCachedPageDate($cachingkey))){
header(null);
header('HTTP/1.0 304 Not Modified');
die();
}
}
header('Last-Modified: '.date(DATE_RFC822, $myhtmlcache->getCachedPageDate($cachingkey)));
echo $myhtmlcache->getCachedPage($cachingkey);
die();
}
}
$cache = array();
if (file_exists('./vidcache.dat')){
$cache=unserialize(file_get_contents('./vidcache.dat'));
}
?><!DOCTYPE html>
<html>
<head>
<title>All videos from <?php echo htmlspecialchars($sitename);?></title>
<link rel="shortcut icon" href="./<?php echo $favicon;?>" />
<meta name="description" value="<?php echo htmlspecialchars($description);?>"/>
<meta charset="UTF-8"/>
<link href="./style.css" rel="stylesheet" type="text/css"/>
<meta name="viewport" content="width=device-width" />
</head>
<body>
<a href="./"><?php echo htmlspecialchars($sitename);?> Home</a> > All vids<hr/>
<a href="./random_vids.php">All videos in random mode</a><br/>
<?php
$arts = explode ("\n", file_get_contents('./d/artists.txt'));
sort($arts);
$selart='';
if (isset($_GET['a'])){$selart=$_GET['a'];}
foreach ($arts as $art){
$col='';
if ($art==$selart){$col='background-color:white;';}
echo '<span style="'.$col.'">[<a href="?a='.urlencode($art).'">'.htmlspecialchars($art).'</a>';
foreach ($hlartists as $tis){
if (isset($tis['name'])&&$tis['name']==$art){
echo ' ('.htmlspecialchars($tis['styles']).')';
}
}
echo ']</span> ';
}
echo '<hr/>';
if ($selart!=''){
$querystring = 'listalbums='.urlencode($selart);
$album_file=null;
$remoteapicache=array();
if (file_exists('./vidremoteapicache-v2.dat')){
$remoteapicache=unserialize(file_get_contents('./vidremoteapicache-v2.dat'));
if (isset($remoteapicache[$querystring])){
$album_file=$remoteapicache[$querystring];
}
}
if ($album_file==null) {
$query=file_get_contents($clewnapiurl.'?'.$querystring);
if (file_exists('./vidremoteapicache-v2.dat')){
$remoteapicache=unserialize(file_get_contents('./vidremoteapicache-v2.dat'));
}
$remoteapicache[$querystring]=$query;
file_put_contents('./vidremoteapicache-v2.dat', serialize($remoteapicache));
}
else {
$query=$album_file;
}
//$query=file_get_contents($clewnapiurl.'?'.$querystring);
$query2=file_get_contents($serverapi.'?listalbums='.urlencode($selart));
if ($query!==false&&$query2!==false){$query=trim($query).trim($query2);}
$selalb='';
if ($query!==false){
$arts= explode("\n", trim($query));
if (isset($_GET['b'])){$selalb=$_GET['b'];}
$run=false;
foreach ($arts as $art){
$rerun=false;
if ((in_array(html_entity_decode($art, ENT_COMPAT | ENT_HTML401 ), $cache)))
{$rerun=true;}
else if (intval(trim(file_get_contents($videoapiurl.'?hasalbum='.urlencode(html_entity_decode($art)))))>0){
$cached=array();
if (file_exists('./vidcache.dat')){
$cached=unserialize(file_get_contents('./vidcache.dat'));
}
array_push($cached, html_entity_decode($art));
file_put_contents('./vidcache.dat', serialize($cached));
$rerun=true;
}
if ($rerun){
$run=true;
$col='';
if (html_entity_decode($art)==$selalb){$col='background-color:white;';}
echo '<span style="'.$col.'">[<a href="?a='.urlencode($selart).'&b='.urlencode(html_entity_decode($art)).'">'.$art.'</a>]</span> ';
}
}
if (!$run){
echo 'This artist/project has no video available for now… <a href="./?artist='.urlencode($selart).'">Listen to the music maybe?</a>';
}
}
else {echo 'no album found. Maybe a temporary overload? Try again later maybe';}
echo '<hr/>';
if ($selalb!=''){
$query=file_get_contents($videoapiurl.'?baselistformats=1');
if ($query!==false){
$formats = explode("\n", trim($query));
$query=file_get_contents($videoapiurl.'?listalbvids='.urlencode($selalb));
if ($query!==false){
$array=explode("\n",trim($query));
for ($i=0;$i<count($array);$i++){
echo 'Video '.ceil(($i+1)/2).'/'.(count($array)/2).'<hr/>';
echo '<video style="width:85%;" controls="controls" preload="none">';
foreach ($formats as $format){
echo '<source src="'.$videourl.rawurlencode($array[$i]).'.'.$format.'"/>';
}
echo '</video><br>'.htmlspecialchars($array[$i+1]).' - Download ';
foreach ($formats as $format){
echo '<a href="'.$videourl.rawurlencode($array[$i]).'.'.$format.'" download>'.htmlspecialchars($format).'</a>';
}
echo '<br/>';
echo '<a target="_blank" href="./random_vids.php?v='.urlencode($array[$i]).'.mp4">Share?</a><br/>';
$i++;
}
}
else {echo 'Video tier API did not reply. Maybe a temporary overload? You may <a href="./?album='.urlencode(html_entity_decode($selalb)).'">listen to the music maybe?</a>';}
}
else {echo 'Video tier API did not reply. Maybe a temporary overload? You may <a href="./?album='.urlencode(html_entity_decode($selalb)).'">listen to the music maybe?</a>';}
}
}
?>
</body>
</html><?php
if ($activatehtmlcache){
if ($willhavetocache){
$htmlcode=ob_get_contents();
if ($htmlcode!==false){
$myhtmlcache->cachePage($cachingkey, $htmlcode);
}
}
}
?>