Skip to content

Commit

Permalink
More transcoding support. Still need to add user-configurable options.
Browse files Browse the repository at this point in the history
  • Loading branch information
wnielson committed Feb 9, 2014
1 parent e178e54 commit e7ac08e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
38 changes: 31 additions & 7 deletions omplex/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,23 @@ def get_proper_title(self):
setattr(self, "_title", title)
return getattr(self, "_title")

def get_playback_url(self, direct_play=True,
video_height=1080, video_width=1920,
video_bitrate=20000, video_quality=100):
def is_transcode_suggested(self):
if self._part_node:
if self._part_node.get("container") == "mov":
log.info("Video::is_transcode_suggested part container is mov, suggesting transcode")
return True
return False

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
Expand All @@ -137,11 +148,12 @@ def get_playback_url(self, direct_play=True,
"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=shoutcast,http-video;videoDecoders=h264{profile:high&resolution:1080&level:51};audioDecoders=mp3,aac"
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)")
Expand All @@ -152,9 +164,21 @@ def get_playback_url(self, direct_play=True,

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

return get_plex_url(urlparse.urljoin(self.parent.server_url, url), args)
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))

log.error("Video::get_playback_url couldn't generate playback url")

def get_audio_idx(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions omplex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def get_plex_url(url, data={}):
"X-Plex-Device": "RaspberryPI",

# Lies
"X-Plex-Product": "Plex Home Theater",
"X-Plex-Platform": "Plex Home Theater"
"X-Plex-Product": "Popcorn Hour",
"X-Plex-Platform": "Popcorn Hour"
})

# Kinda ghetto...
Expand Down

0 comments on commit e7ac08e

Please sign in to comment.