Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Commit 1dab49f

Browse files
committed
Added search capability for TV shows.
1 parent 617e474 commit 1dab49f

File tree

2 files changed

+81
-4
lines changed

2 files changed

+81
-4
lines changed

Server/Library/Section/Show.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,27 @@ public function getContentRatings()
246246
)
247247
);
248248
}
249+
250+
/**
251+
* Searches show titles for the passed query and returns the shows that
252+
* match.
253+
*
254+
* @param string $query The search term against which the shows will be
255+
* matched.
256+
*
257+
* @uses Plex_Server_Library::getItems()
258+
* @uses Plex_Server_Library_SectionAbstract::buildSearchEndpoint()
259+
* @uses Plex_Server_Library_SectionAbstract::SEARCH_TYPE_SHOW
260+
*
261+
* @return Plex_Server_Library_Item_Show[] An array of show objects.
262+
*/
263+
public function searchShows($query)
264+
{
265+
return $this->getItems(
266+
$this->buildSearchEndpoint(
267+
Plex_Server_Library_SectionAbstract::SEARCH_TYPE_SHOW,
268+
$query
269+
)
270+
);
271+
}
249272
}

Server/Library/SectionAbstract.php

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ abstract class Plex_Server_Library_SectionAbstract extends Plex_Server_Library
106106
protected $createdAt;
107107

108108
/**
109-
* Endpoint for retrieiving all items for a section.
109+
* Endpoint for retrieving all items for a section.
110110
*/
111111
const ENDPOINT_CATEGORY_ALL = 'all';
112112

113113
/**
114-
* Endpoint for retrieiving all unwatched items for a section.
114+
* Endpoint for retrieving all unwatched items for a section.
115115
*/
116116
const ENDPOINT_CATEGORY_UNWATCHED = 'unwatched';
117117

@@ -151,10 +151,40 @@ abstract class Plex_Server_Library_SectionAbstract extends Plex_Server_Library
151151
const ENDPOINT_CATEGORY_GENRE = 'genre';
152152

153153
/**
154-
* Endpoint for retrieiving items for a sectoin by year.
154+
* Endpoint for retrieiving items for a section by year.
155155
*/
156156
const ENDPOINT_CATEGORY_YEAR = 'year';
157157

158+
/**
159+
* Endpoing for searching a section for items.
160+
*/
161+
const ENDPOINT_SEARCH = 'search';
162+
163+
/**
164+
* Parameter for searching movies.
165+
*/
166+
const SEARCH_TYPE_MOVIE = 1;
167+
168+
/**
169+
* Parameter for searching television shows.
170+
*/
171+
const SEARCH_TYPE_SHOW = 2;
172+
173+
/**
174+
* Parameter for searching teleivision episodes.
175+
*/
176+
const SEARCH_TYPE_EPISODE = 4;
177+
178+
/**
179+
* Parameter for searching artists.
180+
*/
181+
const SEARCH_TYPE_ARTIST = 8;
182+
183+
/**
184+
* Parameter for searching tracks.
185+
*/
186+
const SEARCH_TYPE_TRACK = 10;
187+
158188
/**
159189
* Adds the attributes to the object if they exist.
160190
*
@@ -220,7 +250,7 @@ public function setAttributes($attribute)
220250
* @uses Plex_Server_Library::ENDPOINT_SECTION
221251
* @uses Plex_Server_Library_SectionAbstract::getKey()
222252
*
223-
* @return void
253+
* @return string The requested endpoint.
224254
*/
225255
protected function buildEndpoint($endpoint)
226256
{
@@ -232,6 +262,30 @@ protected function buildEndpoint($endpoint)
232262
);
233263
}
234264

265+
/**
266+
* Builds an endpoint to search a Plex library section.
267+
*
268+
* @param integer $type The type of item to be searched.
269+
* @param string $query The string of text against which the search will be
270+
* run.
271+
*
272+
* @uses Plex_Server_Library_SectionAbstract::ENDPOINT_SEARCH
273+
* @uses Plex_Server_Library_SectionAbstract::buildEndpoint()
274+
*
275+
* @return string The requested search endpoint.
276+
*/
277+
protected function buildSearchEndpoint($type, $query)
278+
{
279+
$endpoint = sprintf(
280+
'%s?type=%d&query=%s',
281+
self::ENDPOINT_SEARCH,
282+
$type,
283+
trim($query)
284+
);
285+
286+
return $this->buildEndpoint($endpoint);
287+
}
288+
235289
/**
236290
* Generic method allowing a child class to retrieve all items for its
237291
* section.

0 commit comments

Comments
 (0)