From 430fb25658dfa505989cc08b478f97c51db11cfb Mon Sep 17 00:00:00 2001 From: Michael Shepanski Date: Wed, 4 Nov 2015 22:49:09 -0500 Subject: [PATCH] Add is_watched property; Fix python3 bug in examples --- examples/tests.py | 8 ++++++++ examples/utils.py | 2 +- plexapi/utils.py | 2 +- plexapi/video.py | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/tests.py b/examples/tests.py index 5103e13d..f8f20fca 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -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).') diff --git a/examples/utils.py b/examples/utils.py index 3071e542..0a11e987 100644 --- a/examples/utils.py +++ b/examples/utils.py @@ -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 diff --git a/plexapi/utils.py b/plexapi/utils.py index ce1c213f..7281cd25 100644 --- a/plexapi/utils.py +++ b/plexapi/utils.py @@ -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: diff --git a/plexapi/video.py b/plexapi/video.py index de6130a1..84ed54b3 100644 --- a/plexapi/video.py +++ b/plexapi/video.py @@ -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):