@@ -356,6 +356,9 @@ def _loadData(self, data):
356356 self ._filterTypes = None
357357 self ._fieldTypes = None
358358 self ._totalViewSize = None
359+ self ._totalSize = None
360+ self ._totalDuration = None
361+ self ._totalStorage = None
359362
360363 def fetchItems (self , ekey , cls = None , container_start = None , container_size = None , ** kwargs ):
361364 """ Load the specified key to find and build all items with the specified tag
@@ -394,7 +397,36 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
394397 @property
395398 def totalSize (self ):
396399 """ Returns the total number of items in the library for the default library type. """
397- return self .totalViewSize (includeCollections = False )
400+ if self ._totalSize is None :
401+ self ._totalSize = self .totalViewSize (includeCollections = False )
402+ return self ._totalSize
403+
404+ @property
405+ def totalDuration (self ):
406+ """ Returns the total duration (in milliseconds) of items in the library. """
407+ if self ._totalDuration is None :
408+ self ._getTotalDurationStorage ()
409+ return self ._totalDuration
410+
411+ @property
412+ def totalStorage (self ):
413+ """ Returns the total storage (in bytes) of items in the library. """
414+ if self ._totalStorage is None :
415+ self ._getTotalDurationStorage ()
416+ return self ._totalStorage
417+
418+ def _getTotalDurationStorage (self ):
419+ """ Queries the Plex server for the total library duration and storage and caches the values. """
420+ data = self ._server .query ('/media/providers?includeStorage=1' )
421+ xpath = (
422+ './MediaProvider[@identifier="com.plexapp.plugins.library"]'
423+ '/Feature[@type="content"]'
424+ '/Directory[@id="%s"]'
425+ ) % self .key
426+ directory = next (iter (data .findall (xpath )), None )
427+ if directory :
428+ self ._totalDuration = utils .cast (int , directory .attrib .get ('durationTotal' ))
429+ self ._totalStorage = utils .cast (int , directory .attrib .get ('storageTotal' ))
398430
399431 def totalViewSize (self , libtype = None , includeCollections = True ):
400432 """ Returns the total number of items in the library for a specified libtype.
0 commit comments