Skip to content

Commit c31f7c6

Browse files
committed
refactor: For all Plex objects, call the base class's loadData function to do cache invalidation
1 parent d8860c9 commit c31f7c6

File tree

8 files changed

+51
-42
lines changed

8 files changed

+51
-42
lines changed

plexapi/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ def extend(
11741174
setattr(self, key, getattr(__iterable, key))
11751175

11761176
def _loadData(self, data):
1177-
self._data = data
1177+
PlexPartialObject._loadData(self, data)
11781178
self.allowSync = utils.cast(int, data.attrib.get('allowSync'))
11791179
self.augmentationKey = data.attrib.get('augmentationKey')
11801180
self.identifier = data.attrib.get('identifier')

plexapi/client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def reload(self):
124124

125125
def _loadData(self, data):
126126
""" Load attribute values from Plex XML response. """
127-
self._data = data
127+
PlexObject._loadData(self, data)
128128
self.deviceClass = data.attrib.get('deviceClass')
129129
self.machineIdentifier = data.attrib.get('machineIdentifier')
130130
self.product = data.attrib.get('product')
@@ -606,7 +606,7 @@ class ClientTimeline(PlexObject):
606606
key = 'timeline/poll'
607607

608608
def _loadData(self, data):
609-
self._data = data
609+
PlexObject._loadData(self, data)
610610
self.address = data.attrib.get('address')
611611
self.audioStreamId = utils.cast(int, data.attrib.get('audioStreamId'))
612612
self.autoPlay = utils.cast(bool, data.attrib.get('autoPlay'))

plexapi/library.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Library(PlexObject):
3939
key = '/library'
4040

4141
def _loadData(self, data):
42-
self._data = data
42+
PlexObject._loadData(self, data)
4343
self.identifier = data.attrib.get('identifier')
4444
self.mediaTagVersion = data.attrib.get('mediaTagVersion')
4545
self.title1 = data.attrib.get('title1')
@@ -432,7 +432,7 @@ class LibrarySection(PlexObject):
432432
"""
433433

434434
def _loadData(self, data):
435-
self._data = data
435+
PlexObject._loadData(self, data)
436436
self.agent = data.attrib.get('agent')
437437
self.allowSync = utils.cast(bool, data.attrib.get('allowSync'))
438438
self.art = data.attrib.get('art')
@@ -441,7 +441,6 @@ def _loadData(self, data):
441441
self.filters = utils.cast(bool, data.attrib.get('filters'))
442442
self.key = utils.cast(int, data.attrib.get('key'))
443443
self.language = data.attrib.get('language')
444-
self.locations = self.listAttrs(data, 'path', etag='Location')
445444
self.refreshing = utils.cast(bool, data.attrib.get('refreshing'))
446445
self.scanner = data.attrib.get('scanner')
447446
self.thumb = data.attrib.get('thumb')
@@ -456,6 +455,10 @@ def _loadData(self, data):
456455
self._totalDuration = None
457456
self._totalStorage = None
458457

458+
@cached_data_property
459+
def locations(self):
460+
return self.listAttrs(self._data, 'path', etag='Location')
461+
459462
@cached_property
460463
def totalSize(self):
461464
""" Returns the total number of items in the library for the default library type. """
@@ -2165,7 +2168,7 @@ class LibraryTimeline(PlexObject):
21652168

21662169
def _loadData(self, data):
21672170
""" Load attribute values from Plex XML response. """
2168-
self._data = data
2171+
PlexObject._loadData(self, data)
21692172
self.size = utils.cast(int, data.attrib.get('size'))
21702173
self.allowSync = utils.cast(bool, data.attrib.get('allowSync'))
21712174
self.art = data.attrib.get('art')
@@ -2194,7 +2197,7 @@ class Location(PlexObject):
21942197

21952198
def _loadData(self, data):
21962199
""" Load attribute values from Plex XML response. """
2197-
self._data = data
2200+
PlexObject._loadData(self, data)
21982201
self.id = utils.cast(int, data.attrib.get('id'))
21992202
self.path = data.attrib.get('path')
22002203

@@ -2220,7 +2223,7 @@ class Hub(PlexObject):
22202223

22212224
def _loadData(self, data):
22222225
""" Load attribute values from Plex XML response. """
2223-
self._data = data
2226+
PlexObject._loadData(self, data)
22242227
self.context = data.attrib.get('context')
22252228
self.hubKey = data.attrib.get('hubKey')
22262229
self.hubIdentifier = data.attrib.get('hubIdentifier')
@@ -2869,7 +2872,7 @@ class FilteringFilter(PlexObject):
28692872
TAG = 'Filter'
28702873

28712874
def _loadData(self, data):
2872-
self._data = data
2875+
PlexObject._loadData(self, data)
28732876
self.filter = data.attrib.get('filter')
28742877
self.filterType = data.attrib.get('filterType')
28752878
self.key = data.attrib.get('key')
@@ -2895,7 +2898,7 @@ class FilteringSort(PlexObject):
28952898

28962899
def _loadData(self, data):
28972900
""" Load attribute values from Plex XML response. """
2898-
self._data = data
2901+
PlexObject._loadData(self, data)
28992902
self.active = utils.cast(bool, data.attrib.get('active', '0'))
29002903
self.activeDirection = data.attrib.get('activeDirection')
29012904
self.default = data.attrib.get('default')
@@ -2920,7 +2923,7 @@ class FilteringField(PlexObject):
29202923

29212924
def _loadData(self, data):
29222925
""" Load attribute values from Plex XML response. """
2923-
self._data = data
2926+
PlexObject._loadData(self, data)
29242927
self.key = data.attrib.get('key')
29252928
self.title = data.attrib.get('title')
29262929
self.type = data.attrib.get('type')
@@ -2963,6 +2966,7 @@ class FilteringOperator(PlexObject):
29632966

29642967
def _loadData(self, data):
29652968
""" Load attribute values from Plex XML response. """
2969+
PlexObject._loadData(self, data)
29662970
self.key = data.attrib.get('key')
29672971
self.title = data.attrib.get('title')
29682972

@@ -2985,7 +2989,7 @@ class FilterChoice(PlexObject):
29852989

29862990
def _loadData(self, data):
29872991
""" Load attribute values from Plex XML response. """
2988-
self._data = data
2992+
PlexObject._loadData(self, data)
29892993
self.fastKey = data.attrib.get('fastKey')
29902994
self.key = data.attrib.get('key')
29912995
self.thumb = data.attrib.get('thumb')
@@ -3015,7 +3019,7 @@ class ManagedHub(PlexObject):
30153019

30163020
def _loadData(self, data):
30173021
""" Load attribute values from Plex XML response. """
3018-
self._data = data
3022+
PlexObject._loadData(self, data)
30193023
self.deletable = utils.cast(bool, data.attrib.get('deletable', True))
30203024
self.homeVisibility = data.attrib.get('homeVisibility', 'none')
30213025
self.identifier = data.attrib.get('identifier')
@@ -3139,6 +3143,7 @@ class Folder(PlexObject):
31393143

31403144
def _loadData(self, data):
31413145
""" Load attribute values from Plex XML response. """
3146+
PlexObject._loadData(self, data)
31423147
self.key = data.attrib.get('key')
31433148
self.title = data.attrib.get('title')
31443149

@@ -3179,7 +3184,7 @@ class FirstCharacter(PlexObject):
31793184

31803185
def _loadData(self, data):
31813186
""" Load attribute values from Plex XML response. """
3182-
self._data = data
3187+
PlexObject._loadData(self, data)
31833188
self.key = data.attrib.get('key')
31843189
self.size = data.attrib.get('size')
31853190
self.title = data.attrib.get('title')
@@ -3200,6 +3205,7 @@ class Path(PlexObject):
32003205
TAG = 'Path'
32013206

32023207
def _loadData(self, data):
3208+
PlexObject._loadData(self, data)
32033209
self.home = utils.cast(bool, data.attrib.get('home'))
32043210
self.key = data.attrib.get('key')
32053211
self.network = utils.cast(bool, data.attrib.get('network'))
@@ -3229,6 +3235,7 @@ class File(PlexObject):
32293235
TAG = 'File'
32303236

32313237
def _loadData(self, data):
3238+
PlexObject._loadData(self, data)
32323239
self.key = data.attrib.get('key')
32333240
self.path = data.attrib.get('path')
32343241
self.title = data.attrib.get('title')

plexapi/media.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class MediaPart(PlexObject):
141141

142142
def _loadData(self, data):
143143
""" Load attribute values from Plex XML response. """
144-
self._data = data
144+
PlexObject._loadData(self, data)
145145
self.accessible = utils.cast(bool, data.attrib.get('accessible'))
146146
self.audioProfile = data.attrib.get('audioProfile')
147147
self.container = data.attrib.get('container')
@@ -271,7 +271,7 @@ class MediaPartStream(PlexObject):
271271

272272
def _loadData(self, data):
273273
""" Load attribute values from Plex XML response. """
274-
self._data = data
274+
PlexObject._loadData(self, data)
275275
self.bitrate = utils.cast(int, data.attrib.get('bitrate'))
276276
self.codec = data.attrib.get('codec')
277277
self.decision = data.attrib.get('decision')
@@ -572,7 +572,7 @@ class TranscodeSession(PlexObject):
572572

573573
def _loadData(self, data):
574574
""" Load attribute values from Plex XML response. """
575-
self._data = data
575+
PlexObject._loadData(self, data)
576576
self.audioChannels = utils.cast(int, data.attrib.get('audioChannels'))
577577
self.audioCodec = data.attrib.get('audioCodec')
578578
self.audioDecision = data.attrib.get('audioDecision')
@@ -613,7 +613,7 @@ class TranscodeJob(PlexObject):
613613
TAG = 'TranscodeJob'
614614

615615
def _loadData(self, data):
616-
self._data = data
616+
PlexObject._loadData(self, data)
617617
self.generatorID = data.attrib.get('generatorID')
618618
self.key = data.attrib.get('key')
619619
self.progress = data.attrib.get('progress')
@@ -632,7 +632,7 @@ class Optimized(PlexObject):
632632
TAG = 'Item'
633633

634634
def _loadData(self, data):
635-
self._data = data
635+
PlexObject._loadData(self, data)
636636
self.id = data.attrib.get('id')
637637
self.composite = data.attrib.get('composite')
638638
self.title = data.attrib.get('title')
@@ -670,7 +670,7 @@ class Conversion(PlexObject):
670670
TAG = 'Video'
671671

672672
def _loadData(self, data):
673-
self._data = data
673+
PlexObject._loadData(self, data)
674674
self.addedAt = data.attrib.get('addedAt')
675675
self.art = data.attrib.get('art')
676676
self.chapterSource = data.attrib.get('chapterSource')
@@ -746,7 +746,7 @@ def __str__(self):
746746

747747
def _loadData(self, data):
748748
""" Load attribute values from Plex XML response. """
749-
self._data = data
749+
PlexObject._loadData(self, data)
750750
self.filter = data.attrib.get('filter')
751751
self.id = utils.cast(int, data.attrib.get('id'))
752752
self.key = data.attrib.get('key')
@@ -957,7 +957,7 @@ class Guid(PlexObject):
957957

958958
def _loadData(self, data):
959959
""" Load attribute values from Plex XML response. """
960-
self._data = data
960+
PlexObject._loadData(self, data)
961961
self.id = data.attrib.get('id')
962962

963963

@@ -975,7 +975,7 @@ class Image(PlexObject):
975975

976976
def _loadData(self, data):
977977
""" Load attribute values from Plex XML response. """
978-
self._data = data
978+
PlexObject._loadData(self, data)
979979
self.alt = data.attrib.get('alt')
980980
self.type = data.attrib.get('type')
981981
self.url = data.attrib.get('url')
@@ -997,7 +997,7 @@ class Rating(PlexObject):
997997

998998
def _loadData(self, data):
999999
""" Load attribute values from Plex XML response. """
1000-
self._data = data
1000+
PlexObject._loadData(self, data)
10011001
self.image = data.attrib.get('image')
10021002
self.type = data.attrib.get('type')
10031003
self.value = utils.cast(float, data.attrib.get('value'))
@@ -1020,7 +1020,7 @@ class Review(PlexObject):
10201020
TAG = 'Review'
10211021

10221022
def _loadData(self, data):
1023-
self._data = data
1023+
PlexObject._loadData(self, data)
10241024
self.filter = data.attrib.get('filter')
10251025
self.id = utils.cast(int, data.attrib.get('id', 0))
10261026
self.image = data.attrib.get('image')
@@ -1045,7 +1045,7 @@ class UltraBlurColors(PlexObject):
10451045

10461046
def _loadData(self, data):
10471047
""" Load attribute values from Plex XML response. """
1048-
self._data = data
1048+
PlexObject._loadData(self, data)
10491049
self.bottomLeft = data.attrib.get('bottomLeft')
10501050
self.bottomRight = data.attrib.get('bottomRight')
10511051
self.topLeft = data.attrib.get('topLeft')
@@ -1066,7 +1066,7 @@ class BaseResource(PlexObject):
10661066
"""
10671067

10681068
def _loadData(self, data):
1069-
self._data = data
1069+
PlexObject._loadData(self, data)
10701070
self.key = data.attrib.get('key')
10711071
self.provider = data.attrib.get('provider')
10721072
self.ratingKey = data.attrib.get('ratingKey')
@@ -1141,7 +1141,7 @@ def __repr__(self):
11411141
return f"<{':'.join([self.__class__.__name__, name, offsets])}>"
11421142

11431143
def _loadData(self, data):
1144-
self._data = data
1144+
PlexObject._loadData(self, data)
11451145
self.end = utils.cast(int, data.attrib.get('endTimeOffset'))
11461146
self.filter = data.attrib.get('filter')
11471147
self.id = utils.cast(int, data.attrib.get('id', 0))
@@ -1175,7 +1175,7 @@ def __repr__(self):
11751175
return f"<{':'.join([self.__class__.__name__, name, offsets])}>"
11761176

11771177
def _loadData(self, data):
1178-
self._data = data
1178+
PlexObject._loadData(self, data)
11791179
self.end = utils.cast(int, data.attrib.get('endTimeOffset'))
11801180
self.final = utils.cast(bool, data.attrib.get('final'))
11811181
self.id = utils.cast(int, data.attrib.get('id'))
@@ -1209,7 +1209,7 @@ class Field(PlexObject):
12091209
TAG = 'Field'
12101210

12111211
def _loadData(self, data):
1212-
self._data = data
1212+
PlexObject._loadData(self, data)
12131213
self.locked = utils.cast(bool, data.attrib.get('locked'))
12141214
self.name = data.attrib.get('name')
12151215

@@ -1229,7 +1229,7 @@ def __repr__(self):
12291229
return f"<{':'.join([p for p in [self.__class__.__name__, name, score] if p])}>"
12301230

12311231
def _loadData(self, data):
1232-
self._data = data
1232+
PlexObject._loadData(self, data)
12331233
self.guid = data.attrib.get('guid')
12341234
self.lifespanEnded = data.attrib.get('lifespanEnded')
12351235
self.name = data.attrib.get('name')
@@ -1251,14 +1251,15 @@ def __repr__(self):
12511251
return f"<{':'.join([p for p in [self.__class__.__name__, uid] if p])}>"
12521252

12531253
def _loadData(self, data):
1254-
self._data = data
1254+
PlexObject._loadData(self, data)
12551255
self.hasAttribution = data.attrib.get('hasAttribution')
12561256
self.hasPrefs = data.attrib.get('hasPrefs')
12571257
self.identifier = data.attrib.get('identifier')
12581258
self.name = data.attrib.get('name')
12591259
self.primary = data.attrib.get('primary')
12601260
self.shortIdentifier = self.identifier.rsplit('.', 1)[1]
12611261

1262+
# TODO: How should the cached data property be handled here?
12621263
if 'mediaType' in self._initpath:
12631264
self.languageCodes = self.listAttrs(data, 'code', etag='Language')
12641265
self.mediaTypes = []
@@ -1331,7 +1332,7 @@ def __repr__(self):
13311332
return f'<{self.__class__.__name__}:{self.platform}:{self.offerType}>'
13321333

13331334
def _loadData(self, data):
1334-
self._data = data
1335+
PlexObject._loadData(self, data)
13351336
self.country = data.attrib.get('country')
13361337
self.offerType = data.attrib.get('offerType')
13371338
self.platform = data.attrib.get('platform')

plexapi/myplex.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ class Section(PlexObject):
13291329
TAG = 'Section'
13301330

13311331
def _loadData(self, data):
1332-
self._data = data
1332+
PlexObject._loadData(self, data)
13331333
self.id = utils.cast(int, data.attrib.get('id'))
13341334
self.key = utils.cast(int, data.attrib.get('key'))
13351335
self.shared = utils.cast(bool, data.attrib.get('shared', '0'))
@@ -1368,7 +1368,7 @@ class MyPlexServerShare(PlexObject):
13681368

13691369
def _loadData(self, data):
13701370
""" Load attribute values from Plex XML response. """
1371-
self._data = data
1371+
PlexObject._loadData(self, data)
13721372
self.id = utils.cast(int, data.attrib.get('id'))
13731373
self.accountID = utils.cast(int, data.attrib.get('accountID'))
13741374
self.serverId = utils.cast(int, data.attrib.get('serverId'))
@@ -1573,7 +1573,7 @@ class ResourceConnection(PlexObject):
15731573
TAG = 'connection'
15741574

15751575
def _loadData(self, data):
1576-
self._data = data
1576+
PlexObject._loadData(self, data)
15771577
self.address = data.attrib.get('address')
15781578
self.ipv6 = utils.cast(bool, data.attrib.get('IPv6'))
15791579
self.local = utils.cast(bool, data.attrib.get('local'))
@@ -2047,7 +2047,7 @@ class GeoLocation(PlexObject):
20472047
TAG = 'location'
20482048

20492049
def _loadData(self, data):
2050-
self._data = data
2050+
PlexObject._loadData(self, data)
20512051
self.city = data.attrib.get('city')
20522052
self.code = data.attrib.get('code')
20532053
self.continentCode = data.attrib.get('continent_code')

0 commit comments

Comments
 (0)