-
Notifications
You must be signed in to change notification settings - Fork 0
/
menuItems.php
284 lines (257 loc) · 9.08 KB
/
menuItems.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
include_once 'config.php';
include_once 'data.php';
include_once 'utils.php';
$useSeasonNameForMenuItems = true;
$episodeNameInTitle = false;
//2 API calls total for series
//1 here + 1 in parse(episode)
function parseSeries($item)
{
global $libraryBrowse;
if ($item->UserData->Played || $libraryBrowse) {
return parse($item);
} else {
//gets first unwatched episode for this series
//sorting by Premiere Date - not quite right for dvd ordered series
//but next up doesn't work right after show is deleted
$params = new UserItemsParams();
$params->Limit = 1;
$params->ParentID = $item->Id;
$params->SortBy = 'PremiereDate';
$params->IncludeItemTypes = ItemType::EPISODE;
$params->GroupItems = true;
$params->IsPlayed = false;
$params->Recursive = true;
$unwatched = getUsersItems($params);
$first_unwatched = $unwatched->Items[0];
$first_unwatched->UserData->UnplayedItemCount = $item->UserData->UnplayedItemCount;
return parse($first_unwatched);
}
}
function parse($item)
{
global $indexStyle;
$menuItem = new stdClass();
// massage recordings to look like final output
if ($item->Type == ItemType::RECORDING && $item->IsSeries) {
// treat it like an episode
$item->Type = ItemType::EPISODE;
$item->Name = $item->EpisodeTitle;
}
$menuItem->Name = getName($item);
$menuItem->Subtitle = getSubtitle($item);
$menuItem->BackdropID = getBackdropIDandTag($item)->Id;
setDetailURL($item, $menuItem);
setPosterInfo($item, $menuItem);
if ($menuItem->PosterID) {
$imageProps = new ImageParams();
$imageProps->height = ($indexStyle->popupHeight ?? $indexStyle->thumbnailsHeight);
$imageProps->width = ($indexStyle->popupWidth ?? $indexStyle->thumbnailsWidth);
$imageProps->setIndicators($item);
$menuItem->PosterURL = getImageURL($menuItem->PosterID, $imageProps, $menuItem->ImageType);
} elseif ($item->Type == ItemType::ACTOR || $item->Type == ItemType::GUESTSTAR) {
$menuItem->PosterID = -1;
$menuItem->PosterURL = 'images/person/person' . rand(1, 5) . '.png';
}
return $menuItem;
}
function getName($item)
{
global $episodeNameInTitle;
if ($item->Type == ItemType::EPISODE) {
if ($episodeNameInTitle) {
$name = $item->IndexNumber . '. ' . $item->Name;
} else {
$name = $item->SeriesName;
}
} else {
$name = $item->Name;
}
return $name;
}
function getSubtitle($item)
{
global $useSeasonNameForMenuItems, $prettySpecialFeatures, $episodeNameInTitle;
switch ($item->Type) {
case ItemType::EPISODE:
if ($useSeasonNameForMenuItems) {
$subtitle = $item->SeasonName;
} else {
if (!$episodeNameInTitle) {
$subtitle = 'S' . $item->ParentIndexNumber . ':E' . $item->IndexNumber . ' - ' . $item->Name;
}
}
break;
case ItemType::SERIES:
$subtitle = ProductionRangeString($item);
break;
//PersonTypes
case ItemType::ACTOR:
case "Director":
case "Writer":
case "Producer":
case ItemType::GUESTSTAR:
case "Composer":
case "Conductor":
case "Lyricist":
$subtitle = ($item->Role ? "as " . $item->Role : $item->Type);
if ($subtitle == ItemType::GUESTSTAR) {
$subtitle = "Guest star";
}
break;
default:
$subtitle = $item->ProductionYear;
if ($item->ExtraType) {
if ($item->ExtraType !== 'Unknown') {
$subtitle = $prettySpecialFeatures[$item->ExtraType];
} else {
$subtitle = ' ';
}
}
break;
}
return $subtitle;
}
function getFolderURL($item, $menuItem)
{
global $forceItemDetails;
//set up default browsing params
$cbp = new CategoryBrowseParams();
$cbp->name = $item->Name;
$cbp->folderType = $item->Type;
$cbp->collectionType = $item->CollectionType;
$cbp->params->ParentID = $item->Id;
$cbp->backdropId = $menuItem->BackdropID;
switch ($item->Type) {
case ItemType::COLLECTIONFOLDER:
case ItemType::USERVIEW:
//set topParentId from Id
$cbp->name = null;
$cbp->topParentId = $item->Id;
$cbp->topParentName = $item->Name;
$detailURL = categoryBrowseURLEx($cbp);
break;
case ItemType::SEASON:
$detailURL = "Season.php?id=" . $item->Id;
break;
case ItemType::SERIES:
//go directly to season page, or continue to default
if ($item->ChildCount == 1) {
$detailURL = "seasonRedirect.php?SeasonType=first&SeriesId=" . $item->Id;
break;
}
default:
//get topParentId from querystring
$cbp->topParentId = $_GET['topParentId'];
$cbp->topParentName = $_GET['topParentName'];
$detailURL = categoryBrowseURLEx($cbp);
break;
}
if ($forceItemDetails) {
//default to itemDetails page
$detailURL = itemDetailsLink($item->Id);
}
return $detailURL;
}
function getNonFolderURL($item, $menuItem)
{
global $forceItemDetails, $regularSeason;
$regularSeason = null;
switch ($item->MediaType) {
case "Video":
if ($item->Type == ItemType::EPISODE) {
//check for season info, very rarely an episode has no season IDs provided
if ($item->SeasonId) {
$detailURL = "Season.php?id=" . $item->SeasonId . "&episode=" . $item->IndexNumber;
//for specials check airs[after|before] info and display that season
//but seasonID for airs season not included
$specialInSeason = $item->AirsBeforeSeasonNumber ?? $item->AirsAfterSeasonNumber;
if ($specialInSeason) {
$regularSeason = getSeasonFromSeriesBySeasonNumber($item->SeriesId, $specialInSeason);
$detailURL = "Season.php?id=" . $regularSeason->Id . "&episode=" . $item->IndexNumber . "&special";
}
} else {
//try season redirect, latest season will probably be the one that doesn't have all metadata
//I think this is why an episode won't have a seasonID
$detailURL = "seasonRedirect.php?SeasonType=latest&SeriesId=" . $item->SeriesId
. "&IndexNumber=" . $item->IndexNumber;
}
}
break;
case "Audio":
$detailURL = translatePathToNMT($item->Path);
$menuItem->OnDemandTag = "AOD";
break;
case "Photo":
$detailURL = translatePathToNMT($item->Path);
$menuItem->OnDemandTag = "POD";
break;
default:
break;
}
if (!$detailURL || $forceItemDetails) {
//default to itemDetails page
$detailURL = itemDetailsLink($item->Id);
}
return $detailURL;
}
function setDetailURL($item, $menuItem)
{
if ($item->IsFolder) {
$detailURL = getFolderURL($item, $menuItem);
} else {
$detailURL = getNonFolderURL($item, $menuItem);
}
$menuItem->DetailURL = $detailURL;
}
function getEpisodePosterID($item, $useSeasonImage)
{
global $indexStyle, $regularSeason;
//check for special in a regular season
$seasonID = is_null($regularSeason) ? $item->SeasonId : $regularSeason->Id;
//API
if ($useSeasonImage && itemImageExists($seasonID, $indexStyle->ImageType)) {
return $seasonID;
} else {
return $item->SeriesPrimaryImageTag ? $item->SeriesId : null;
}
}
function setPosterInfo($item, $menuItem)
{
global $indexStyle;
global $displayepisode;
$menuItem->ImageType = $indexStyle->ImageType;
switch ($item->Type) {
case ItemType::SEASON:
$posterID = $item->ImageTags->{$indexStyle->ImageType} ? $item->Id : $item->SeriesId;
break;
case ItemType::EPISODE:
if (!$displayepisode) {
$posterID = getEpisodePosterID($item, true);
break;
}
default:
if ($item->ImageTags) {
$posterID = $item->ImageTags->{$indexStyle->ImageType} ? $item->Id : null;
} else {
$posterID = $item->PrimaryImageTag ? $item->Id : null;
}
if (!$posterID && $item->MediaType == 'Video') {
//show parent thumb instead
$menuItem->ImageType = ImageType::THUMB;
$posterID = $item->ParentThumbItemId;
}
break;
}
$menuItem->PosterID = $posterID;
}
function getMenuItem($item)
{
if ($item->Type == ItemType::SERIES) {
$menuItem = parseSeries($item);
} else {
$menuItem = parse($item);
}
return $menuItem;
}