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

Commit

Permalink
Added search capability for TV shows.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbart committed Dec 23, 2012
1 parent 617e474 commit 1dab49f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
23 changes: 23 additions & 0 deletions Server/Library/Section/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,27 @@ public function getContentRatings()
)
);
}

/**
* Searches show titles for the passed query and returns the shows that
* match.
*
* @param string $query The search term against which the shows will be
* matched.
*
* @uses Plex_Server_Library::getItems()
* @uses Plex_Server_Library_SectionAbstract::buildSearchEndpoint()
* @uses Plex_Server_Library_SectionAbstract::SEARCH_TYPE_SHOW
*
* @return Plex_Server_Library_Item_Show[] An array of show objects.
*/
public function searchShows($query)
{
return $this->getItems(
$this->buildSearchEndpoint(
Plex_Server_Library_SectionAbstract::SEARCH_TYPE_SHOW,
$query
)
);
}
}
62 changes: 58 additions & 4 deletions Server/Library/SectionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ abstract class Plex_Server_Library_SectionAbstract extends Plex_Server_Library
protected $createdAt;

/**
* Endpoint for retrieiving all items for a section.
* Endpoint for retrieving all items for a section.
*/
const ENDPOINT_CATEGORY_ALL = 'all';

/**
* Endpoint for retrieiving all unwatched items for a section.
* Endpoint for retrieving all unwatched items for a section.
*/
const ENDPOINT_CATEGORY_UNWATCHED = 'unwatched';

Expand Down Expand Up @@ -151,10 +151,40 @@ abstract class Plex_Server_Library_SectionAbstract extends Plex_Server_Library
const ENDPOINT_CATEGORY_GENRE = 'genre';

/**
* Endpoint for retrieiving items for a sectoin by year.
* Endpoint for retrieiving items for a section by year.
*/
const ENDPOINT_CATEGORY_YEAR = 'year';

/**
* Endpoing for searching a section for items.
*/
const ENDPOINT_SEARCH = 'search';

/**
* Parameter for searching movies.
*/
const SEARCH_TYPE_MOVIE = 1;

/**
* Parameter for searching television shows.
*/
const SEARCH_TYPE_SHOW = 2;

/**
* Parameter for searching teleivision episodes.
*/
const SEARCH_TYPE_EPISODE = 4;

/**
* Parameter for searching artists.
*/
const SEARCH_TYPE_ARTIST = 8;

/**
* Parameter for searching tracks.
*/
const SEARCH_TYPE_TRACK = 10;

/**
* Adds the attributes to the object if they exist.
*
Expand Down Expand Up @@ -220,7 +250,7 @@ public function setAttributes($attribute)
* @uses Plex_Server_Library::ENDPOINT_SECTION
* @uses Plex_Server_Library_SectionAbstract::getKey()
*
* @return void
* @return string The requested endpoint.
*/
protected function buildEndpoint($endpoint)
{
Expand All @@ -232,6 +262,30 @@ protected function buildEndpoint($endpoint)
);
}

/**
* Builds an endpoint to search a Plex library section.
*
* @param integer $type The type of item to be searched.
* @param string $query The string of text against which the search will be
* run.
*
* @uses Plex_Server_Library_SectionAbstract::ENDPOINT_SEARCH
* @uses Plex_Server_Library_SectionAbstract::buildEndpoint()
*
* @return string The requested search endpoint.
*/
protected function buildSearchEndpoint($type, $query)
{
$endpoint = sprintf(
'%s?type=%d&query=%s',
self::ENDPOINT_SEARCH,
$type,
trim($query)
);

return $this->buildEndpoint($endpoint);
}

/**
* Generic method allowing a child class to retrieve all items for its
* section.
Expand Down

0 comments on commit 1dab49f

Please sign in to comment.