Feature: Get video object by plex "key" identifier

closes #4
This commit is contained in:
Simon W. Jackson 2015-05-29 13:24:47 +02:00
parent eb1e508638
commit 1f8cd6d5b7
2 changed files with 13 additions and 0 deletions

View file

@ -46,6 +46,9 @@ class Library(object):
def get(self, title): def get(self, title):
return video.find_item(self.server, '/library/all', title) return video.find_item(self.server, '/library/all', title)
def getByKey(self, key):
return video.find_key(self.server, key)
def search(self, title, filter='all', vtype=None, **tags): def search(self, title, filter='all', vtype=None, **tags):
""" Search all available content. """ Search all available content.
title: Title to search (pass None to search all titles). title: Title to search (pass None to search all titles).

View file

@ -215,6 +215,16 @@ def build_item(server, elem, initpath):
raise UnknownType('Unknown video type: %s' % vtype) raise UnknownType('Unknown video type: %s' % vtype)
def find_key(server, key):
path = '/library/metadata/{0}'.format(key)
try:
# Video seems to be the first sub element
elem = server.query(path)[0]
return build_item(server, elem, path)
except:
raise NotFound('Unable to find key: %s' % key)
def find_item(server, path, title): def find_item(server, path, title):
for elem in server.query(path): for elem in server.query(path):
if elem.attrib.get('title').lower() == title.lower(): if elem.attrib.get('title').lower() == title.lower():