def playMedia(self, media, offset=0, **params): """ Start playback of the specified media item. See also: Parameters: media (:class:`~plexapi.media.Media`): Media item to be played back (movie, music, photo, playlist, playqueue). offset (int): Number of milliseconds at which to start playing with zero representing the beginning (default 0). **params (dict): Optional additional parameters to include in the playback request. See also: https://github.com/plexinc/plex-media-player/wiki/Remote-control-API#modified-commands Raises: :class:`~plexapi.exceptions.Unsupported`: When no PlexServer specified in this object. """ if not self._server: raise Unsupported('A server must be specified before using this command.') server_url = media._server._baseurl.split(':') try: self.sendCommand('timeline/subscribe', port=server_url[1].strip('/'), protocol='http') except: # some clients dont need or like this and raises http 400. # We want to include the exception in the log, but it might still work # so we swallow it. log.exception('%s failed to subscribe ' % self.title) playqueue = media if isinstance(media, PlayQueue) else self._server.createPlayQueue(media) self.sendCommand('playback/playMedia', **dict({ 'machineIdentifier': self._server.machineIdentifier, 'address': server_url[1].strip('/'), 'port': server_url[-1], 'offset': offset, 'key': media.key, 'token': media._server._token, 'containerKey': '/playQueues/%s?window=100&own=1' % playqueue.playQueueID, }, **params))
def get_token(self, machineIdentifier): try: for item in self._server.query(self._server.FRIENDINVITE.format(machineId=machineIdentifier)): if utils.cast(int, item.attrib.get('userID')) == self.id: return item.attrib.get('accessToken') except Exception: log.exception('Failed to get access token for %s' % self.title)
def playMedia(self, media, offset=0, **params): """ Start playback of the specified media item. See also: Parameters: media (:class:`~plexapi.media.Media`): Media item to be played back (movie, music, photo, playlist, playqueue). offset (int): Number of milliseconds at which to start playing with zero representing the beginning (default 0). **params (dict): Optional additional parameters to include in the playback request. See also: https://github.com/plexinc/plex-media-player/wiki/Remote-control-API#modified-commands Raises: :class:`~plexapi.exceptions.Unsupported`: When no PlexServer specified in this object. """ if not self._server: raise Unsupported('A server must be specified before using this command.') server_url = media._server._baseurl.split(':') if self.product != 'OpenPHT': try: self.sendCommand('timeline/subscribe', port=server_url[1].strip('/'), protocol='http') except: # noqa: E722 # some clients dont need or like this and raises http 400. # We want to include the exception in the log, # but it might still work so we swallow it. log.exception('%s failed to subscribe ' % self.title) playqueue = media if isinstance(media, PlayQueue) else self._server.createPlayQueue(media) self.sendCommand('playback/playMedia', **dict({ 'machineIdentifier': self._server.machineIdentifier, 'address': server_url[1].strip('/'), 'port': server_url[-1], 'offset': offset, 'key': media.key, 'token': media._server._token, 'containerKey': '/playQueues/%s?window=100&own=1' % playqueue.playQueueID, }, **params))