Comments (43)
I'll have to review all the examples, sorry about that.
- The first one should read
client.title
. Plex used to return this as name but has since been updated. - 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.
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 :
- 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.
- 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.
Hi
Any update on this?
thanks
from python-plexapi.
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:
- Are you calling
PlexClient.playMedia()
directly, or getting a proper PlexClient object from PlexServer? -- There is an example in tests/tests.py namedtest_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)
- 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.
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.
Sounds like we just need more testing there. I'll take a look this week.
from python-plexapi.
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.
I'll check that as well when I dig in. I'm not sure how the Plex WebClient displays it offhand.
from python-plexapi.
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.
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.
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.
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.
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.
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.
I just updated pypi to version 2.0.2 so you should be able to update with pip install -U plexapi
from python-plexapi.
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.
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.
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.
See the updated code snippet in my last comment that doesn't require the wonky test setup.
from python-plexapi.
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.
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.
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.
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.
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.
Does the version of Python matter? I am using WinPython-64bit-3.4.4.2 as the error message above shows.
from python-plexapi.
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.
My server version is 0.9.12.19. Let me update and see what happens
from python-plexapi.
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.
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.
I am in a Windows machine. What is my $home? Where do I create the config.ini file?
from python-plexapi.
$home means your home directory.
from python-plexapi.
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.
Which version of Python are you using to test your code? What is the OS?
from python-plexapi.
That file path seems messed up
from python-plexapi.
That is the path in Windows.
from python-plexapi.
So you are storing your log inside a folder named config.ini ?
from python-plexapi.
@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.
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.
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.
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.
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.
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.
Merging this bug with #62
from python-plexapi.
Related Issues (20)
- Unable to connect to a Plex HTPC client HOT 3
- Add Type Hints to Improve Codebase Readability and Maintainability HOT 1
- Show and Season from the video module use wrong key to get subtitleLanguage attribute
- Add support for track genres in music libraries HOT 1
- feat: python class for available filters HOT 3
- Add support for Plex Profile Watch History and Ratings
- Library section lookup clobbered when multiple libraries have the same title
- editAlbum Missing ... HOT 1
- Unable to find Libraries after using PlexApi based python script. HOT 5
- locations is empty when casting to dict HOT 2
- Add 'merge' method for music albums
- Ability to Modify MovieHistory & EpisodeHistory details HOT 1
- Bad Request response when adding library with default language
- Issues creating `PlexClient` instances from `PlexServer` sessions in 4.15.8 HOT 1
- feat: Endpoint for computing sonic adventure
- Add View History Manually HOT 2
- Streams in MediaParts empty (reload() has no effect)
- `totalSize` of MediaContainer
- createPlaylist does not guard smart=True and non-empty items HOT 2
- "Invalid library sectionID: None" after PlexPartialObject.reload() HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-plexapi.