Giter Club home page Giter Club logo

Comments (43)

pkkid avatar pkkid commented on May 5, 2024

I'll have to review all the examples, sorry about that.

  1. The first one should read client.title. Plex used to return this as name but has since been updated.
  2. Unfortunately there is no ability to play a full playlist, just individual media items. It's up to the media player (or user of the API) to implement playing the next items. I believe the official PlexWebClient somehow monitors when items finish and play the next items as well (but I admit I haven't looked to deep into it). Both Photo and Playlist support are very new, you might be one of the first people to use them.

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

Michael, you are doing a great service by providing this api package. I don't mind piloting the new photo and playlist features. I can write a loop over each item. Play an item, wait for 30 secs and movevto next and so on. A few questions :

  1. How do I play an item in a playlist in the body of the loop? Client.playMedia (item) where the item is an item in the playlist, did not work.
  2. More generally, I have a list of photos under the photo section of the library with a directory structure of foo/bar. That is, bar is a directory under foo and foo is under the photo section of library. Now bar has the photos I want to display on client. How do I loop over each photo without adding them to a playlist?

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

Hi
Any update on this?

thanks

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Ahh sorry, I have been quiet. I meant to reply sooner.

What I generally do to add something to the API is check to see what the Plex WebClient is doing by turning on the dev tools in Chrome, doing the action I want to mimick, and watching what requests its making. I am not 100% sure that Plex Server can't play playlists, we should double check with the WebClient there.

To answer your questions:

  1. Are you calling PlexClient.playMedia() directly, or getting a proper PlexClient object from PlexServer? -- There is an example in tests/tests.py named test_playlist() that might serve as a good starting point. But the test doesn't actually wait for the first item to finish in the playlist to see if the second item plays automatically (I should definitely add that).
def test_playlist(plex, account=None):
    client = plex.client(name)
    artist = plex.library.section(AUDIO_SECTION).get(AUDIO_ARTIST)
    album = artist.album(AUDIO_ALBUM)
    playlist = plex.createPlaylist('test_play_playlist', album)
    log(2, 'Playing playlist: %s' % playlist)
    client.playMedia(playlist)
    time.sleep(5)
    log(2, 'stop..')
    client.stop('music'); time.sleep(1)
  1. For this one, I might refer to the test_list_photoalbums() in the tests. That should be a good example at finding an album and looping through the photos in there.
def test_list_photoalbums(plex, account=None):
    photosection = plex.library.section(PHOTO_SECTION)
    photoalbums = photosection.all()
    log(2, 'Listing albums..')
    for album in photoalbums[:10]:
        log(4, '%s' % album.title)
    assert len(photoalbums), 'No photoalbums found.'
    album = photosection.get(PHOTO_ALBUM)
    photos = album.photos()
    for photo in photos[:10]:
        log(4, '%s (%sx%s)' % (basename(photo.media[0].parts[0].file), photo.media[0].width, photo.media[0].height))
    assert len(photoalbums), 'No photos found.'

When I get a chance I'll try adding more thorough tests around the playlist actions and solidify that a bit more as well.

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

I get the proper client object from the server. My playlist has just 2 photos. When I do client.playMedia(playlist), the first photo plays and then I get the following error:

