Skip to content

Commit

Permalink
Updated to work with changed PMS output
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony B committed Jan 15, 2017
1 parent 63955c8 commit fac2108
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def Start():
else:
Dict['plextoken'] = None

Log("Plex Token: {}".format(Dict['token']))
#Log("Plex Token: {}".format(Dict['token']))

HTTP.CacheTime = 0

Expand Down
49 changes: 30 additions & 19 deletions Contents/Code/plexshufflebyalbum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,33 @@
import json
from pprint import pprint
import random
from uuid import getnode

try:
# see if we're running in a plex plug-in
HTTP
except:
import requests
HTTP = None
class Logger:
def Debug(self, *args):
print args
Log = Logger()

BASE_HEADERS = {
'X-Plex-Platform': "PMS",
'X-Plex-Platform-Version': "1",
'X-Plex-Provides': 'controller',
'X-Plex-Product': "shufflebyalbum",
'X-Plex-Version': "1",
'X-Plex-Device': "PMS-Plugin",
'X-Plex-Device-Name': "pms",
'X-Plex-Client-Identifier': str(hex(getnode()))
}





def http_comm(url, method, headers):
if HTTP:
Expand All @@ -32,9 +53,8 @@ def __init__(self, host='localhost',port=32400, token = ""):

def query(self, path, method):
url = self.base_url + path
headers = dict()
headers = dict(BASE_HEADERS)
headers['Accept'] = 'application/json'
headers['X-Plex-Client-Identifier'] = '77777777-abab-4bc3-86a6-809c4901fb87'
if self.token:
headers['X-Plex-Token'] = self.token

Expand All @@ -59,31 +79,23 @@ def getClients(self):
path = "/clients"
response = self.get(path)
try:
return response['_children']
return response['MediaContainer']['Server']
except:
return []

def getSections(self):
path = "/library/sections"
response = self.get(path)
try:
return response['_children']
return response['MediaContainer']['Directory']
except:
return []

def getAlbums(self, section):
path = "/library/sections/{}/albums".format(section)
response = self.get(path)
try:
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
albums = response['MediaContainer']['Metadata']
return albums
except:
return []
Expand All @@ -92,15 +104,15 @@ def getServerInfo(self):
path = ""
response = self.get(path)
try:
return response
return response['MediaContainer']
except:
return {}

def getPlaylists(self):
path = "/playlists"
response = self.get(path)
try:
return response['_children']
return response['MediaContainer']['Metadata']
except:
return []

Expand All @@ -125,16 +137,15 @@ def createPlaylistOfAlbums(self, title, album_list, guid):
path += ",".join(key_list)
response = self.post(path)
try:
return response['_children'][0]
return response['MediaContainer']['Metadata'][0]
except:
return []


def createPlayQueueForPlaylist(self, playlist_id):
path = "/playQueues"
path += "?playlistID={}".format(playlist_id)
path += "&shuffle=0&type=audio&includeChapters=1&includeRelated=1"
return self.post(path)
return self.post(path)['MediaContainer']


def get_music_sections(server_ip, server_port, token):
Expand Down Expand Up @@ -200,7 +211,7 @@ def get_clients(server_ip, server_port, token):
def play_on_client(server_ip, server_port, token, client, playlist):
server = PlexServer(server_ip, server_port, token)

CLIENT_IP = client['address']
CLIENT_IP = client['host']
CLIENT_PORT = client['port']
MEDIA_ID = playlist['ratingKey']
CLIENT_ID = client['machineIdentifier']
Expand Down

0 comments on commit fac2108

Please sign in to comment.