Comments (10)
Hey there, I just came across this project when trying to create a little specialized utility for generating playlists. What you've got so far looks great, but of course, no playlist manipulations yet.
While, I've been able to use the REST API to view playlists, I haven't been able to track down any API description for creating, deleting, or adding/removing items to playlists. Do you have any reference that you can share? I'm not afraid to dig through source code of any kind if that's what it takes!
Thanks!
from python-plexapi.
I should have playlist support within a week or two. In version two, I plan to have all enhancements closed.
Anyway, what I have been doing to figure out the API is open chrome dev tools in the Plex Web interface. Then perform the actions I wanted to know and check out the URL that it is calling.
from python-plexapi.
Just started messing with this today. Here is what I found:
def addItem(self, item):
# PUT /playlists/29988/items?uri=library%3A%2F%2F32268d7c-3e8c-4ab5-98ad-bad8a3b78c63%2Fitem%2F%252Flibrary%252Fmetadata%252F801
pass
def removeItem(self, item):
# DELETE /playlists/29988/items/4866
pass
def moveItem(self, item, after):
# PUT /playlists/29988/items/4556/move?after=4445
# PUT /playlists/29988/items/4556/move (to first item)
pass
def edit(self, title=None, summary=None):
# PUT /library/metadata/29988?title=You%20Look%20Like%20Gollum2&summary=foobar
pass
def delete(self):
# DELETE /playlists/29988
pass
@classmethod
def create(self, server):
# POST /playlists?type=video&title=TESTING&smart=0&uri=library%3A%2F%2F32268d7c-3e8c-4ab5-98ad-bad8a3b78c63%2Fitem%2F%252Flibrary%252Fmetadata%252F801
# RESPONSE: <Playlist ratingKey="53596" key="/playlists/53596/items" guid="com.plexapp.agents.none://ea4b8781-1605-4127-bea0-651d48f8ad18" type="playlist" title="TESTING" summary="" smart="0" playlistType="video" composite="/playlists/53596/composite/1460261551" ratingCount="0" duration="5348000" leafCount="1" addedAt="1460261551" updatedAt="1460261551" durationInSeconds="1"></Playlist>
pass
from python-plexapi.
This is a great start, thanks! Of course, now that I know you're on the case, I may just let you finish and reap the rewards of your hard work ;-)
from python-plexapi.
Not content to wait, and since I need only a very small-subset of your API, I followed your technique of use chrome dev tools to spy on the Plex web UI. I put together a small wrapper that serves my specific needs, which I'll paste in here. The specific things I found were that you can add multiple items at once when creating a playlist, and that the UUID pass when creating a playlist seems to be for the content section. Thanks for your help! I'll probably switch over to your API when it's solidifed.
import sys
import os
import requests
import json
from pprint import pprint
import random
class PlexServer(object):
def __init__(self, host='localhost',port=32400):
self.base_url = "http://{}:{}".format(host,port)
def query(self, path, request_func):
url = self.base_url + path
headers = dict()
headers['Accept'] = 'application/json'
r = request_func(url, headers=headers, allow_redirects=True)
try:
response = json.loads( r.content )
return response
except:
return None
def get(self, path):
#print "GET", path
return self.query(path, requests.get)
def post(self, path):
#print "POST", path
return self.query(path, requests.post)
def delete(self, path):
#print "DELETE", path
return self.query(path, requests.delete)
def getSections(self):
path = "/library/sections"
response = self.get(path)
return response['_children']
def getAlbums(self, section):
path = "/library/sections/{}/albums".format(section)
response = self.get(path)
albums = response['_children']
for a in albums:
# massage the genres info:
genre_list = []
for c in a['_children']:
if c['_elementType'] == 'Genre':
genre_list.append(c['tag'])
a['genres'] = genre_list
return albums
def getPlaylists(self):
path = "/playlists"
response = self.get(path)
return response['_children']
# takes a dict item as returned from getPlaylists
def deletePlaylist(self, playlist):
playlist_key = playlist['key']
path = playlist_key.replace("/items", "")
return self.delete(path)
# takes a list of album dict items as returned from getAlbums
def createPlaylistOfAlbums(self, title, album_list, guid):
key_list = []
for a in album_list:
key_num = a['key'].replace("/children","").replace("/library/metadata/", "")
key_list.append(key_num)
path = "/playlists"
path += "?type=audio"
path += "&title={}".format(title)
path += "&smart=0"
path += "&uri=library://{}/directory//library/metadata/".format(guid)
path += ",".join(key_list)
return self.post(path)
from python-plexapi.
Awesome, glad you got it working. I suspected you may be able to add multiple items, but didn't really look into it too closely. Thanks for the example.
from python-plexapi.
@beville Did you ever figure out what guid is and where is comes from?
from python-plexapi.
As far as I could tell, the guid matches the UUID for the section of the content that you're adding the playlist for. (/library/sections)
When creating the playlist, it didn't seem to matter what I used, but I was trying to match the network trace from the Web UI as close as I could. So when I added a music album, it seemed to use the uuid of the only music section I have.
from python-plexapi.
Thanks. I added support for most things in this change as well as a few tests to help prevent regressions in the future. I did not fix the UUID thing mentioned above. In the next few days I'll cleanup the edges a bit more. I still want to do the following:
- Fix the UUID as mentioned above.
- Cleanup checking playlist types match (I'm not happy with the current implementation).
- Raise exceptions if operations did not complete successfully.
commit 3138ad1
Author: Michael Shepanski [email protected]
Date: Sun Apr 10 23:49:23 2016 -0400
Added playlist support
from python-plexapi.
commit 748fc68
Author: Michael Shepanski [email protected]
Date: Mon Apr 11 22:43:21 2016 -0400
Cleanup playlist support; Fix UUID on URLs; Better method to store listTypes; Cache section IDs in library
from python-plexapi.
Related Issues (20)
- 4.15.1 breaks setSelectedSubtitleStream due to missing arg (Quick fix!)
- PlexHistory.source() returns Tag class if file has been deleted
- Third-party sign in
- `SmartFilterMixin._parseFilters` algorithm fails when multi-level filters are to be parsed
- Create a Contributing guide for the project HOT 1
- Filter parsing returns unknown keys `group` and `having`
- Code Improvement: Fix class `Playable`
- Code Improvement: Organize Project Structure
- 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
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.