-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
76 lines (69 loc) · 2.88 KB
/
functions.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
<?php
function encodeURL($unencoded_url) {
$encoded_url = preg_replace_callback('#://([^/]+)/([^?]+)#', function ($match) {
return '://' . $match[1] . '/' . join('/', array_map('rawurlencode', explode('/', $match[2])));
}, $unencoded_url);
return $encoded_url;
}
function recursiveScanDirectory($websiteRoot, $root, $path, $title, $language, $imagepath, $rating) {
$content = array_diff(scandir($path), array('..', '.'));
//print_r($content);
$externalPath = encodeURL(str_replace($root, $websiteRoot, $path));
// Reading poster file
if (in_array('cover.jpg', $content)) {
//print("Cover.jpg found!");
$imagepath = $externalPath . '/cover.jpg';
} else if (in_array('cover.png', $content)) {
//print("Cover.png found!");
$imagepath = $externalPath . '/cover.png';
}
// Reading eventual config file
$coverfile = $path . '/cover.json';
if (in_array('cover.json', $content)) {
//print("Cover.json found!");
$file = file_get_contents($coverfile);
$coverdata = json_decode($file);
if (isset($coverdata->title)) {
$title = $coverdata->title;
}
if (isset($coverdata->image)) {
$imagepath = $externalPath . "/" . $coverdata->image;
}
if (isset($coverdata->language)) {
$language = $coverdata->language;
}
if (isset($coverdata->rating)) {
$rating = $coverdata->rating;
}
}
$films = array();
$newdirs = array();
// Scanning local files, looking for videos
foreach ($content as $i => $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
// Check if it's a video file
if ($ext === "mp4" || $ext === "mkv" || $ext === "avi" || $ext === "wmv") {
$film = new stdClass;
$film->filename = $file;
$film->path = str_replace("\\","/",$externalPath."/".$file);
$film->image = str_replace("\\","/",$imagepath);
$film->title = $title;
$film->language = $language;
$film->rating = $rating;
array_push($films, $film);
} else if (is_dir($path."/".$file)) {
array_push($newdirs, $file);
}
}
// Scanning local directories
foreach ($newdirs as $i => $folder) {
$result = recursiveScanDirectory($websiteRoot, $root, $path."/".$folder, $title, $language, $imagepath, $rating);
$films = array_merge($films, $result);
}
return $films;
}
function getFilmsJSON($websiteRoot, $root) {
$films = recursiveScanDirectory($websiteRoot, $root, $root, "", "", "no_poster.svg", -1);
return json_encode($films);
}
?>