forked from MattsShack/Plex-Movie-Poster-Display
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetData.php
223 lines (211 loc) · 8.85 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
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
<?php
//For feedback, suggestions, or issues please visit https://www.mattsshack.com/plex-movie-poster-display/
include 'config.php';
include 'status.php';
$results = Array();
$movies = Array();
ob_start();
$data = [];
//Setup Scrolling Text Using jQuery Marquee (https://www.jqueryscript.net/animation/Text-Scrolling-Plugin-for-jQuery-Marquee.html)
if ($pmpBottomScroll == 'Enabled') {
$scrollPrepend = "<div class='marquee' style='height: 100%'>";
$scrollAppend = "</div>
<script>
$(function(){
$('.marquee').marquee({
allowCss3Support: true,
css3easing: 'linear',
delayBeforeStart: 2000,
duration: 8000,
direction: 'up',
gap: 20,
startVisible: true
});
});
</script>";
} else {
$scrollPrepend = "";
$scrollAppend = "";
}
//Clean Up Cache Dir (Files Older than 24 hours)
$cachePath = 'cache/posters/';
if ($handle = opendir($cachePath)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && ((time() - filectime($cachePath . $file)) > 86400)) {
unlink($cachePath . $file);
}
}
}
// Let's be lazy
$title = "";
$display = "";
$bottomLine = "";
$isPlaying = false;
$mediaTitle = "";
$mediaSummary = "";
$mediaTagline = "";
$topText = "";
$topCustom = "";
$bottomText = "";
$bottomCustom = "";
$topColor = "";
$bottomColor = "";
$topSize = "";
$bottomSize = "";
$autoScaleBottom = false;
$autoScaleTop = false;
$scrollBottom = false;
$topSelection = false;
$bottomSelection = false;
//Display Custom Image if Enabled
if ($customImageEnabled == "Enabled") {
$data['type'] = 'custom';
$topSize = $customTopFontSize;
$topColor = $customTopFontColor;
$bottomSize = $customBottomFontSize;
$bottomColor = $customBottomFontColor;
$topText = $customTopText;
$bottomText = $customBottomText;
$topSelection = $nowShowingTop;
$bottomSelection = $nowShowingBottom;
$display = "url('cache/custom/$customImage')";
$topStrokeColor = $customTopFontOutlineColor;
$topStrokeSize = $customTopFontOutlineSize;
$bottomStrokeColor = $customBottomFontOutlineColor;
$bottomStrokeSize = $customBottomFontOutlineSize;
} else {
// Plex Module Connect to Plex
$url = "http://$plexServer:32400/status/sessions?X-Plex-Token=$plexToken";
// Store this for debugging
$data['sessionUrl'] = $url;
$data['plexClient'] = $plexClient;
$data['plexClientName'] = $plexClientName;
$getXml = file_get_contents($url);
$xml = simplexml_load_string($getXml) or die("feed not loading");
$isPlaying = false;
if ($xml['size'] != '0') {
$data['hasXml'] = true;
foreach ($xml->Video as $clients) {
$art = false;
// If this matches our client IP or name, gather data
if (strstr($clients->Player['address'], $plexClient) || strstr($clients->Player['title'], $plexClientName)) {
$isPlaying = true;
$autoScaleTop = $nowShowingTopAutoScale;
$autoScaleBottom = $nowShowingBottomAutoScale;
$topSelection = $nowShowingTop;
$bottomSelection = $nowShowingBottom;
$data['hasClient1'] = true;
$mediaTitle = $clients['title'];
$mediaSummary = $clients['summary'];
$mediaTagline = $clients['tagline'];
$topSize = $nowShowingTopFontSize;
$topColor = $nowShowingTopFontColor;
$bottomSize = $nowShowingBottomFontSize;
$bottomColor = $nowShowingBottomFontColor;
//Now Showing Sections
if (strstr($clients['type'], "movie")) {
$art = $clients['thumb'];
} elseif (strstr($clients['type'], "episode")) {
$art = $clients['grandparentThumb'];
}
//Progress Bar
if ($pmpDisplayProgress == 'Enabled') {
$percentComplete = (((int)$clients['duration'] / 1000) / ((int)$clients['viewOffset'] / 1000)) * 100;
$progressBar = "<div class='progress' style='height : " . $pmpDisplayProgressSize . "px;'><div class='progress-bar' role='progressbar' style='width: " . $percentComplete . "%; background-color : " . $pmpDisplayProgressColor . ";' aria-valuenow='" . $percentComplete . "' aria-valuemin='0' aria-valuemax='100'></div></div> ";
} else {
$progressBar = NULL;
}
}
}
}
$data['isPlaying'] = $isPlaying;
//Coming Soon (If Nothing is Playing)
if (!$isPlaying) {
//Clean Up Status
updateStatus();
$autoScaleBottom = $comingSoonBottomAutoScale;
$autoScaleTop = $comingSoonTopAutoScale;
$topColor = $comingSoonTopFontColor;
$topSize = $comingSoonTopFontSize;
$bottomColor = $comingSoonBottomFontColor;
$bottomSize = $comingSoonBottomFontSize;
$topSelection = $comingSoonTop;
$bottomSelection = $comingSoonBottom;
//Multi Movie Section Support
$plexServerMovieSections = explode(",", $plexServerMovieSection);
$useSection = rand(0, count($plexServerMovieSections) - 1);
$MoviesURL = 'http://' . $plexServer . ':32400/library/sections/' . $plexServerMovieSections[$useSection] . '/' . $comingSoonShowSelection . '?X-Plex-Token=' . $plexToken . '';
$getMovies = file_get_contents($MoviesURL);
$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'];
$mediaTitle = $movie['title'];
$mediaSummary = $movie['summary'];
$mediaTagline = $movie['tagline'];
}
}
}
}
}
// If we're not using custom images, check if we need to cache art from Plex
// Otherwise, necessary values are set at the top
if ($customImageEnabled != "Enabled") {
// Check to see if we should cache our art
if ($cacheEnabled) {
$poster = explode("/", $art);
$poster = trim($poster[count($poster) - 1], '/');
$filename = 'cache/posters/' . $poster;
// There's nothing else to do here, just save it
if (!file_exists($filename)) {
file_put_contents("cache/posters/$poster", fopen("http://$plexServer:32400$art?X-Plex-Token=$plexToken", 'r'));
}
$display = "url('cache/posters/$poster')";
} else {
$display = "url('http://$plexServer:32400$art?X-Plex-Token=$plexToken')";
}
// Figure out which text goes where
switch($topSelection) {
case 'title': $topText = $mediaTitle;break;
case 'summary': $topText = $mediaSummary;break;
case 'tagline': $topText = $mediaTagline;break;
case 'custom': $topText = $isPlaying ? $nowShowingTopText : $comingSoonTopText;break;
}
switch($bottomSelection) {
case 'title': $bottomText = $mediaTitle;break;
case 'summary': $bottomText = $mediaSummary;break;
case 'tagline': $bottomText = $mediaTagline;break;
case 'custom': $bottomText = $isPlaying ? $nowShowingBottomText : $comingSoonBottomText;break;
}
// Set our stroke size and color for top and bottom
$topStrokeSize = $isPlaying ? $comingSoonTopFontOutlineSize : $nowShowingTopFontOutlineSize;
$topStrokeColor = $isPlaying ? $comingSoonTopFontOutlineColor : $nowShowingTopFontOutlineColor;
$bottomStrokeSize = $isPlaying ? $comingSoonBottomFontOutlineSize : $nowShowingBottomFontOutlineSize;
$bottomStrokeColor = $isPlaying ? $comingSoonBottomFontOutlineColor : $nowShowingBottomFontOutlineColor;
}
$topStyle = "color: ${topColor}; -webkit-text-stroke: ${topStrokeSize}px ${topStrokeColor};";
if (!$autoScaleTop) $topStyle .= "font-size: ${topSize}px;";
$topLine = "<div><span class='userText' style='$topStyle'> $topText</span></div>";
$bottomStyle = "color: ${bottomColor};";
if (!$autoScaleBottom) $bottomStyle .= "font-size: ${bottomSize}px;";
$bottomLine = "$scrollPrepend<div><span class='userText' style='$bottomStyle'>${bottomText}</span></div>$scrollAppend";
$results = [];
$results['top'] = $topLine;
$results['middle'] = $display;
$results['bottom'] = $bottomLine;
ob_end_clean();
echo json_encode($results);
die();
//Update Status
function updateStatus($lastNowShowing = "") {
$myFile = fopen("status.php", "w") or die("Unable to open file!");
fwrite($myFile, ' <?php $lastNowShowing = "' . $lastNowShowing. '";');
fclose($myFile);
}