Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding History object and history deletion #1491

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion plexapi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def history(self, maxresults=None, mindate=None, ratingKey=None, accountID=None,
args['viewedAt>'] = int(mindate.timestamp())

key = f'/status/sessions/history/all{utils.joinArgs(args)}'
return self.fetchItems(key, maxresults=maxresults)
return self.fetchItems(key, maxresults=maxresults, cls=History)

def playlists(self, playlistType=None, sectionId=None, title=None, sort=None, **kwargs):
""" Returns a list of all :class:`~plexapi.playlist.Playlist` objects on the server.
Expand Down Expand Up @@ -1305,3 +1305,35 @@ def _loadData(self, data):
self.claimed = utils.cast(bool, data.attrib.get('claimed'))
self.machineIdentifier = data.attrib.get('machineIdentifier')
self.version = data.attrib.get('version')


class History(PlexObject):
""" Represents a single history data point."""

def _loadData(self, data):
self._data = data
self.historyKey = data.attrib.get('historyKey')
self.key = data.attrib.get('key')
self.parentKey = data.attrib.get('parentKey')
self.ratingKey = data.attrib.get('ratingKey')
self.librarySectionID = data.attrib.get('librarySectionID')
self.grandparentKey = data.attrib.get('grandparentKey')
self.grandparentTitle = data.attrib.get('grandparentTitle')
self.title = data.attrib.get('title')
self.type = data.attrib.get('type')
self.thumb = data.attrib.get('thumb')
self.parentThumb = data.attrib.get('parentThumb')
self.grandparentThumb = data.attrib.get('grandparentThumb')
self.grandparentArt = data.attrib.get('grandparentArt')
self.index = data.attrib.get('index')
self.parentIndex = data.attrib.get('parentIndex')
self.viewedAt = utils.toDatetime(data.attrib.get('viewedAt'))
self.accountID = utils.cast(int, data.attrib.get('accountID'))
self.deviceID = utils.cast(int, data.attrib.get('deviceID'))

def __repr__(self):
return f"<{self.__class__.__name__}:{self.accountID}:{self.viewedAt}>"

def delete(self):
""" Delete history data point from Server. """
return self._server.query(key=self.historyKey, method=self._server._session.delete)
Loading