@@ -600,6 +600,19 @@ 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 , maxresults = 9999999 , mindate = None ):
604+ """ Get Play History for all library sections on all servers for the owner.
605+ Parameters:
606+ maxresults (int): Only return the specified number of results (optional).
607+ mindate (datetime): Min datetime to return results from.
608+ """
609+ servers = [x for x in self .resources () if x .provides == 'server' and x .owned ]
610+ hist = []
611+ for server in servers :
612+ conn = server .connect ()
613+ hist .extend (conn .history (maxresults = maxresults , mindate = mindate , accountID = 1 ))
614+ return hist
615+
603616
604617class MyPlexUser (PlexObject ):
605618 """ This object represents non-signed in users such as friends and linked
@@ -654,6 +667,8 @@ def _loadData(self, data):
654667 self .title = data .attrib .get ('title' , '' )
655668 self .username = data .attrib .get ('username' , '' )
656669 self .servers = self .findItems (data , MyPlexServerShare )
670+ for server in self .servers :
671+ server .accountID = self .id
657672
658673 def get_token (self , machineIdentifier ):
659674 try :
@@ -663,6 +678,29 @@ def get_token(self, machineIdentifier):
663678 except Exception :
664679 log .exception ('Failed to get access token for %s' % self .title )
665680
681+ def server (self , name ):
682+ """ Returns the :class:`~plexapi.myplex.MyPlexServerShare` that matches the name specified.
683+
684+ Parameters:
685+ name (str): Name of the server to return.
686+ """
687+ for server in self .servers :
688+ if name .lower () == server .name .lower ():
689+ return server
690+
691+ raise NotFound ('Unable to find server %s' % name )
692+
693+ def history (self , maxresults = 9999999 , mindate = None ):
694+ """ Get all Play History for a user in all shared servers.
695+ Parameters:
696+ maxresults (int): Only return the specified number of results (optional).
697+ mindate (datetime): Min datetime to return results from.
698+ """
699+ hist = []
700+ for server in self .servers :
701+ hist .extend (server .history (maxresults = maxresults , mindate = mindate ))
702+ return hist
703+
666704
667705class Section (PlexObject ):
668706 """ This refers to a shared section. The raw xml for the data presented here
@@ -689,6 +727,16 @@ def _loadData(self, data):
689727 self .type = data .attrib .get ('type' )
690728 self .shared = utils .cast (bool , data .attrib .get ('shared' ))
691729
730+ def history (self , maxresults = 9999999 , mindate = None ):
731+ """ Get all Play History for a user for this section in this shared server.
732+ Parameters:
733+ maxresults (int): Only return the specified number of results (optional).
734+ mindate (datetime): Min datetime to return results from.
735+ """
736+ server = self ._server ._server .resource (self ._server .name ).connect ()
737+ return server .history (maxresults = maxresults , mindate = mindate ,
738+ accountID = self ._server .accountID , librarySectionID = self .sectionKey )
739+
692740
693741class MyPlexServerShare (PlexObject ):
694742 """ Represents a single user's server reference. Used for library sharing.
@@ -711,6 +759,7 @@ def _loadData(self, data):
711759 """ Load attribute values from Plex XML response. """
712760 self ._data = data
713761 self .id = utils .cast (int , data .attrib .get ('id' ))
762+ self .accountID = utils .cast (int , data .attrib .get ('accountID' ))
714763 self .serverId = utils .cast (int , data .attrib .get ('serverId' ))
715764 self .machineIdentifier = data .attrib .get ('machineIdentifier' )
716765 self .name = data .attrib .get ('name' )
@@ -720,7 +769,21 @@ def _loadData(self, data):
720769 self .owned = utils .cast (bool , data .attrib .get ('owned' ))
721770 self .pending = utils .cast (bool , data .attrib .get ('pending' ))
722771
772+ def section (self , name ):
773+ """ Returns the :class:`~plexapi.myplex.Section` that matches the name specified.
774+
775+ Parameters:
776+ name (str): Name of the section to return.
777+ """
778+ for section in self .sections ():
779+ if name .lower () == section .title .lower ():
780+ return section
781+
782+ raise NotFound ('Unable to find section %s' % name )
783+
723784 def sections (self ):
785+ """ Returns a list of all :class:`~plexapi.myplex.Section` objects shared with this user.
786+ """
724787 url = MyPlexAccount .FRIENDSERVERS .format (machineId = self .machineIdentifier , serverId = self .id )
725788 data = self ._server .query (url )
726789 sections = []
@@ -731,6 +794,15 @@ def sections(self):
731794
732795 return sections
733796
797+ def history (self , maxresults = 9999999 , mindate = None ):
798+ """ Get all Play History for a user in this shared server.
799+ Parameters:
800+ maxresults (int): Only return the specified number of results (optional).
801+ mindate (datetime): Min datetime to return results from.
802+ """
803+ server = self ._server .resource (self .name ).connect ()
804+ return server .history (maxresults = maxresults , mindate = mindate , accountID = self .accountID )
805+
734806
735807class MyPlexResource (PlexObject ):
736808 """ This object represents resources connected to your Plex server that can provide
0 commit comments