def getDecisionPath(self, directPlay=False): if not self.item or not self.metadata: return None decisionPath = self.metadata.decisionPath if not decisionPath: server = self.metadata.transcodeServer or self.item.getServer() decisionPath = self.buildTranscode(server, util.AttributeDict(), self.metadata.partIndex, True, False).decisionPath # Modify the decision params based on the transcode url if decisionPath: if directPlay: decisionPath = decisionPath.replace("directPlay=0", "directPlay=1") # Clear all subtitle parameters and add the a valid subtitle type based # on the video player. This will let the server decide if it can supply # sidecar subs, burn or embed w/ an optional transcode. for key in ("subtitles", "advancedSubtitles"): decisionPath = re.sub('([?&]{0}=)\w+'.format(key), '', decisionPath) subType = 'sidecar' # AppSettings().getBoolPreference("custom_video_player"), "embedded", "sidecar") decisionPath = http.addUrlParam(decisionPath, "subtitles=" + subType) # Global variables for all decisions decisionPath = http.addUrlParam(decisionPath, "mediaBufferSize=50000") decisionPath = http.addUrlParam(decisionPath, "hasMDE=1") decisionPath = http.addUrlParam(decisionPath, 'X-Plex-Platform=Chrome') return decisionPath
def sendTimelineToServer(self, timelineType, timeline, time): if not hasattr(timeline.item, 'getServer') or not timeline.item.getServer(): return serverTimeline = self.getServerTimeline(timelineType) # Only send timeline if it's the first, item changes, playstate changes or timer pops itemsEqual = timeline.item and serverTimeline.item and timeline.item.ratingKey == serverTimeline.item.ratingKey if itemsEqual and timeline.state == serverTimeline.state and not serverTimeline.isExpired( ): return serverTimeline.reset() serverTimeline.item = timeline.item serverTimeline.state = timeline.state # Ignore sending timelines for multi part media with no duration obj = timeline.choice if obj and obj.part and obj.part.duration.asInt( ) == 0 and obj.media.parts and len(obj.media.parts) > 1: util.WARN_LOG( "Timeline not supported: the current part doesn't have a valid duration" ) return # It's possible with timers and in player seeking for the time to be greater than the # duration, which causes a 400, so in that case we'll set the time to the duration. duration = timeline.item.duration.asInt() or timeline.duration if time > duration: time = duration params = util.AttributeDict() params["time"] = time params["duration"] = duration params["state"] = timeline.state params["guid"] = timeline.item.guid params["ratingKey"] = timeline.item.ratingKey params["url"] = timeline.item.url params["key"] = timeline.item.key params["containerKey"] = timeline.item.container.address if timeline.playQueue: params["playQueueItemID"] = timeline.playQueue.selectedId path = "/:/timeline" for paramKey in params: if params[paramKey]: path = http.addUrlParam( path, paramKey + "=" + urllib.quote(str(params[paramKey]))) request = plexrequest.PlexRequest(timeline.item.getServer(), path) context = request.createRequestContext( "timelineUpdate", callback.Callable(self.onTimelineResponse)) context.playQueue = timeline.playQueue plexapp.APP.startRequest(request, context)
def buildUrl(self, server, path, includeToken=False): if '://' in path: url = path else: url = self.address + path if includeToken: # If we have a token, use it. Otherwise see if any other connections # for this server have one. That will let us use a plex.tv token for # something like a manually configured connection. token = self.token or server.getToken() if token: url = http.addUrlParam(url, "X-Plex-Token=" + token) return url