|
17 | 17 | from plexapi.playlist import Playlist |
18 | 18 | from plexapi.playqueue import PlayQueue |
19 | 19 | from plexapi.settings import Settings |
20 | | -from plexapi.utils import deprecated |
| 20 | +from plexapi.utils import cached_property, deprecated |
21 | 21 | from requests.status_codes import _codes as codes |
22 | 22 |
|
23 | 23 | # Need these imports to populate utils.PLEXOBJECTS |
@@ -109,8 +109,6 @@ def __init__(self, baseurl=None, token=None, session=None, timeout=None): |
109 | 109 | self._showSecrets = CONFIG.get('log.show_secrets', '').lower() == 'true' |
110 | 110 | self._session = session or requests.Session() |
111 | 111 | self._timeout = timeout |
112 | | - self._library = None # cached library |
113 | | - self._settings = None # cached settings |
114 | 112 | self._myPlexAccount = None # cached myPlexAccount |
115 | 113 | self._systemAccounts = None # cached list of SystemAccount |
116 | 114 | self._systemDevices = None # cached list of SystemDevice |
@@ -173,27 +171,22 @@ def _headers(self, **kwargs): |
173 | 171 | def _uriRoot(self): |
174 | 172 | return f'server://{self.machineIdentifier}/com.plexapp.plugins.library' |
175 | 173 |
|
176 | | - @property |
| 174 | + @cached_property |
177 | 175 | def library(self): |
178 | 176 | """ Library to browse or search your media. """ |
179 | | - if not self._library: |
180 | | - try: |
181 | | - data = self.query(Library.key) |
182 | | - self._library = Library(self, data) |
183 | | - except BadRequest: |
184 | | - data = self.query('/library/sections/') |
185 | | - # Only the owner has access to /library |
186 | | - # so just return the library without the data. |
187 | | - return Library(self, data) |
188 | | - return self._library |
189 | | - |
190 | | - @property |
| 177 | + try: |
| 178 | + data = self.query(Library.key) |
| 179 | + except BadRequest: |
| 180 | + # Only the owner has access to /library |
| 181 | + # so just return the library without the data. |
| 182 | + data = self.query('/library/sections/') |
| 183 | + return Library(self, data) |
| 184 | + |
| 185 | + @cached_property |
191 | 186 | def settings(self): |
192 | 187 | """ Returns a list of all server settings. """ |
193 | | - if not self._settings: |
194 | | - data = self.query(Settings.key) |
195 | | - self._settings = Settings(self, data) |
196 | | - return self._settings |
| 188 | + data = self.query(Settings.key) |
| 189 | + return Settings(self, data) |
197 | 190 |
|
198 | 191 | def account(self): |
199 | 192 | """ Returns the :class:`~plexapi.server.Account` object this server belongs to. """ |
|
0 commit comments