chriscollins/php-plex

一个简单的PHP库,用于与Plex(http://plexapp.com)HTTP控制API交互。(从https://github.com/bonvga/php-plex分支而来)

dev-master 2015-03-15 15:32 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:33:14 UTC


README

一个简单的PHP库,用于与Plex(《http://plexapp.com》)HTTP控制API交互。

需求

php-curl simpleXML

功能

允许访问您的Plex媒体库,以便您可以通过多种方便的方式检索您的节目、季、剧集、电影、艺术家、专辑和曲目。

提供简单的播放和导航命令,并有一个播放剧集、电影和曲目的接口。

不支持的特性

照片功能尚未实现。

播放功能仅在剧集、电影和曲目级别实现。计划是向应用程序控制器传递季或专辑,并使其播放整个内容。

尚未为项目列表实现分页。

安装

使用Composer安装php-plex,只需将以下内容添加到您的'composer.json'文件中:

{
    require: {
        "bonvga/php-flex": "*",
        ...
    }
}

示例

设置

require_once('path/to/Plex.php');

$servers = array(
	'shepherd' => array(
		'address' => '192.168.11.9'
	)
);

$plex = new Plex();
$plex->registerServers($servers);

$server = $plex->getServer('shepherd');
$client = $plex->getClient('zoe');

在媒体库级别获取项目

// On deck and recently added items
$server->getLibrary()->getOnDeckItems();
$server->getLibrary()->getRecentlyAddedItems();

// Sections
$server->getLibrary()->getSections();
$server->getLibrary()->getSection('Movies');
$server->getLibrary()->getSection('TV Shows');
$server->getLibrary()->getSection('Music');

电影

// Lists of movies
$section->getAllMovies();
$section->getUnwatchedMovies();
$section->getRecentlyReleasedMovies();
$section->getRecentlyAddedMovies();
$section->getRecentlyViewedMovies();
$section->getOnDeckMovies();
$section->getMoviesByYear(1983);
$section->getMoviesByDecade(1980);
$section->getMoviesByContentRating('R');
$section->getMoviesByResolution('1080');
$section->getMoviesByFirstCharacter('Q');

// Single movies

// Exact title
$section->getMovie('Heavy Metal in Baghdad');
// Rating key
$section->getMovie(83696);
// Key
$section->getMovie('/library/metadata/83696');

// Collections
$section->getCollections();
$section->getMoviesByCollection(13206);

// Genres
$section->getGenres();
$section->getMoviesByGenre(1252);

// Directors
$section->getDirectors();
$section->getMoviesByDirector(357);

// Actors
$section->getActors();
$section->getMoviesByActor(3903);

// Search
$section->searchMovies('fly');

节目、季和剧集

// Lists of shows
$section->getAllShows();
$section->getUnwatchedShows();
$section->getShowsByFirstCharacter('Q');
$section->getShowsByYear(1983);
$section->getShowsByContentRating('TV-MA');

// Single shows
// Exact title
$section->getShow('Firefly');
// Rating key
$section->getShow(46585);
// Key
$section->getShow('/library/metadata/46585');

// Lists of episodes
$section->getRecentlyAiredEpisodes();
$section->getRecentlyAddedEpisodes();
$section->getRecentlyViewedEpisodes();
$section->getOnDeckEpisodes();

// Single episodes
// Exact title
$section->getEpisode('Crucifixed');
// Rating key
$section->getEpisode(83780);
// Key
$section->getEpisode('/library/metadata/83780');

// Collections
$section->getCollections();
$section->getShowsByCollection(13205);

// Genres
$section->getGenres();
$section->getShowsByGenre(8196);

// Search
$section->searchShows('fly');
$section->searchEpisodes('fly');

// By show
$show = $showSection->getShow('Peep Show');
$seasons = $show->getSeasons();
$seasonByIndex = $show->getSeason(2);
$seasonByKey = $show->getSeason('/library/metadata/3112');
$seasonByExactTitleMatch = $show->getSeason('Season 2');
$episodes = $seasonByIndex->getEpisodes();
$episodeByIndex = $seasonByIndex->getEpisode(4);
$episodeByKey = $seasonByIndex->getEpisode('/library/metadata/3116');
$episodeByExactTitleMatch = $seasonByIndex->getEpisode('University Challenge');

艺术家、专辑和曲目

// Lists of artists
$section->getAllArtists();

// Single artists
// Exact title
$section->getArtist('Acrassicauda');
// Rating key
$section->getArtist(83757);
// Key
$section->getArtist('/library/metadata/83757');

// Collections
$section->getCollections()
$section->getArtistsByCollection(13206);

// Genres
$section->getGenres();
$section->getArtistsByGenre(11644);

// Albums
$section->getAllAlbums();
$section->getAlbumsByDecade(1980);
$section->getAlbumsByYear(1983);
$section->getRecentlyAddedAlbums();

// Single tracks
// Exact title
$section->getTrack('Can\'t Buy Me Love');
// Rating key
$section->getTrack(67962);
// Key
$section->getTrack('/library/metadata/67962');

// Search
$section->searchArtists('fly');
$section->searchTracks('fly');

// By artist
$artist = $artistSection->getArtist('Paolo Nutini');
$albums = $artist->getAlbums();
$albumByKey = $artist->getAlbum('/library/metadata/57718');
$albumByExactTitleMatch = $artist->getAlbum('These Streets');
$tracks = $albumByExactTitleMatch->getTracks();
$trackByIndex = $albumByExactTitleMatch->getTrack(3);
$trackByKey = $albumByExactTitleMatch->getTrack('/library/metadata/57726');
$trackByExactTitleMatch = $albumByExactTitleMatch->getTrack('Rewind');

项目媒体信息

$showSection = $library->getSection('TV Shows');
$episode = $showSection->getShow("The Simpsons")
	->getSeason(4)
	->getEpisode(12);

// Media Info
$media = $episode->getMedia();
$duration = $media->getDuration();
$bitrate = $media->getBitrate();

// File
$file = reset($media->getFiles());
$path = $file->getFile();
$size = $file->getSize();

播放控制器

$playback = $client->getPlaybackController();
$playback->play();
$playback->pause();
$playback->stop();
$playback->rewind();
$playback->fastForward();
$playback->stepForward();
$playback->bigStepForward();
$playback->stepBack();
$playback->bigStepBack();
$playback->skipNext();
$playback->skipPrevious();

导航控制器

$navigation = $client->getNavigationController();
$navigation->moveUp();
$navigation->moveDown();
$navigation->moveLeft();
$navigation->moveRight()
$navigation->pageUp();
$navigation->pageDown();
$navigation->nextLetter();
$navigation->previousLetter();
$navigation->select();
$navigation->back();
$navigation->contextMenu();
$navigation->toggleOSD();

应用程序控制器

$application = $client->getApplicationController();

$episode = $section
	->getShow('It\'s Always Sunny in Philadelphia')
	->getSeason(5)
	->getEpisode(4);

// Play episode from beginning
$application->playMedia($episode);

// Play epsiode from where it was last stopped
$application->playMedia($episode, $episode->getViewOffset());

// Set voume to half
$application->setVolume(50);