From a331f7d43df45970a583c05efa0d2361d75bab90 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Tue, 30 Aug 2016 00:22:54 -0500 Subject: [PATCH] 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. --- resources/lib/playbackutils.py | 41 +++++++++++++++++++++++++++++++++- resources/lib/player.py | 9 ++++++++ resources/settings.xml | 3 ++- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/resources/lib/playbackutils.py b/resources/lib/playbackutils.py index f089195a..084650ca 100644 --- a/resources/lib/playbackutils.py +++ b/resources/lib/playbackutils.py @@ -4,11 +4,15 @@ import json import logging +import requests +import os +import shutil import sys import xbmc import xbmcgui import xbmcplugin +import xbmcvfs import api import artwork @@ -246,6 +250,9 @@ class PlaybackUtils(): except (TypeError, KeyError, IndexError): return + temp = xbmc.translatePath( + "special://profile/addon_data/plugin.video.emby/temp/").decode('utf-8') + kodiindex = 0 for stream in mediastreams: @@ -258,10 +265,21 @@ class PlaybackUtils(): # Direct stream url = ("%s/Videos/%s/%s/Subtitles/%s/Stream.srt" % (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 mapping[kodiindex] = index - externalsubs.append(url) kodiindex += 1 mapping = json.dumps(mapping) @@ -269,6 +287,27 @@ class PlaybackUtils(): 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): # Set up item and item info allartwork = self.artwork.getAllArtwork(self.item, parentInfo=True) diff --git a/resources/lib/player.py b/resources/lib/player.py index 1fd19135..57114af3 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -6,6 +6,7 @@ import json import logging import xbmc +import xbmcvfs import xbmcgui import clientinfo @@ -473,6 +474,7 @@ class Player(xbmc.Player): else: log.info("User skipped deletion.") + self.stopPlayback(data) # Stop transcoding @@ -481,6 +483,13 @@ class Player(xbmc.Player): deviceId = self.clientInfo.getDeviceId() url = "{server}/emby/Videos/ActiveEncodings?DeviceId=%s" % deviceId 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() diff --git a/resources/settings.xml b/resources/settings.xml index 25e8b247..ac6ddd0f 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -52,9 +52,10 @@ - + +