Default to play from HTTP

Add download external subs option. With testing, we can determine if we
even need a second option or if it should be downloading by default as a
workaround to not being able to label external tracks when using url in
Kodi.
This commit is contained in:
angelblue05 2016-08-30 00:22:54 -05:00
parent 00c0556300
commit a331f7d43d
3 changed files with 51 additions and 2 deletions

View file

@ -4,11 +4,15 @@
import json import json
import logging import logging
import requests
import os
import shutil
import sys import sys
import xbmc import xbmc
import xbmcgui import xbmcgui
import xbmcplugin import xbmcplugin
import xbmcvfs
import api import api
import artwork import artwork
@ -246,6 +250,9 @@ class PlaybackUtils():
except (TypeError, KeyError, IndexError): except (TypeError, KeyError, IndexError):
return return
temp = xbmc.translatePath(
"special://profile/addon_data/plugin.video.emby/temp/").decode('utf-8')
kodiindex = 0 kodiindex = 0
for stream in mediastreams: for stream in mediastreams:
@ -258,10 +265,21 @@ class PlaybackUtils():
# Direct stream # Direct stream
url = ("%s/Videos/%s/%s/Subtitles/%s/Stream.srt" url = ("%s/Videos/%s/%s/Subtitles/%s/Stream.srt"
% (self.server, itemid, itemid, index)) % (self.server, itemid, itemid, index))
if settings('downloadExternalSubs') == "true":
filename = "Stream.%s.srt" % stream['Language']
try:
path = self._download_external_subs(url, temp, filename)
externalsubs.append(path)
except Exception as e:
log.error(e)
continue
else:
externalsubs.append(url)
# map external subtitles for mapping # map external subtitles for mapping
mapping[kodiindex] = index mapping[kodiindex] = index
externalsubs.append(url)
kodiindex += 1 kodiindex += 1
mapping = json.dumps(mapping) mapping = json.dumps(mapping)
@ -269,6 +287,27 @@ class PlaybackUtils():
return externalsubs return externalsubs
def _download_external_subs(self, src, dst, filename):
if not xbmcvfs.exists(dst):
xbmcvfs.mkdir(dst)
path = os.path.join(dst, filename)
try:
response = requests.get(src, stream=True)
response.raise_for_status()
except Exception as e:
del response
raise
else:
f = open(path, 'wb')
f.write(response.content)
f.close()
del response
return path
def setArtwork(self, listItem): def setArtwork(self, listItem):
# Set up item and item info # Set up item and item info
allartwork = self.artwork.getAllArtwork(self.item, parentInfo=True) allartwork = self.artwork.getAllArtwork(self.item, parentInfo=True)

View file

@ -6,6 +6,7 @@ import json
import logging import logging
import xbmc import xbmc
import xbmcvfs
import xbmcgui import xbmcgui
import clientinfo import clientinfo
@ -473,6 +474,7 @@ class Player(xbmc.Player):
else: else:
log.info("User skipped deletion.") log.info("User skipped deletion.")
self.stopPlayback(data) self.stopPlayback(data)
# Stop transcoding # Stop transcoding
@ -481,6 +483,13 @@ class Player(xbmc.Player):
deviceId = self.clientInfo.getDeviceId() deviceId = self.clientInfo.getDeviceId()
url = "{server}/emby/Videos/ActiveEncodings?DeviceId=%s" % deviceId url = "{server}/emby/Videos/ActiveEncodings?DeviceId=%s" % deviceId
self.doUtils(url, action_type="DELETE") self.doUtils(url, action_type="DELETE")
path = xbmc.translatePath(
"special://profile/addon_data/plugin.video.emby/temp/").decode('utf-8')
dirs, files = xbmcvfs.listdir(path)
for file in files:
xbmcvfs.delete("%s%s" % (path, file))
self.played_info.clear() self.played_info.clear()

View file

@ -52,9 +52,10 @@
<setting id="deleteMovies" type="bool" label="30116" visible="eq(-2,true)" default="false" subsetting="true" /> <setting id="deleteMovies" type="bool" label="30116" visible="eq(-2,true)" default="false" subsetting="true" />
<setting id="resumeJumpBack" type="slider" label="30521" default="10" range="0,1,120" option="int" /> <setting id="resumeJumpBack" type="slider" label="30521" default="10" range="0,1,120" option="int" />
<setting type="sep" /> <setting type="sep" />
<setting id="playFromStream" type="bool" label="30002" default="false" /> <setting id="playFromStream" type="bool" label="30002" default="true" />
<setting id="videoBitrate" type="enum" label="30160" values="664 Kbps SD|996 Kbps HD|1.3 Mbps HD|2.0 Mbps HD|3.2 Mbps HD|4.7 Mbps HD|6.2 Mbps HD|7.7 Mbps HD|9.2 Mbps HD|10.7 Mbps HD|12.2 Mbps HD|13.7 Mbps HD|15.2 Mbps HD|16.7 Mbps HD|18.2 Mbps HD|20.0 Mbps HD|40.0 Mbps HD|100.0 Mbps HD [default]|1000.0 Mbps HD" visible="true" default="17" subsetting="true" /> <setting id="videoBitrate" type="enum" label="30160" values="664 Kbps SD|996 Kbps HD|1.3 Mbps HD|2.0 Mbps HD|3.2 Mbps HD|4.7 Mbps HD|6.2 Mbps HD|7.7 Mbps HD|9.2 Mbps HD|10.7 Mbps HD|12.2 Mbps HD|13.7 Mbps HD|15.2 Mbps HD|16.7 Mbps HD|18.2 Mbps HD|20.0 Mbps HD|40.0 Mbps HD|100.0 Mbps HD [default]|1000.0 Mbps HD" visible="true" default="17" subsetting="true" />
<setting id="enableExternalSubs" type="bool" label="Enable external subs for direct stream" default="true" /> <setting id="enableExternalSubs" type="bool" label="Enable external subs for direct stream" default="true" />
<setting id="downloadExternalSubs" type="bool" label="Download external subs" visible="eq(-1,true)" default="true" subsetting="true" />
<setting id="transcodeH265" type="enum" label="30522" default="0" values="Disabled|480p(and higher)|720p(and higher)|1080p" /> <setting id="transcodeH265" type="enum" label="30522" default="0" values="Disabled|480p(and higher)|720p(and higher)|1080p" />
<setting id="transcodeHi10P" type="bool" label="30537" default="false"/> <setting id="transcodeHi10P" type="bool" label="30537" default="false"/>
<setting id="markPlayed" type="number" visible="false" default="90" /> <setting id="markPlayed" type="number" visible="false" default="90" />