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 artists and tracks to the artist section.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbart committed Dec 23, 2012
1 parent 3d6c79d commit 6910738
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions Plex.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
require_once(sprintf('%s/Server/Library/Item/Episode.php', $phpPlexDir));
require_once(sprintf('%s/Server/Library/Item/Artist.php', $phpPlexDir));
require_once(sprintf('%s/Server/Library/Item/Album.php', $phpPlexDir));
require_once(sprintf('%s/Server/Library/Item/Track.php', $phpPlexDir));
require_once(sprintf('%s/Client.php', $phpPlexDir));

/**
Expand Down
92 changes: 92 additions & 0 deletions Server/Library/Item/Track.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

/**
* Plex Library Track
*
* @category php-plex
* @package Plex_Server
* @subpackage Plex_Server_Library
* @author <[email protected]> Nick Bartkowiak
* @copyright (c) 2012 Nick Bartkowiak
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3)
* @version 0.0.1
*
* This file is part of php-plex.
*
* php-plex is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* php-plex is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

/**
* Represents a Plex track.
*
* @category php-plex
* @package Plex_Server
* @subpackage Plex_Server_Library
* @author <[email protected]> Nick Bartkowiak
* @copyright (c) 2012 Nick Bartkowiak
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3)
* @version 0.0.1
*/
class Plex_Server_Library_Item_Track
extends Plex_Server_Library_ItemChildAbstract
{
/**
* Original title of the artist.
* @var string
*/
private $originalTitle;

/**
* Sets an array of attributes, if they exist, to the corresponding class
* member.
*
* @param array $attribute An array of item attributes as passed back by the
* Plex HTTP API.
*
* @uses Plex_Server_Library_ItemAbstract::setAttributes()
*
* @return void
*/
public function setAttributes($attribute)
{
parent::setAttributes($attribute);

if (isset($attribute['originalTitle'])) {
$this->setOriginalTitle($attribute['originalTitle']);
}
}

/**
* Returns the original title.
*
* @uses Plex_Server_Library_Item_Track::$originalTitle
*
* @return string The original title.
*/
public function getOriginalTitle()
{
return $this->originalTitle;
}
/
/**
* Sets the original title.
*
* @param string $originalTitle The original title.
*
* @uses Plex_Server_Library_Item_Track::$originalTitle
*
* @return void
*/
public function setOriginalTitle($originalTitle)
{
$this->originalTitle = $originalTitle;
}
}
46 changes: 46 additions & 0 deletions Server/Library/Section/Artist.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,50 @@ public function getRecentlyAddedAlbums()
{
return $this->getRecentlyAddedSectionItems();
}

/**
* Searches artist titles for the passed query and returns the artists that
* match.
*
* @param string $query The search term against which the artists will be
* matched.
*
* @uses Plex_Server_Library::getItems()
* @uses Plex_Server_Library_SectionAbstract::buildSearchEndpoint()
* @uses Plex_Server_Library_SectionAbstract::SEARCH_TYPE_ARTIST
*
* @return Plex_Server_Library_Item_Artist[] An array of artist objects.
*/
public function searchArtists($query)
{
return $this->getItems(
$this->buildSearchEndpoint(
Plex_Server_Library_SectionAbstract::SEARCH_TYPE_ARTIST,
$query
)
);
}

/**
* Searches track titles for the passed query and returns the tracks that
* match.
*
* @param string $query The search term against which the tracks will be
* matched.
*
* @uses Plex_Server_Library::getItems()
* @uses Plex_Server_Library_SectionAbstract::buildSearchEndpoint()
* @uses Plex_Server_Library_SectionAbstract::SEARCH_TYPE_TRACK
*
* @return Plex_Server_Library_Item_Track[] An array of track objects.
*/
public function searchTracks($query)
{
return $this->getItems(
$this->buildSearchEndpoint(
Plex_Server_Library_SectionAbstract::SEARCH_TYPE_TRACK,
$query
)
);
}
}

0 comments on commit 6910738

Please sign in to comment.