From 1f8cd6d5b75e0fb655559fac3dd27fe8b6d88317 Mon Sep 17 00:00:00 2001 From: "Simon W. Jackson" Date: Fri, 29 May 2015 13:24:47 +0200 Subject: [PATCH 1/2] Feature: Get video object by plex "key" identifier closes #4 --- plexapi/library.py | 3 +++ plexapi/video.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/plexapi/library.py b/plexapi/library.py index ef47ae85..9408ddc8 100644 --- a/plexapi/library.py +++ b/plexapi/library.py @@ -46,6 +46,9 @@ class Library(object): def get(self, 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): """ Search all available content. title: Title to search (pass None to search all titles). diff --git a/plexapi/video.py b/plexapi/video.py index c13792ec..c38355b6 100644 --- a/plexapi/video.py +++ b/plexapi/video.py @@ -215,6 +215,16 @@ def build_item(server, elem, initpath): 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): for elem in server.query(path): if elem.attrib.get('title').lower() == title.lower(): From c2a5a7ce28dc1fa701e911f44812e9c4ddbf2467 Mon Sep 17 00:00:00 2001 From: "Simon W. Jackson" Date: Fri, 29 May 2015 13:25:09 +0200 Subject: [PATCH 2/2] Ignore virtualenv files --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index a99063e1..094be661 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,13 @@ syntax: glob *.db *.log *.pyc +*.swp *.sublime-* *__pycache__* dist build *.egg-info .idea/ +lib/ +bin/ +include/