added support for strm files played through the addon
This commit is contained in:
parent
fedb6b4893
commit
e10801cb48
2 changed files with 54 additions and 11 deletions
|
@ -15,8 +15,11 @@ downloadUtils = DownloadUtils()
|
||||||
from PlayUtils import PlayUtils
|
from PlayUtils import PlayUtils
|
||||||
from API import API
|
from API import API
|
||||||
import Utils as utils
|
import Utils as utils
|
||||||
|
import os
|
||||||
|
import xbmcvfs
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
|
||||||
language = addon.getLocalizedString
|
language = addon.getLocalizedString
|
||||||
|
|
||||||
WINDOW = xbmcgui.Window( 10000 )
|
WINDOW = xbmcgui.Window( 10000 )
|
||||||
|
@ -56,9 +59,23 @@ class PlaybackUtils():
|
||||||
|
|
||||||
|
|
||||||
playurl = PlayUtils().getPlayUrl(server, id, result)
|
playurl = PlayUtils().getPlayUrl(server, id, result)
|
||||||
thumbPath = API().getArtwork(result, "Primary")
|
|
||||||
listItem = xbmcgui.ListItem(path=playurl, iconImage=thumbPath, thumbnailImage=thumbPath)
|
|
||||||
|
|
||||||
|
isStrmFile = False
|
||||||
|
thumbPath = API().getArtwork(result, "Primary")
|
||||||
|
|
||||||
|
#workaround for when the file to play is a strm file itself
|
||||||
|
if playurl.endswith(".strm"):
|
||||||
|
isStrmFile = True
|
||||||
|
tempPath = os.path.join(addondir,"library","temp.strm")
|
||||||
|
xbmcvfs.copy(playurl, tempPath)
|
||||||
|
sfile = open(tempPath, 'r')
|
||||||
|
playurl = sfile.readline()
|
||||||
|
sfile.close()
|
||||||
|
xbmcvfs.delete(tempPath)
|
||||||
|
WINDOW.setProperty("virtualstrm", id)
|
||||||
|
WINDOW.setProperty("virtualstrmtype", result.get("Type"))
|
||||||
|
|
||||||
|
listItem = xbmcgui.ListItem(path=playurl, iconImage=thumbPath, thumbnailImage=thumbPath)
|
||||||
self.setListItemProps(server, id, listItem, result)
|
self.setListItemProps(server, id, listItem, result)
|
||||||
|
|
||||||
# Can not play virtual items
|
# Can not play virtual items
|
||||||
|
@ -105,6 +122,9 @@ class PlaybackUtils():
|
||||||
|
|
||||||
#this launches the playback
|
#this launches the playback
|
||||||
#artwork only works with both resolvedurl and player command
|
#artwork only works with both resolvedurl and player command
|
||||||
|
if isStrmFile:
|
||||||
|
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
|
||||||
|
else:
|
||||||
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
|
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
|
||||||
xbmc.Player().play(playurl,listItem)
|
xbmc.Player().play(playurl,listItem)
|
||||||
|
|
||||||
|
@ -115,6 +135,7 @@ class PlaybackUtils():
|
||||||
list.setArt({name:path})
|
list.setArt({name:path})
|
||||||
return list
|
return list
|
||||||
|
|
||||||
|
|
||||||
def setListItemProps(self, server, id, listItem, result):
|
def setListItemProps(self, server, id, listItem, result):
|
||||||
# set up item and item info
|
# set up item and item info
|
||||||
userid = downloadUtils.getUserId()
|
userid = downloadUtils.getUserId()
|
||||||
|
|
|
@ -91,9 +91,7 @@ class Player( xbmc.Player ):
|
||||||
currentFile = data.get("currentfile")
|
currentFile = data.get("currentfile")
|
||||||
type = data.get("Type")
|
type = data.get("Type")
|
||||||
|
|
||||||
if(refresh_id != None):
|
|
||||||
#report updates playcount and resume status to Kodi and MB3
|
|
||||||
librarySync.updatePlayCount(item_id,type)
|
|
||||||
|
|
||||||
if(currentPosition != None and self.hasData(runtime)):
|
if(currentPosition != None and self.hasData(runtime)):
|
||||||
runtimeTicks = int(runtime)
|
runtimeTicks = int(runtime)
|
||||||
|
@ -110,6 +108,9 @@ class Player( xbmc.Player ):
|
||||||
self.printDebug("mb3sync Service -> Offering Delete:" + str(deleteurl),2)
|
self.printDebug("mb3sync Service -> Offering Delete:" + str(deleteurl),2)
|
||||||
gotDeleted = self.deleteItem(deleteurl)
|
gotDeleted = self.deleteItem(deleteurl)
|
||||||
|
|
||||||
|
if(refresh_id != None):
|
||||||
|
#report updates playcount and resume status to Kodi and MB3
|
||||||
|
librarySync.updatePlayCount(item_id,type)
|
||||||
|
|
||||||
self.played_information.clear()
|
self.played_information.clear()
|
||||||
|
|
||||||
|
@ -253,18 +254,20 @@ class Player( xbmc.Player ):
|
||||||
|
|
||||||
self.downloadUtils.downloadUrl(url, postBody="", type="POST")
|
self.downloadUtils.downloadUrl(url, postBody="", type="POST")
|
||||||
|
|
||||||
|
jsonData = downloadUtils.downloadUrl("http://" + server + "/mediabrowser/Users/" + userid + "/Items/" + id + "?format=json&ImageTypeLimit=1", suppress=False, popup=1 )
|
||||||
|
|
||||||
# save data map for updates and position calls
|
# save data map for updates and position calls
|
||||||
data = {}
|
data = {}
|
||||||
data["deleteurl"] = deleteurl
|
data["deleteurl"] = deleteurl
|
||||||
data["runtime"] = runtime
|
data["runtime"] = runtime
|
||||||
data["item_id"] = item_id
|
data["item_id"] = item_id
|
||||||
data["refresh_id"] = refresh_id
|
data["refresh_id"] = refresh_id
|
||||||
data["currentfile"] = currentFile
|
data["currentfile"] = xbmc.Player().getPlayingFile()
|
||||||
data["AudioStreamIndex"] = audioindex
|
data["AudioStreamIndex"] = audioindex
|
||||||
data["SubtitleStreamIndex"] = subtitleindex
|
data["SubtitleStreamIndex"] = subtitleindex
|
||||||
data["playmethod"] = playMethod
|
data["playmethod"] = playMethod
|
||||||
data["Type"] = itemType
|
data["Type"] = itemType
|
||||||
self.played_information[currentFile] = data
|
self.played_information[xbmc.Player().getPlayingFile()] = data
|
||||||
|
|
||||||
self.printDebug("mb3sync Service -> ADDING_FILE : " + currentFile,2)
|
self.printDebug("mb3sync Service -> ADDING_FILE : " + currentFile,2)
|
||||||
self.printDebug("mb3sync Service -> ADDING_FILE : " + str(self.played_information),2)
|
self.printDebug("mb3sync Service -> ADDING_FILE : " + str(self.played_information),2)
|
||||||
|
@ -293,6 +296,25 @@ class Player( xbmc.Player ):
|
||||||
def onPlayBackEnded( self ):
|
def onPlayBackEnded( self ):
|
||||||
# Will be called when xbmc stops playing a file
|
# Will be called when xbmc stops playing a file
|
||||||
self.printDebug("mb3sync Service -> onPlayBackEnded",2)
|
self.printDebug("mb3sync Service -> onPlayBackEnded",2)
|
||||||
|
|
||||||
|
#workaround when strm files are launched through the addon - mark watched when finished playing
|
||||||
|
#TODO --> mark watched when 95% is played of the file
|
||||||
|
WINDOW = xbmcgui.Window( 10000 )
|
||||||
|
if WINDOW.getProperty("virtualstrm") != "":
|
||||||
|
try:
|
||||||
|
id = WINDOW.getProperty("virtualstrm")
|
||||||
|
type = WINDOW.getProperty("virtualstrmtype")
|
||||||
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
port = addon.getSetting('port')
|
||||||
|
host = addon.getSetting('ipaddress')
|
||||||
|
server = host + ":" + port
|
||||||
|
userid = self.downloadUtils.getUserId()
|
||||||
|
watchedurl = 'http://' + server + '/mediabrowser/Users/' + userid + '/PlayedItems/' + id
|
||||||
|
self.downloadUtils.downloadUrl(watchedurl, postBody="", type="POST")
|
||||||
|
librarySync.updatePlayCount(id,type)
|
||||||
|
except: pass
|
||||||
|
WINDOW.clearProperty("virtualstrm")
|
||||||
|
|
||||||
self.stopAll()
|
self.stopAll()
|
||||||
|
|
||||||
def onPlayBackStopped( self ):
|
def onPlayBackStopped( self ):
|
||||||
|
|
Loading…
Reference in a new issue