Add is_watched property; Fix python3 bug in examples

This commit is contained in:
Michael Shepanski 2015-11-04 22:49:09 -05:00
parent 1c27b9afb6
commit 430fb25658
4 changed files with 12 additions and 2 deletions

View file

@ -227,6 +227,14 @@ def test_015_list_devices(plex, user=None):
# item.mark_as_done(part.sync_id)
def test_017_is_watched(plex, user=None):
show = plex.library.section(SHOW_SECTION).get(SHOW_TITLE)
episode = show.get(SHOW_EPISODE)
log(2, '%s is_watched: %s' % (episode.title, episode.is_watched))
movie = plex.library.section(MOVIE_SECTION).get(MOVIE_TITLE)
log(2, '%s is_watched: %s' % (movie.title, movie.is_watched))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Run PlexAPI tests.')
parser.add_argument('-r', '--resource', help='Name of the Plex resource (requires user/pass).')

View file

@ -34,7 +34,7 @@ def iter_tests(module, args):
check_test = lambda name: name.startswith('test_') or name.startswith('example_')
check_name = lambda name: not args.name or args.name in name
module = sys.modules[module]
for func in sorted(module.__dict__.values()):
for _, func in sorted(module.__dict__.items()): # .values():
if inspect.isfunction(func) and inspect.getmodule(func) == module:
if check_test(func.__name__) and check_name(func.__name__):
yield func

View file

@ -26,7 +26,7 @@ class PlexPartialObject(object):
def __getattr__(self, attr):
if self.isPartialObject():
self.reload()
return self.__dict__.get(attr)
return self.__dict__[attr]
def __setattr__(self, attr, value):
if value != NA:

View file

@ -138,6 +138,7 @@ class Movie(Video):
self.duration = cast(int, data.attrib.get('duration', NA))
self.originallyAvailableAt = toDatetime(data.attrib.get('originallyAvailableAt', NA), '%Y-%m-%d')
self.primaryExtraKey = data.attrib.get('primaryExtraKey', NA)
self.is_watched = bool(self.viewCount > 0) # custom attr
class Show(Video):
@ -246,6 +247,7 @@ class Episode(Video):
self.year = cast(int, data.attrib.get('year', NA))
self.duration = cast(int, data.attrib.get('duration', NA))
self.originallyAvailableAt = toDatetime(data.attrib.get('originallyAvailableAt', NA), '%Y-%m-%d')
self.is_watched = bool(self.viewCount > 0) # custom attr
@property
def thumbUrl(self):