forked from MattsShack/Plex-Movie-Poster-Display
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetData.php
109 lines (87 loc) · 3.93 KB
/
getData.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
<?php
include 'config.php';
$results = Array();
$movies = Array();
#Display Custom Image
if ($customImageEnabled == "Yes") {
$title = "<br /><p style='font-size: 80px; -webkit-text-stroke: 2px yellow;'> </p>";
$display = "<img src='$customImage' style='width: 100%'>";
$info = "<p style='font-size: 65px; -webkit-text-stroke: 2px yellow;'> </p>";
} else {
#Plex Module
$url = 'http://'.$plexServer.':32400/status/sessions?X-Plex-Token='.$plexToken.'';
$getxml = file_get_contents($url);
$xml = simplexml_load_string($getxml) or die("feed not loading");
$title = NULL;
$display = NULL;
$info = NULL;
if ($xml['size'] != '0') {
foreach ($xml->Video as $clients) {
if(strstr($clients->Player['address'], $plexClient)) {
if(strstr($clients['type'], "movie")) {
$art = $clients['thumb'];
$poster = explode("/", $art);
$poster = trim($poster[count($poster) - 1], '/');
$filename = '/cache/' . $poster;
if (file_exists($filename)) {
#Future Code Coming
} else {
file_put_contents("cache/$poster", fopen("http://$plexServer:32400$art?X-Plex-Token=$plexToken", 'r'));
}
$title = "<br /><p style='font-size: 65px; -webkit-text-stroke: 2px yellow;'> $nowShowingTopText </p>";
$display = "<img src='cache/$poster' style='width: 100%'>";
$info = "<p style='font-size: 30px;'>" . $clients['summary'] . "</p>";
}
if(strstr($clients['type'], "episode")) {
$art = $clients['grandparentThumb'];
$poster = explode("/", $art);
$poster = trim($poster[count($poster) - 1], '/');
$filename = '/cache/' . $poster;
if (file_exists($filename)) {
#Future Code Coming
} else {
file_put_contents("cache/$poster", fopen("http://$plexServer:32400$art?X-Plex-Token=$plexToken", 'r'));
}
$title = "<br /><p style='font-size: 65px; -webkit-text-stroke: 2px yellow;'> $nowShowingTopText </p>";
$display = "<img src='cache/$poster' style='width: 100%'>";
$info = "<p style='font-size: 30px;'>Episode: " . $clients['title'] . " - " . $clients['summary'] . "</p>";
}
}
}
}
#If Nothing is Playing
if ($display == NULL) {
$title = "<br /><p style='font-size: 90px; -webkit-text-stroke: 2px yellow;'> $comingSoonTopText </p>";
$UnWatchedMoviesURL = 'http://'.$plexServer.':32400/library/sections/'.$plexServerMovieSection.'/all?X-Plex-Token='.$plexToken.'';
$getMovies = file_get_contents($UnWatchedMoviesURL);
$xmlMovies = simplexml_load_string($getMovies) or die("feed not loading");
$countMovies = count($xmlMovies);
if ($countMovies > '0') {
foreach ($xmlMovies->Video as $movie) {
$movies[] = strip_tags($movie['title']);
}
$random_keys = array_rand($movies,1);
$showMovie = $movies[$random_keys];
foreach ($xmlMovies->Video as $movie) {
if(strstr($movie['title'], $showMovie)) {
$art = $movie['thumb'];
$poster = explode("/", $art);
$poster = trim($poster[count($poster) - 1], '/');
$filename = 'cache/' . $poster;
if (file_exists($filename)) {
#Future Code Coming
} else {
file_put_contents("cache/$poster", fopen("http://$plexServer:32400$art?X-Plex-Token=$plexToken", 'r'));
}
$display = "<img src='cache/$poster' style='width: 100%'>";
}
}
}
$info = "<br /><p style='font-size: 75px; -webkit-text-stroke: 2px yellow;'> $comingSoonBottomText </p>";
}
}
$results['top'] = "$title";
$results['middle'] = "$display";
$results['bottom'] = "$info";
echo json_encode($results);
?>