Beispiel #1
0
    def get_playback_url(self, direct_play=None, offset=0,
                         video_height=1080,      video_width=1920,
                         video_bitrate=20000,    video_quality=100):
        """
        Returns the URL to use for the trancoded file.
        """
        if direct_play is None:
            # See if transcoding is suggested
            direct_play = not self.is_transcode_suggested()

        if direct_play:
            if not self._part_node:
                return
            url  = urlparse.urljoin(self.parent.server_url, self._part_node.get("key", ""))
            return get_plex_url(url)

        url = "/video/:/transcode/universal/start.m3u8"
        args = {
            "path":             self.node.get("key"),
            "session":          settings.client_uuid,
            "protocol":         "hls",
            "directPlay":       "0",
            "directStream":     "1",
            "fastSeek":         "1",
            "maxVideoBitrate":  str(video_bitrate),
            "videoQuality":     str(video_quality),
            "videoResolution":  "%sx%s" % (video_width,video_height),
            "mediaIndex":       self._media or 0,
            "partIndex":        self._part or 0,
            "offset":           offset,
            #"skipSubtitles":    "1",
        }

        audio_formats = []
        protocols = "protocols=http-live-streaming,http-mp4-streaming,http-mp4-video,http-mp4-video-720p,http-streaming-video,http-streaming-video-720p;videoDecoders=mpeg4,h264{profile:high&resolution:1080&level:51};audioDecoders=mp3,aac{channels:8}"
        if settings.audio_ac3passthrough:
            audio_formats.append("add-transcode-target-audio-codec(type=videoProfile&context=streaming&protocol=hls&audioCodec=ac3)")
            audio_formats.append("add-transcode-target-audio-codec(type=videoProfile&context=streaming&protocol=hls&audioCodec=eac3)")
            protocols += ",ac3{bitrate:800000&channels:8}"
        if settings.audio_dtspassthrough:
            audio_formats.append("add-transcode-target-audio-codec(type=videoProfile&context=streaming&protocol=hls&audioCodec=dca)")
            protocols += ",dts{bitrate:800000&channels:8}"

        if audio_formats:
            args["X-Plex-Client-Profile-Extra"] = "+".join(audio_formats)
            args["X-Plex-Client-Capabilities"]  = protocols

        # OMXPlayer seems to have an issue playing the "start.m3u8" file
        # directly, so we need to extract the index file
        r = urllib.urlopen(get_plex_url(urlparse.urljoin(self.parent.server_url, url), args))
        try:
            for line in r.readlines():
                line = line.strip()
                if line and line[0] != "#" and line.find("m3u8") > 0:
                    base = urlparse.urljoin(self.parent.server_url, "/video/:/transcode/universal/")
                    return urlparse.urljoin(base, line)
        except Exception, e:
            log.error("Video::get_playback_url error processing response: %s" % str(e))
Beispiel #2
0
 def __init__(self, url):
     """
     ``url`` should be a URL to the Plex XML media item.
     """
     self.path       = urlparse.urlparse(url)
     self.server_url = self.path.scheme + "://" + self.path.netloc
     self.tree       = et.parse(urllib.urlopen(get_plex_url(url)))
Beispiel #3
0
 def get_machine_identifier(self):
     if not hasattr(self, "_machine_identifier"):
         doc = urllib.urlopen(get_plex_url(self.server_url))
         tree = et.parse(doc)
         setattr(self, "_machine_identifier", tree.find('.').get("machineIdentifier"))
     return getattr(self, "_machine_identifier", None)