client.playMedia(playlist)`
File "<string>", line unknown
ParseError: syntax error: line 1, column 0

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Sounds like we just need more testing there. I'll take a look this week.

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

Thanks, Michael. I also looked at your test_list_photoalbums function. In the for loop where you get each photo, your are displaying a log message. But how do I play it on a client?
client.playMedia(photo) doesn't work. Is there some other API to display the photo o the client?

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

I'll check that as well when I dig in. I'm not sure how the Plex WebClient displays it offhand.

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

Hi
I played around with the test_list_photoalbums code that you posted above. I had to make a few changes since PHOTO_SECTION (replaced with 'Photos'), log (replaced with print) did not work and basename was not defined. Here is the code that prints the title of the photo correctly:

def test_list_photoalbums(plex,client):
   # for section in plex.library.sections():
    #    print (section.title)
    photosection = plex.library.section('Photos')
    photoalbums = photosection.all()
    print( 'Listing albums..')
    for album in photoalbums[:1]:
        print('%s' % album.title)
        photos = album.photos()
        for photo in photos[:1]:
            print('%s' % photo.title)
    return photo

Now instead of printing the title, I want to play it on my phone which is connected to the server. If I replace the print('%s' % photo.title) with client.playMedia(photo) I get the following error:


--------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-52-1ea28ea8a050> in <module>()
----> 1 client.playMedia(photo)

C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\client.py in playMedia(self, media, **params)
    145             raise Unsupported('A server must be specified before using this command.')
    146         server_url = media.server.baseurl.split(':')
--> 147         playqueue = self.server.createPlayQueue(media)
    148         self.sendCommand('playback/playMedia', **dict({
    149             'machineIdentifier': self.server.machineIdentifier,

C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\server.py in createPlayQueue(self, item)
     78 
     79     def createPlayQueue(self, item):
---> 80         return PlayQueue.create(self, item)
     81 
     82     def headers(self):

C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\playqueue.py in create(cls, server, item, shuffle, repeat, includeChapters, includeRelated)
     33             args['type'] = item.playlistType
     34         else:
---> 35             uuid = item.section().uuid
     36             args['key'] = item.key
     37             args['type'] = item.listType

TypeError: '_NA' object is not callable

Please HELP! How do you display a photo on a client?

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

The following change fixes the error you're seeing. I also started working on a test to display a photo, but it doesn't seem to work as expected yet. We need to research more if this is possible, and what the calls to the client would look like.

commit 98671d7
Author: Michael Shepanski [email protected]
Date: Thu Jul 7 22:41:11 2016 -0400
Add missing section() function to Photo object
Work on showing photos on client (not working yet)

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

ok, thanks. Here is a useful tidbit that might help you debug showing photos on client. I created a playlist with two photos and then did client.playMedia(playlist). The first photo displayed correctly but not the second. It errored out with the following:

client.playMedia(playlist)
File "<string>", line unknown
ParseError: syntax error: line 1, column 0

Try it. So I believe it is possible to display photos but we are missing something.

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Thanks for that, playing photos on my phone is working, but not on my desktop client running OpenPHT. This test is currently working for me.

def test_playlist_photos(plex, account=None):
    client = safe_client('iphone-mike', CLIENT_BASEURL, plex)
    photosection = plex.library.section(PHOTO_SECTION)
    album = photosection.get(PHOTO_ALBUM)
    photos = album.photos()
    playlist = plex.createPlaylist('test_play_playlist2', photos)
    try:
        client.playMedia(playlist)
        for i in range(3):
            time.sleep(2)
            client.skipNext(mtype='photo')
    finally:
        playlist.delete()

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

This is also working for me:

def test_playlist_photos(plex, account=None):
    client = safe_client('iphone-mike', CLIENT_BASEURL, plex)
    photosection = plex.library.section(PHOTO_SECTION)
    album = photosection.get(PHOTO_ALBUM)
    for photo in album.photos()[:4]:
        client.playMedia(photo)
        time.sleep(2)

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

Unfortunately, it is not working for me. Maybe I am not using the latest code. Can you tell me how to get your latest code?
I am on Windows 7 64 bit home edition and using WinPython 3.4.4. I am trying out your scripts using ipython notebook.

What version of Python are you running?

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

I just updated pypi to version 2.0.2 so you should be able to update with pip install -U plexapi

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

Hi Michael

I upgraded to 2.0.2 and restarted my ipython note book. I cut and pasted your code and changed the client name to my phone instead of yours. Here is the code:

import plexapi
from plexapi.server import PlexServer
plex = PlexServer()
@register('playlist,photos')
def test_playlist_photos(plex, account=None):
    client = safe_client('My SAMSUNG-SM-G900A', CLIENT_BASEURL, plex)
    photosection = plex.library.section(PHOTO_SECTION)
    album = photosection.get(PHOTO_ALBUM)
    photos = album.photos()
    for photo in photos[:4]:
        client.playMedia(photo)
        time.sleep(2)

Looks like it doesn't understand 'register'. I get the following error:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-17-7c7509f16dbb> in <module>()
      2 from plexapi.server import PlexServer
      3 plex = PlexServer()
----> 4 @register('playlist,photos')
      5 def test_playlist_photos(plex, account=None):
      6     client = safe_client('My SAMSUNG-SM-G900A', CLIENT_BASEURL, plex)

NameError: name 'register' is not defined

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Just remove that line, its a generator to register my test case. You'll also need to define all those CAPS variables. Take a look at the top of the tests.py file to see what I had them set to change change them appropriately. or better yet, just do it this way:

import time
from plexapi.server import PlexServer
plex = PlexServer()
client = plex.client('iphone-mike')
photosection = plex.library.section('Photos')
album = photosection.get('2015-12-12 - Family Photo for Christmas card')
for photo in album.photos()[:4]:
    client.playMedia(photo)
    time.sleep(2)

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

I tried removing it. But now PHOTO_SECTION, PHOTO_ALBUM, CLIENT_BASEURL, etc. are undefined. Do I need to import anything else? For example, I had to import time otherwise time was also unrecognized.

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

See the updated code snippet in my last comment that doesn't require the wonky test setup.

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

I have exactly your code snippet as below (are you referring to something else?) and It is giving PHOTO_SECTION, PHOTO_ALBUM, CLIENT_BASEURL and safe_client as unrecognized.

import plexapi
import time
from plexapi.server import PlexServer
plex = PlexServer()
def test_playlist_photos(plex, account=None):
    client = safe_client('My SAMSUNG-SM-G900A', CLIENT_BASEURL, plex)
    photosection = plex.library.section(PHOTO_SECTION)
    album = photosection.get(PHOTO_ALBUM)
    photos = album.photos()
    for photo in photos[:4]:
        client.playMedia(photo)
        time.sleep(2)

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

This one.

import time
from plexapi.server import PlexServer
plex = PlexServer()
client = plex.client('iphone-mike')
photosection = plex.library.section('Photos')
album = photosection.get('2015-12-12 - Family Photo for Christmas card')
for photo in album.photos()[:4]:
    client.playMedia(photo)
    time.sleep(2)

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

We are getting closer. All errors are gone except the one with client.playMedia(photo). Here is my code snippet which is exactly same as yours except I point to my phone and my photo album.

import time
from plexapi.server import PlexServer
plex = PlexServer()
client = plex.client('My SAMSUNG-SM-G900A')
photosection = plex.library.section('Photos')
album = photosection.get('Australia 2011')
for photo in album.photos()[:4]:
    client.playMedia(photo)
    time.sleep(2)

The is the error I am getting:

Traceback (most recent call last):
  File "C:\WinPython-64bit-3.4.4.2\MyScripts\photos.py", line 9, in <module>
    client.playMedia(photo)
  File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\client.py", line 147, in playMedia
    playqueue = self.server.createPlayQueue(media)
  File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\server.py", line 80, in createPlayQueue
    return PlayQueue.create(self, item)
  File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\playqueue.py", line 35, in create
    uuid = item.section().uuid
  File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\photo.py", line 74, in section
    return self.server.library.sectionByID(self.photoalbum().librarySectionID)
  File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\library.py", line 51, in sectionByID
    return self._sectionsByID[sectionID]
TypeError: unhashable type: '_NA'
>>> 

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Are you sure you're using the 2.0.2 code? try running this in iPython:

In [1]: import plexapi
In [2]: plexapi.VERSION
Out[2]: '2.0.2'

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

I get '2.0.2' (see below). I even tried using an iphone instead of android device as client but no luck.
This is really driving me up the wall. Any help will be really appreciated.

import plexapi
plexapi.VERSION

Output is:
'2.0.2'

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

Does the version of Python matter? I am using WinPython-64bit-3.4.4.2 as the error message above shows.

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

That's the version of python-plexapi, not the version of Python. OK, next question.. What version of the Plex Server are you running? You can get this from the PlexWeb client under Settings > Server > General. Let's make sure that's the latest version as well (mine is 1.0.0.2261).

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

My server version is 0.9.12.19. Let me update and see what happens

from python-plexapi.

scam2050 avatar scam2050 commented on May 5, 2024

So I updated to the same plex server version as yours (1.0.0.2261) and I get the first photo displayed and then the following error messages :-(

Traceback (most recent call last):
  File "C:\WinPython-64bit-3.4.4.2\MyScripts\photos.py", line 9, in <module>
    client.playMedia(photo)
  File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\client.py", line 154, in playMedia
    }, **params))
  File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\client.py", line 85, in sendCommand
    return self.query(path, headers=headers)
  File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\plexapi\client.py", line 71, in query
    return ElementTree.fromstring(data) if data else None
  File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\xml\etree\ElementTree.py", line 1335, in XML
    parser.feed(text)
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Uhhg, you are just having terrible luck, that error means the XML that the PlexServer returned is invalid. If you can enable logging, you may be able to see what URL the plexapi called and see what the XML was that was invalid. -- To enable logging, create a file at <HOME_DIR>/.config/plexapi/config.ini with the following contents (changing the path appropriately).

[logging]
path = <PATH_TO_LOG_FILE>

Then you can tail or watch that file and see every URL that is called when using the plexapi. You should also be able to open the URLs in your browser to see the raw XML.

BTW, I'm not sure many people ventured into using this api on Windows, I wonder if that is some of the source of the trouble we have been having. If that's the case, then we just need to slug through it (I don't have a Windows machine to test on). Thanks for not giving up yet. :D

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

I am in a Windows machine. What is my $home? Where do I create the config.ini file?

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

$home means your home directory.

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

Since I am on windows machine My home is C:\Users<my name>. So I created the following in
C:\Users\Mouli.config\plexapi\config.ini:

[logging]
path=C:\Users\Mouli\.config\plexapi\config.ini\plex.log

When I run the code that produces the xml error I don't see any log file in the path I specified. Maybe the logging works only in Unix?

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

Which version of Python are you using to test your code? What is the OS?

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

That file path seems messed up

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

That is the path in Windows.

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

So you are storing your log inside a folder named config.ini ?

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

@cmoulikus, what Hellowlol is trying to say is that you config.ini should probably look more like the following. When when running the test script from last week, you should see the plex.log file get populated with the URLs it's been calling.

[logging]
path=C:\Users\Mouli\.config\plexapi\plex.log

Also, thatsa good question, if you run python --version whats the version you are running? It shouldn't matter too much, but its good to know.

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

That is exactly what I have:

[logging]
path=C:\Users\Mouli\.config\plexapi\plex.log

I don't get any log file. I am using python 3.4.4
Anyways, I turned on the debug in Spyder and put a breakpoint in line 71 of client.py in plexapi since that is where the call to xml parser on data generates the error. This is the value of data:

b'Failure: 200 OK\r\n'

Any clues? Remember, I can breakpoint and look at variables anywhere through the debugger in Spyder.
The value of the variable url in the same function is:
http://192.168.0.104:32400/player/playback/playMedia?address=localhost&commandID=1&containerKey=/playQueues/183%3Fwindow%3D100%26own%3D1&key=/library/metadata/15669&machineIdentifier=299723d0c4ecdc120f5b7beb32384d6e5050c90f&port=32400

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

The first photo displays fine and I looked at response.dict in the debugger. This is what I find:

(Pdb) response.__dict__
{'connection': <requests.adapters.HTTPAdapter object at 0x00000000078B4BE0>, 'cookies': <RequestsCookieJar[]>, 'status_code': 200, 'url': 'http://192.168.0.104:32400/player/playback/playMedia?address=localhost&commandID=1&containerKey=/playQueues/187%3Fwindow%3D100%26own%3D1&key=/library/metadata/15669&machineIdentifier=299723d0c4ecdc120f5b7beb32384d6e5050c90f&port=32400', 'request': <PreparedRequest [GET]>, '_content_consumed': True, 'encoding': 'UTF-8', 'history': [], 'elapsed': datetime.timedelta(0, 16, 362936), 'headers': {'Access-Control-Max-Age': '1209600', 'Access-Control-Allow-Origin': '*', 'Content-Type': 'text/plain; charset=UTF-8'}, '_content': b'Failure: 200 OK\r\n', 'raw': <requests.packages.urllib3.response.HTTPResponse object at 0x000000000778AEF0>, 'reason': 'OK'}

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

PROBLEM SOLVED !!!!!

I commented out the call to the xml function (line 71 in client.py in plexapi) and bingo, it works!! Thanks Michael all the help and sticking through all this. The debugger in Spyder was very helpful in stepping through the plexapi code.

Now, I have a different question. Suppose I have a photo album A that has two sub-directories B and C. B and C have all the jpeg photos. How do I recursively step through all photo albums? Does plexapi support that?

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Thanks for the update, this still looks broken. I'm not sure why the response would be what you are seeing, and not a valid XML package saying the same. It's also different for you vs what I am seeing on Linux. NOTE: Commenting out that line will cause some other things to not work (such as the connect() function used by the myplex.py module). I'm going to leave this one open to see if we can reproduce it and provide a proper fix.

As for the second question; Again, I have personally never tried listing nested photoalbums. Do they show up in the PlexWeb client OK if you do this? If they don't then I wont be able to support it either, if they do show up OK in PlexWeb but not PlexAPI, then its a bug and another thread should be started.

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

I agree it is not satisfactory but I have reached the limits of my debuggability. For now it keeps me going.

Nested photoalbums plays fine on web client as well as mobile app but not on PlexApi. I am starting another thread.

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Merging this bug with #62

from python-plexapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.