@@ -600,6 +600,15 @@ def claimToken(self):
600600 raise BadRequest ('(%s) %s %s; %s' % (response .status_code , codename , response .url , errtext ))
601601 return response .json ()['token' ]
602602
603+ def history (self ):
604+ """ Get Play History for all library sections on all servers for the owner. """
605+ servers = [x for x in self .resources () if x .provides == 'server' and x .owned ]
606+ hist = []
607+ for server in servers :
608+ conn = server .connect ()
609+ hist .extend (conn .history (accountID = 1 ))
610+ return hist
611+
603612
604613class MyPlexUser (PlexObject ):
605614 """ This object represents non-signed in users such as friends and linked
@@ -654,6 +663,8 @@ def _loadData(self, data):
654663 self .title = data .attrib .get ('title' , '' )
655664 self .username = data .attrib .get ('username' , '' )
656665 self .servers = self .findItems (data , MyPlexServerShare )
666+ for server in self .servers :
667+ server .accountID = self .id
657668
658669 def get_token (self , machineIdentifier ):
659670 try :
@@ -663,6 +674,25 @@ def get_token(self, machineIdentifier):
663674 except Exception :
664675 log .exception ('Failed to get access token for %s' % self .title )
665676
677+ def server (self , name ):
678+ """ Returns the :class:`~plexapi.myplex.MyPlexServerShare` that matches the name specified.
679+
680+ Parameters:
681+ name (str): Name of the server to return.
682+ """
683+ for server in self .servers :
684+ if name .lower () == server .name .lower ():
685+ return server
686+
687+ raise NotFound ('Unable to find server %s' % name )
688+
689+ def history (self ):
690+ """ Get all Play History for a user in all shared servers. """
691+ hist = []
692+ for server in self .servers :
693+ hist .extend (server .history ())
694+ return hist
695+
666696
667697class Section (PlexObject ):
668698 """ This refers to a shared section. The raw xml for the data presented here
@@ -689,6 +719,11 @@ def _loadData(self, data):
689719 self .type = data .attrib .get ('type' )
690720 self .shared = utils .cast (bool , data .attrib .get ('shared' ))
691721
722+ def history (self ):
723+ """ Get all Play History for a user for this section in this shared server. """
724+ server = self ._server ._server .resource (self ._server .name ).connect ()
725+ return server .history (accountID = self ._server .accountID , librarySectionID = self .sectionKey )
726+
692727
693728class MyPlexServerShare (PlexObject ):
694729 """ Represents a single user's server reference. Used for library sharing.
@@ -711,6 +746,7 @@ def _loadData(self, data):
711746 """ Load attribute values from Plex XML response. """
712747 self ._data = data
713748 self .id = utils .cast (int , data .attrib .get ('id' ))
749+ self .accountID = utils .cast (int , data .attrib .get ('accountID' ))
714750 self .serverId = utils .cast (int , data .attrib .get ('serverId' ))
715751 self .machineIdentifier = data .attrib .get ('machineIdentifier' )
716752 self .name = data .attrib .get ('name' )
@@ -720,7 +756,21 @@ def _loadData(self, data):
720756 self .owned = utils .cast (bool , data .attrib .get ('owned' ))
721757 self .pending = utils .cast (bool , data .attrib .get ('pending' ))
722758
759+ def section (self , name ):
760+ """ Returns the :class:`~plexapi.myplex.Section` that matches the name specified.
761+
762+ Parameters:
763+ name (str): Name of the section to return.
764+ """
765+ for section in self .sections ():
766+ if name .lower () == section .title .lower ():
767+ return section
768+
769+ raise NotFound ('Unable to find section %s' % name )
770+
723771 def sections (self ):
772+ """ Returns a list of all :class:`~plexapi.myplex.Section` objects shared with this user.
773+ """
724774 url = MyPlexAccount .FRIENDSERVERS .format (machineId = self .machineIdentifier , serverId = self .id )
725775 data = self ._server .query (url )
726776 sections = []
@@ -731,6 +781,11 @@ def sections(self):
731781
732782 return sections
733783
784+ def history (self ):
785+ """ Get all Play History for a user in this shared server. """
786+ server = self ._server .resource (self .name ).connect ()
787+ return server .history (accountID = self .accountID )
788+
734789
735790class MyPlexResource (PlexObject ):
736791 """ This object represents resources connected to your Plex server that can provide
0 commit comments