Hi Everyone,
I’ve been using Plex for a long time (despite my forum profile I’m a long-time user and PlexPass member) and I just wanted to let the developers out there know that I created a PHP library for the Plex HTTP Control API. It’s fairly complete, but there are still some things in the works:
Photos have not been implemented yet.
Playback is only implemented at the episode, movies, and track level. The plan is to implement passing a season or album to the application controller and have it play through the entire thing.
Paging has not been implemented for lists of items.
There is no proper error handling, things just tend to fail silently. More explicit error handling will be added at a later date.
I have put the code up on GitHub, so I’m hoping there are some PHP developers out there who’ll try it out and give me some feedback.
php-plex on GitHub
Thanks!
This looks very cool! Thank you for sharing. Do you happen to have a simple php file that shows the complete structure of a working page?
Thank you for creating this! I’ve been looking for such a resource for some script programming! You sir are a god amongst men! … okay maybe I am going a bit far here, but I think you get my appreciation. 
Hey guys, sorry I took so long to respond, seems like I'm not getting emails on replies. DreamStatic, I think we connected over GitHub! Sean, thanks a lot! I hope you find it useful.
Released a new version of php-plex: https://github.com/nickbart/php-plex/tree/0.0.2
I've added in better error handling and an easier way to get sections.
Hi.
I'm trying to use this to make a php file just displaying the recently added tv episodes.
But I'm not sure how to use this script.
I tried this:
<?php
require_once('plexphp/Plex.php');
$servers = array(
'iMini' => array(
'address' => '10.0.1.2'
)
);
$plex = new Plex();
$plex->registerServers($servers);
$server = $plex->getServer('iMini');
$client = $plex->getClient('iPhp');
$server->getLibrary()->getRecentlyAddedItems();
?>
But that outputs nothing.
It seems like $server->getLibrary()->getRecentlyAddedItems(); is a array with a object inside of it.
I would just like to make a loop of all the parentTitle(title of the show).
But when i try it just sends me an error that it's protected.
Any hints on how to do this ? :)
I know some php but not so great with arrays and objects.
Sorry you're having trouble. There's nothing in your code snippet that would produce any output. What happens if you wrap the last line in a var_dump? Like this:
var_dump($server->getLibrary()->getRecentlyAddedItems());
Also, you should be able to get what you are looking for thusly:
$parentTitles = array();
foreach ($server->getLibrary()->getRecentlyAddedItems() as $item) {
$parentTitles[] = $item->getParentTitle();
}
var_dump($parentTitles);
However, not all items have parent titles, like movies, so you might check the type of object before trying to execute getParentTitle().
Hi
I'm looking to use your library in my own small project. I'm successful in using the library, though I was wondering if it's at all possible to get original filename and/or original path to file from it?
Hi
I'm looking to use your library in my own small project. I'm successful in using the library, though I was wondering if it's at all possible to get original filename and/or original path to file from it?
Hi cruzher,
Thanks for using the library! You know, I believe what you're looking for is stored in the item metadata. I never wrote a way to access that info, so now it looks like I should. Assuming the file path is stored there, I can definitely write a way to access it. I can probably get a new version out in a week or so with this feature added. Is that too long?
Hi cruzher,
Thanks for using the library! You know, I believe what you're looking for is stored in the item metadata. I never wrote a way to access that info, so now it looks like I should. Assuming the file path is stored there, I can definitely write a way to access it. I can probably get a new version out in a week or so with this feature added. Is that too long?
That would be great :) thanks for the quick answer.
I'm guessing its possible because if you use the web interface of the server and navigate to an episode or a movie and the press the info button to the left you can se the filepath and by clicking view XML you can se the structure of the API.
I'm guessing its possible because if you use the web interface of the server and navigate to an episode or a movie and the press the info button to the left you can se the filepath and by clicking view XML you can se the structure of the API.
Yes, you are exactly right. It's all stored in XML nodes I simply haven't surfaced with PHP yet. It will take a bit of work to get all the info surface, but I think I can have a "partial release" done very soon that will at least give you access to the file path. Then I can fill it in and do a "whole release" afterward. Keep watching GitHub and hopefully I'll have something out this weekend.
I was wondering if it's at all possible to get original filename and/or original path to file from it?
Just a quick update: I just tagged a new release that adds this functionality in: https://github.com/nickbart/php-plex/tree/0.0.2.5
You should be able to get what you want now by doing something like this:
$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(); // This should give you what you are asking for.
$size = $file->getSize();
It doesn't include the video and audio sections of the file. I'll be working on that next. Let me know if this works for you or if you need any help.
Again, thanks for using the library!
Just a quick update: I just tagged a new release that adds this functionality in: https://github.com/nickbart/php-plex/tree/0.0.2.5
You should be able to get what you want now by doing something like this:
$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(); // This should give you what you are asking for.
$size = $file->getSize();
It doesn't include the video and audio sections of the file. I'll be working on that next. Let me know if this works for you or if you need any help.
Again, thanks for using the library!
Thanks for all your help, I'm working slowly on my project.
noticed on your github that you wrote this.
// File $file = reset($media->getFile()); $path = $file->getFile(); $size = $file->getSize();
Shouldn't it be like this?
// File $file = reset($media->getFiles()); $path = $file->getFile(); $size = $file->getSize();
That small typo could frustrate someone :P
Also there is another thing I was wondering, I can se the "leafcount/viewedleafcount" down to the season level but not per episode, is this something you will add? It would be extremly useful to me.
Yeah, I noticed that mistake. I've actually fixed it in master and develop, but it's still wrong in the 0.0.2.5 tag. I should probably retag it.
I can se the "leafcount/viewedleafcount" down to the season level but not per episode, is this something you will add? It would be extremly useful to me.
I'll look into that. Basically are you trying to see from a single item whether or not it's been watched?
Yeah, I noticed that mistake. I've actually fixed it in master and develop, but it's still wrong in the 0.0.2.5 tag. I should probably retag it.
I'll look into that. Basically are you trying to see from a single item whether or not it's been watched?
Exactly, In this senario I want to make a list of all the episodes that is still unwatched.
Exactly, In this senario I want to make a list of all the episodes that is still unwatched.
I'm fairly certain I can add this in. It'll be a good feature. I'll see if I can fit in with 0.0.3. Not sure when that will be available. Hopefully in the next week or so.
Good afternoon, I am beginner with PLEX and I'm doubt where I put the folder php-0.0.2-plex? and how to configure the files? someone could help me with that?
Good afternoon, I am beginner with PLEX and I'm doubt where I put the folder php-0.0.2-plex? and how to configure the files? someone could help me with that?
Hi there, no worries. You can pretty much put that directory anywhere in your project you like. Say you have a directory structure like this:
eliabeandrade-project
|
|
|___ ___ ___ php-plex-0.0.2 (directory)
|
|
|___ ___ ___ index.php (file)
So, you have a single directory called eliabeandrade-project and inside that you have the php-plex-0.0.2 library directory and a very simple index.php file. To use the php-plex library your index.php would look like this:
<?php
require_once('./php-plex-0.0.2/Plex.php');
// Then you can pretty much follow the README
$servers = array(
'name-of-server' => array(
'address' => '192.168.11.9'
)
);
$plex = new Plex();
$plex->registerServers($servers);
$server = $plex->getServer('name-of-server');
The important part is including Plex.php. As long as the directory structure of php-plex-0.0.2 is maintained, Plex.php should find all the other files it needs and bootstrap them accordingly. But essentially, you can put the php-plex-0.0.2 directory anywhere you want. You can also name it anything you want. What's important is that your application can include Plex.php and that the directory structure of the php-plex-0.0.2 is maintained.
Hopefully that helps you get started. Let me know if yo have any other questions.
Hi there, no worries. You can pretty much put that directory anywhere in your project you like. Say you have a directory structure like this:
eliabeandrade-project
|
|
|___ ___ ___ php-plex-0.0.2 (directory)
|
|
|___ ___ ___ index.php (file)
So, you have a single directory called eliabeandrade-project and inside that you have the php-plex-0.0.2 library directory and a very simple index.php file. To use the php-plex library your index.php would look like this:
<?php require_once('./php-plex-0.0.2/Plex.php'); // Then you can pretty much follow the README $servers = array( 'name-of-server' => array( 'address' => '192.168.11.9' ) ); $plex = new Plex(); $plex->registerServers($servers); $server = $plex->getServer('name-of-server');The important part is including Plex.php. As long as the directory structure of php-plex-0.0.2 is maintained, Plex.php should find all the other files it needs and bootstrap them accordingly. But essentially, you can put the php-plex-0.0.2 directory anywhere you want. You can also name it anything you want. What's important is that your application can include Plex.php and that the directory structure of the php-plex-0.0.2 is maintained.
Hopefully that helps you get started. Let me know if yo have any other questions.
excuse my lack of understanding, it will be that he had the ability to put a video demonstrating the procedure?I am Brazilian and I'm using google translator to be able to communicate.
Hey eliabeandrade, sorry for the late reply. I'll try to put something together to better help you. I'll PM you, so we can keep the noise out of this thread.