nickbart / php-plex

A simple PHP library for interacting with the Plex HTTP Control API
61 stars 23 forks source link

playMedia not working for me? #1

Closed DreamStatic closed 11 years ago

DreamStatic commented 11 years ago

Hello, this is pretty awesome and very powerful. I am impressed with it so far, I am just having one issue with the Application Controller. The Navigation Controller is working so I know I am connected to the client, however; when I try to pass a TV episode or Movie to the Application Controller per the read me, nothing happens. I can echo out thumb, title, key, rating key, etc so I know I am finding the movie, just doesn't play it when I pass it into the controller. Any ideas what I am doing wrong? Thanks again for sharing this awesome bit of code with us laymen. :)

           $plexServers = array(
                'servername' => array(
                    'host' => '192.xxx.x.xxx'
                )
            );

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

            $plexServer = $plex->getServer('servername');
            $client = $plex->getClient('clientname');

            $plexMovies = $plexServer->getLibrary()->getSectionByKey(1);
            $plexTV = $plexServer->getLibrary()->getSectionByKey(2);

            $plexRetrievedMovie = $plexMovies->getMovie('Patriot Games');

            echo $plexRetrievedMovie->getTitle(); // returns Patriot Games
            echo $plexRetrievedMovie->getKey(); // /library/metadata/4479               

            $application = $client->getApplicationController();

            $episode = $plexTV
            ->getShow('Bones')
            ->getSeason(2)
            ->getEpisode(4);

           $application->playMedia($plexRetrievedMovie); // I didn't try these both at the same time, but wanted to show you how I am calling a movie and TV show.
            $application->playMedia($episode); // does not do anything
nickbart commented 11 years ago

Hi there, sorry for the delayed response and that you're having trouble. Can you var_dump the content of your $episode variable? I know you said you are retrieving it, I just want to get a look at it to make sure it's whole.

DreamStatic commented 11 years ago

Thank you for the reply, no worries at all for the delay. You are very kind for sharing this, so thanks for helping at all with my inability to get it working. :) Here is my Episode var_dump for Bones Season 2 Episode 4. And below that is my var_dump for Patriot Games movie. Thanks again, I sure appreciate your knowledge sharing.

VAR_DUMP = Bones Season 2 Episode 4:

object(Plex_Server_Library_Item_Episode)#98 (40) { ["grandparentRatingKey":protected]=> int(15229) ["grandparentKey":protected]=> string(23) "/library/metadata/15229" ["grandparentTitle":protected]=> string(5) "Bones" ["grandparentThumb":protected]=> string(40) "/library/metadata/15229/thumb/1359850753" ["duration":protected]=> int(2625000) ["viewOffset":protected]=> NULL ["parentRatingKey":protected]=> int(15253) ["parentKey":protected]=> string(23) "/library/metadata/15253" ["parentTitle":protected]=> NULL ["parentIndex":protected]=> int(2) ["parentThumb":protected]=> string(40) "/library/metadata/15253/thumb/1324716194" ["originallyAvailalbleAt":protected]=> NULL ["art":protected]=> string(38) "/library/metadata/15229/art/1359850753" ["leafCount":protected]=> NULL ["viewedLeafCount":protected]=> NULL ["year":protected]=> int(2006) ["rating":protected]=> float(7.3000001907349) ["contentRating":protected]=> string(5) "TV-14" ["allowSync":protected]=> NULL ["librarySectionId":protected]=> NULL ["ratingKey":protected]=> int(15257) ["key":protected]=> string(23) "/library/metadata/15257" ["type":protected]=> string(7) "episode" ["title":protected]=> string(22) "The Blonde in the Game" ["titleSort":protected]=> string(18) "Blonde in the Game" ["summary":protected]=> string(232) "After digging up the skeletal remains of a young girl, the investigation points to a convicted serial killer on death row. The team follows cryptic clues that lead to another body, an accomplice, and a victim who may still be alive." ["index":protected]=> int(4) ["thumb":protected]=> string(40) "/library/metadata/15257/thumb/1359850730" ["addedAt":protected]=> object(DateTime)#104 (3) { ["date"]=> string(19) "2011-04-20 02:30:18" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["updatedAt":protected]=> object(DateTime)#100 (3) { ["date"]=> string(19) "2013-02-03 00:18:50" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["refreshing":protected]=> NULL ["agent":protected]=> NULL ["scanner":protected]=> NULL ["language":protected]=> NULL ["uuid":protected]=> NULL ["createdAt":protected]=> NULL ["name":protected]=> string(9) "MultiPlex" ["address":protected]=> NULL ["port":protected]=> int(32400) ["originallyAvailableAt"]=> object(DateTime)#99 (3) { ["date"]=> string(19) "2006-09-20 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "America/Mexico_City" } }

VAR_DUMP = Patriot Games:

