-
Notifications
You must be signed in to change notification settings - Fork 3
/
JSON_Playlist_Builder.php
65 lines (59 loc) · 2.13 KB
/
JSON_Playlist_Builder.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
<?php
// JSON BUILDER BY FOLDER
$json_structure = '{
"Albdroid_Streaming_API":{
"Stream_Wrapper_Data":[';
$Playlist_Data = "Playlist_Data"; // SET PLAYLIST FOLDER TO SCAN
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.'","folder":';
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"]; // 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(
array("%20","-","_","%","?","/"),
array(" "," "," "," "," "," "),
$playlistname
);
// REMOVE SPACES FROM HTTP(s) LINKS
$playlist = str_replace(
array(" "),
array("%20"),
$playlist
);
$json_structure.='
{
"title":"'.$playlistname.'",
"playlist":"'.$path.$playlist.'",
"thumbnail":"'.$thumbnail.'"
},';
}
}
}
$json_structure = chop($json_structure,',')."\n".']'."\n".'}'."\n".'}'; //
echo($json_structure);
file_put_contents('JSON_Playlist_Data.json', $json_structure);
?>