change strm handling (#9)
- change strm handling - don't write .strm file - return and set any listitem properties that are in strm - resolves: https://emby.media/community/index.php?/topic/46651-embycon/page-4#entry456816 while maintaining inputstream support * refactor of strm handling
This commit is contained in:
@@ -61,8 +61,19 @@ def playFile(id, auto_resume):
|
||||
elif resume_result == -1:
|
||||
return
|
||||
|
||||
playurl = PlayUtils().getPlayUrl(id, result)
|
||||
log.info("Play URL: " + playurl)
|
||||
listitem_props = []
|
||||
playurl = None
|
||||
|
||||
# check if strm file, path will contain contain strm contents
|
||||
if result.get('MediaSources'):
|
||||
source = result['MediaSources'][0]
|
||||
if source.get('Container') == 'strm':
|
||||
playurl, listitem_props = PlayUtils().getStrmDetails(result)
|
||||
|
||||
if not playurl:
|
||||
playurl = PlayUtils().getPlayUrl(id, result)
|
||||
|
||||
log.info("Play URL: " + playurl + " ListItem Properties: " + str(listitem_props))
|
||||
|
||||
playback_type_string = "DirectPlay"
|
||||
if playback_type == "1":
|
||||
@@ -75,7 +86,7 @@ def playFile(id, auto_resume):
|
||||
|
||||
listItem = xbmcgui.ListItem(label=result.get("Name", i18n('missing_title')), path=playurl)
|
||||
|
||||
listItem = setListItemProps(id, listItem, result, server)
|
||||
listItem = setListItemProps(id, listItem, result, server, listitem_props)
|
||||
|
||||
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
||||
playlist.clear()
|
||||
@@ -102,7 +113,7 @@ def playFile(id, auto_resume):
|
||||
# xbmc.Player().play()
|
||||
|
||||
|
||||
def setListItemProps(id, listItem, result, server):
|
||||
def setListItemProps(id, listItem, result, server, extra_props):
|
||||
# set up item and item info
|
||||
thumbID = id
|
||||
eppNum = -1
|
||||
@@ -117,6 +128,9 @@ def setListItemProps(id, listItem, result, server):
|
||||
listItem.setProperty('IsPlayable', 'true')
|
||||
listItem.setProperty('IsFolder', 'false')
|
||||
|
||||
for prop in extra_props:
|
||||
listItem.setProperty(prop[0], prop[1])
|
||||
|
||||
# play info
|
||||
details = {
|
||||
'title': result.get("Name", i18n('missing_title')),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Gnu General Public License - see LICENSE.TXT
|
||||
import xbmc
|
||||
import xbmcaddon
|
||||
import xbmcvfs
|
||||
|
||||
import re
|
||||
|
||||
from downloadutils import DownloadUtils
|
||||
from simple_logging import SimpleLogging
|
||||
@@ -25,22 +25,6 @@ class PlayUtils():
|
||||
log.info("playback_type: " + playback_type)
|
||||
playurl = None
|
||||
|
||||
# check if strm file, will contain contain playback url
|
||||
if result.get('MediaSources'):
|
||||
source = result['MediaSources'][0]
|
||||
if source.get('Container') == 'strm':
|
||||
strm_path = xbmc.translatePath('special://temp/')
|
||||
strm_file = xbmc.translatePath('special://temp/embycon.strm')
|
||||
if not xbmcvfs.exists(strm_path):
|
||||
xbmcvfs.mkdirs(strm_path)
|
||||
f = xbmcvfs.File(strm_file, mode='w') # create a temp local .strm, required for inputstream(strm contains listitem properties and path)
|
||||
contents = source.get('Path').encode('utf-8') # contains contents of strm file with linebreaks
|
||||
f.write(contents)
|
||||
f.close()
|
||||
playurl = strm_file if xbmcvfs.exists(strm_file) else None
|
||||
if playurl:
|
||||
return playurl
|
||||
|
||||
# do direct path playback
|
||||
if playback_type == "0":
|
||||
playurl = result.get("Path")
|
||||
@@ -83,6 +67,30 @@ class PlayUtils():
|
||||
log.info("Playback URL: " + playurl)
|
||||
return playurl.encode('utf-8')
|
||||
|
||||
def getStrmDetails(self, result):
|
||||
playurl = None
|
||||
listitem_props = []
|
||||
|
||||
source = result['MediaSources'][0]
|
||||
contents = source.get('Path').encode('utf-8') # contains contents of strm file with linebreaks
|
||||
|
||||
line_break = '\r'
|
||||
if '\r\n' in contents:
|
||||
line_break += '\n'
|
||||
|
||||
lines = contents.split(line_break)
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if line.startswith('#KODIPROP:'):
|
||||
match = re.search('#KODIPROP:(?P<item_property>[^=]+?)=(?P<property_value>.+)', line)
|
||||
if match:
|
||||
listitem_props.append((match.group('item_property'), match.group('property_value')))
|
||||
elif line != '':
|
||||
playurl = line
|
||||
|
||||
log.info("Playback URL: " + playurl + " ListItem Properties: " + str(listitem_props))
|
||||
return playurl, listitem_props
|
||||
|
||||
|
||||
def getDetailsString():
|
||||
|
||||
|
||||
Reference in New Issue
Block a user