object(Plex_Server_Library_Item_Movie)#5 (42) { ["studio":"Plex_Server_Library_Item_Movie":private]=> string(18) "Paramount Pictures" ["tagline":"Plex_Server_Library_Item_Movie":private]=> string(55) "Not for honor. Not for country. For his wife and child." ["grandparentRatingKey":protected]=> NULL ["grandparentKey":protected]=> NULL ["grandparentTitle":protected]=> NULL ["grandparentThumb":protected]=> NULL ["duration":protected]=> int(7020000) ["viewOffset":protected]=> int(45754) ["parentRatingKey":protected]=> NULL ["parentKey":protected]=> NULL ["parentTitle":protected]=> NULL ["parentIndex":protected]=> NULL ["parentThumb":protected]=> NULL ["originallyAvailalbleAt":protected]=> NULL ["art":protected]=> string(37) "/library/metadata/4821/art/1361731919" ["leafCount":protected]=> NULL ["viewedLeafCount":protected]=> NULL ["year":protected]=> int(1992) ["rating":protected]=> NULL ["contentRating":protected]=> string(1) "R" ["allowSync":protected]=> bool(true) ["librarySectionId":protected]=> NULL ["ratingKey":protected]=> int(4821) ["key":protected]=> string(22) "/library/metadata/4821" ["type":protected]=> string(5) "movie" ["title":protected]=> string(13) "Patriot Games" ["titleSort":protected]=> NULL ["summary":protected]=> string(223) "Jack Ryan is on vacation in England when he spoils an assassination attempt on an important member of the Royal Family. Ryan gets drawn back into the CIA when the same splinter faction of the IRA targets him and his family." ["index":protected]=> NULL ["thumb":protected]=> string(39) "/library/metadata/4821/thumb/1361731919" ["addedAt":protected]=> object(DateTime)#14 (3) { ["date"]=> string(19) "2010-11-24 07:27:50" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["updatedAt":protected]=> object(DateTime)#35 (3) { ["date"]=> string(19) "2013-02-24 18:51:59" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["refreshing":protected]=> NULL ["agent":protected]=> NULL ["scanner":protected]=> NULL ["language":protected]=> NULL ["uuid":protected]=> NULL ["createdAt":protected]=> NULL ["name":protected]=> string(9) "MultiPlex" ["address":protected]=> NULL ["port":protected]=> int(32400) ["originallyAvailableAt"]=> object(DateTime)#33 (3) { ["date"]=> string(19) "1992-06-05 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "America/Mexico_City" } }

nickbart commented 11 years ago

Again, sorry for the delays. We'll get through this. Seems like you're connecting fine and everything looks good. If I'm right the endpoint for playing these files should look something like this:

Bones:

http://192.168.x.x:32400/system/players/192.168.x.x/application/playMedia?key=%2Flibrary%2Fmetadata%2F15257&path=http%3A%2F%2F192.168.x.x%3A32400%2Flibrary%2Fmetadata%2F15257

Patriot Games:

http://192.168.x.x:32400/system/players/192.168.x.x/application/playMedia?key=%2Flibrary%2Fmetadata%2F4821&path=http%3A%2F%2F192.168.x.x%3A32400%2Flibrary%2Fmetadata%2F4821

What happens when you just paste these URLs into your browser?

DreamStatic commented 11 years ago

Thanks for the help. Both urls work fine when pasting into browser. Very strange.

This is what I get if I var_dump($client):

object(Plex_Client)#3 (7) { ["host":"Plex_Client":private]=> string(13) "192.168.1.xxx" ["machineIdentifier":"Plex_Client":private]=> string(36) "0bba2d09-63a4-4fbb-a843-51963ddbea08" ["version":"Plex_Client":private]=> string(15) "0.9.5.4-f067f15" ["server":"Plex_Client":private]=> object(Plex_Server)#2 (3) { ["name":protected]=> string(9) "server name" ["address":protected]=> NULL ["port":protected]=> int(32400) } ["name":protected]=> string(11) "client name" ["address":protected]=> string(13) "192.168.1.xxx" ["port":protected]=> int(3000) }

This is what I get if I var_dump($application):

object(Plex_Client_Controller_Application)#9 (7) { ["host":"Plex_Client":private]=> NULL ["machineIdentifier":"Plex_Client":private]=> NULL ["version":"Plex_Client":private]=> NULL ["server":"Plex_Client":private]=> object(Plex_Server)#2 (3) { ["name":protected]=> string(9) "server name" ["address":protected]=> NULL ["port":protected]=> int(32400) } ["name":protected]=> string(11) "client name" ["address":protected]=> string(13) "192.168.1.xxx" ["port":protected]=> int(3000) }

nickbart commented 11 years ago

Very strange indeed. Tell me, can you var_dump the $url variable used on line 116 of MachineAbstract.php? I just want to make sure that it matches what you are putting into your browser. Maybe the software is messing it up somewhere.

DreamStatic commented 11 years ago

Looks like I was able to get it working by changing 'host' to 'address' and now it works as expected. You COMPLETELY rock for the support and sharing this sweet software!!!!

$plexServers = array( 'servername' => array( 'address' => '192.xxx.x.xxx' ) );

nickbart commented 11 years ago

D'oh! The README is wrong. I changed how that worked before I committed the code, but I'd already written the README. Glad you figured it out! Sorry, I didn't spot that sooner.

DreamStatic commented 11 years ago

You helped me realize the problem with the var_dump on the $url tip. Loving it!!! Nice work. :)

nickbart commented 11 years ago

Thanks! Let me know if you run into any more problems. I'm going to close this issue out and start working on better error handling.