-
Notifications
You must be signed in to change notification settings - Fork 2
/
JSON_Playlist_Reader.php
77 lines (68 loc) · 2.21 KB
/
JSON_Playlist_Reader.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
<?php
// JSON FOLDER READER
$json_structure = '{
"Albdroid_Streaming_API":{
"Stream_Wrapper_Data":[';
$Playlist_Data = "Playlist_Data"; // SET PLAYLIST FOLDER TO READ
Scan_Playlist_Folder($Playlist_Data);
function Scan_Playlist_Folder($folder)
{
global $json_structure;
foreach (scandir($folder) as $playlist){
if(is_dir($playlist)){
if($playlist!='..' && ($playlist!='.')){
$json_structure.='{"title":"'.$playlist.'","playlist":[';
Scan_Playlist_Folder($playlist);
$json_structure = chop($json_structure,',');
$json_structure.=']},';
}
}else{
JSON_Playlist_Builder($playlist,$folder);
}
}
}
function JSON_Playlist_Builder($playlist,$folder)
{
global $json_structure;
if($playlist)
{
$cut_extensions_dots = substr($playlist,strrpos($playlist,'.'));
$disallow_extensions = [".php",".jpg",".py",".js",".htaccess",".htpasswd"]; // disable extensions
if(strpos($playlist,'.')>0 &&!in_array($cut_extensions_dots,$disallow_extensions))
{
$playlistname = substr($playlist,0,strpos($playlist,'.'));
$thumbnail = 'https://png.kodi.al/tv/albdroid/black.png'; // thumbnail
$path = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}".pathinfo($_SERVER['PHP_SELF'], 1).'/'.($folder!='.'?$folder.'/':'');
if(file_exists(($folder!='.'?$folder.'/':'').$playlistname.'.jpg'))
{
$thumbnail = ',"thumbnail":"'.$path.($playlistname.'.jpg').'"';
}
// REMOVE SPACES FROM TITLES
$playlistname = str_replace(
// REPLACE FROM
array("%20","-","_","%","?","/"),
// REPLACE TO
array(" "," "," "," "," "," "),
$playlistname
);
// REMOVE SPACES FROM HTTP(s) LINKS
$playlist = str_replace(
// REPLACE FROM
array(" "),
// REPLACE TO
array("%20"),
$playlist
);
$json_structure.='
{
"title":"'.$playlistname.'",
"playlist":"'.$path.$playlist.'",
"thumbnail":"'.$thumbnail.'"
},';
}
}
}
//$json_structure = chop($json_structure,',').']';
$json_structure = chop($json_structure,',')."\n".']'."\n".'}'."\n".'}'; //
echo($json_structure);
?>