2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcplugin
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcaddon
|
|
|
|
import urllib
|
|
|
|
import datetime
|
|
|
|
import time
|
|
|
|
import json as json
|
|
|
|
import inspect
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from DownloadUtils import DownloadUtils
|
|
|
|
from PlayUtils import PlayUtils
|
2015-03-25 05:41:46 +11:00
|
|
|
from ReadKodiDB import ReadKodiDB
|
2015-03-26 03:01:13 +11:00
|
|
|
from ReadEmbyDB import ReadEmbyDB
|
2015-03-28 12:34:09 +11:00
|
|
|
import Utils as utils
|
2015-03-14 08:24:59 +11:00
|
|
|
from API import API
|
|
|
|
import Utils as utils
|
2015-03-22 14:19:26 +11:00
|
|
|
import os
|
|
|
|
import xbmcvfs
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-03-26 04:37:21 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
2015-03-22 14:19:26 +11:00
|
|
|
addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
WINDOW = xbmcgui.Window( 10000 )
|
|
|
|
|
|
|
|
class PlaybackUtils():
|
|
|
|
|
|
|
|
settings = None
|
2015-03-28 12:12:51 +11:00
|
|
|
language = addon.getLocalizedString
|
2015-03-14 08:24:59 +11:00
|
|
|
logLevel = 0
|
2015-03-28 22:16:55 +11:00
|
|
|
downloadUtils = DownloadUtils()
|
2015-07-23 18:18:17 +10:00
|
|
|
|
|
|
|
WINDOW.clearProperty('playurlFalse')
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
def __init__(self, *args):
|
|
|
|
pass
|
|
|
|
|
2015-05-03 07:40:30 +10:00
|
|
|
def PLAY(self, result, setup="service"):
|
2015-04-08 00:21:54 +10:00
|
|
|
xbmc.log("PLAY Called")
|
2015-04-14 04:56:36 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
|
|
|
|
username = WINDOW.getProperty('currUser')
|
|
|
|
userid = WINDOW.getProperty('userId%s' % username)
|
|
|
|
server = WINDOW.getProperty('server%s' % username)
|
2015-03-28 12:34:09 +11:00
|
|
|
|
2015-05-03 17:24:23 +10:00
|
|
|
try:
|
|
|
|
id = result["Id"]
|
|
|
|
except:
|
|
|
|
return
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-06-07 02:19:53 +10:00
|
|
|
userData = result['UserData']
|
2015-07-20 14:25:59 +10:00
|
|
|
|
|
|
|
# BOOKMARK - RESUME POINT
|
|
|
|
timeInfo = API().getTimeInfo(result)
|
|
|
|
jumpBackSec = int(addon.getSetting("resumeJumpBack"))
|
|
|
|
seekTime = round(float(timeInfo.get('ResumeTime')), 6)
|
|
|
|
if seekTime > jumpBackSec:
|
|
|
|
# To avoid negative bookmark
|
|
|
|
seekTime = seekTime - jumpBackSec
|
2015-06-07 02:19:53 +10:00
|
|
|
|
|
|
|
itemsToPlay = []
|
|
|
|
# Check for intros
|
|
|
|
if seekTime == 0:
|
|
|
|
# if we have any play them when the movie/show is not being resumed
|
|
|
|
# We can add the option right here
|
|
|
|
url = "{server}/mediabrowser/Users/{UserId}/Items/%s/Intros?format=json&ImageTypeLimit=1&Fields=Etag" % id
|
|
|
|
intros = self.downloadUtils.downloadUrl(url)
|
|
|
|
if intros[u'TotalRecordCount'] == 0:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
for intro in intros[u'Items']:
|
|
|
|
introId = intro[u'Id']
|
|
|
|
itemsToPlay.append(introId)
|
|
|
|
|
|
|
|
# Add original item
|
|
|
|
itemsToPlay.append(id)
|
|
|
|
|
2015-05-09 16:44:02 +10:00
|
|
|
# For split movies
|
|
|
|
if u'PartCount' in result:
|
|
|
|
partcount = result[u'PartCount']
|
|
|
|
# Get additional parts/playurl
|
|
|
|
url = "{server}/mediabrowser/Videos/%s/AdditionalParts" % id
|
|
|
|
parts = self.downloadUtils.downloadUrl(url)
|
|
|
|
for part in parts[u'Items']:
|
|
|
|
partId = part[u'Id']
|
2015-06-07 02:19:53 +10:00
|
|
|
itemsToPlay.append(partId)
|
2015-05-02 10:26:06 +10:00
|
|
|
|
2015-06-07 02:19:53 +10:00
|
|
|
if len(itemsToPlay) > 1:
|
|
|
|
# Let's play the playlist
|
|
|
|
return self.AddToPlaylist(itemsToPlay)
|
2015-06-06 00:46:17 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
playurl = PlayUtils().getPlayUrl(server, id, result)
|
2015-07-23 18:18:17 +10:00
|
|
|
if playurl == False or WINDOW.getProperty('playurlFalse') == "true":
|
|
|
|
WINDOW.clearProperty('playurlFalse')
|
2015-05-07 16:11:20 +10:00
|
|
|
xbmc.log("Failed to retrieve the playback path/url.")
|
|
|
|
return
|
2015-05-07 16:19:14 +10:00
|
|
|
|
2015-08-06 18:09:45 +10:00
|
|
|
if WINDOW.getProperty("%splaymethod" % playurl) == "Transcode":
|
|
|
|
playurlprefs = self.audioSubsPref(playurl, result.get("MediaSources"))
|
|
|
|
if playurlprefs:
|
|
|
|
playurl = playurlprefs
|
|
|
|
else: # User cancelled dialog
|
|
|
|
return
|
|
|
|
|
2015-03-15 05:17:16 +11:00
|
|
|
thumbPath = API().getArtwork(result, "Primary")
|
2015-03-22 14:19:26 +11:00
|
|
|
|
2015-05-07 01:02:16 +10:00
|
|
|
#if the file is a virtual strm file, we need to override the path by reading it's contents
|
|
|
|
if playurl.endswith(".strm"):
|
|
|
|
xbmc.log("virtual strm file file detected, starting playback with 3th party addon...")
|
|
|
|
StrmTemp = "special://temp/temp.strm"
|
|
|
|
xbmcvfs.copy(playurl, StrmTemp)
|
|
|
|
playurl = open(xbmc.translatePath(StrmTemp), 'r').readline()
|
|
|
|
|
2015-03-22 14:19:26 +11:00
|
|
|
listItem = xbmcgui.ListItem(path=playurl, iconImage=thumbPath, thumbnailImage=thumbPath)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
# Can not play virtual items
|
|
|
|
if (result.get("LocationType") == "Virtual"):
|
2015-03-28 12:12:51 +11:00
|
|
|
xbmcgui.Dialog().ok(self.language(30128), self.language(30129))
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-04-14 04:56:36 +10:00
|
|
|
watchedurl = "%s/mediabrowser/Users/%s/PlayedItems/%s" % (server, userid, id)
|
|
|
|
positionurl = "%s/mediabrowser/Users/%s/PlayingItems/%s" % (server, userid, id)
|
|
|
|
deleteurl = "%s/mediabrowser/Items/%s" % (server, id)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
# set the current playing info
|
|
|
|
WINDOW.setProperty(playurl+"watchedurl", watchedurl)
|
|
|
|
WINDOW.setProperty(playurl+"positionurl", positionurl)
|
|
|
|
WINDOW.setProperty(playurl+"deleteurl", "")
|
|
|
|
WINDOW.setProperty(playurl+"deleteurl", deleteurl)
|
|
|
|
|
2015-07-20 14:25:59 +10:00
|
|
|
#show the additional resume dialog if launched from a widget
|
|
|
|
if xbmc.getCondVisibility("Window.IsActive(home)"):
|
|
|
|
if seekTime != 0:
|
|
|
|
displayTime = str(datetime.timedelta(seconds=(int(seekTime))))
|
|
|
|
display_list = [ self.language(30106) + ' ' + displayTime, self.language(30107)]
|
|
|
|
resumeScreen = xbmcgui.Dialog()
|
|
|
|
resume_result = resumeScreen.select(self.language(30105), display_list)
|
|
|
|
if resume_result == 0:
|
|
|
|
listItem.setProperty('StartOffset', str(seekTime))
|
|
|
|
|
|
|
|
elif resume_result < 0:
|
|
|
|
# User cancelled dialog
|
|
|
|
xbmc.log("Emby player -> User cancelled resume dialog.")
|
2015-07-21 16:12:06 +10:00
|
|
|
xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listItem)
|
2015-07-20 14:25:59 +10:00
|
|
|
return
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
if result.get("Type")=="Episode":
|
|
|
|
WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId"))
|
|
|
|
else:
|
|
|
|
WINDOW.setProperty(playurl+"refresh_id", id)
|
|
|
|
|
|
|
|
WINDOW.setProperty(playurl+"runtimeticks", str(result.get("RunTimeTicks")))
|
|
|
|
WINDOW.setProperty(playurl+"type", result.get("Type"))
|
|
|
|
WINDOW.setProperty(playurl+"item_id", id)
|
|
|
|
|
2015-05-07 01:02:16 +10:00
|
|
|
#launch the playback - only set the listitem props if we're not using the setresolvedurl approach
|
2015-05-03 07:40:30 +10:00
|
|
|
if setup == "service":
|
2015-05-07 01:02:16 +10:00
|
|
|
self.setListItemProps(server, id, listItem, result)
|
2015-05-03 07:40:30 +10:00
|
|
|
xbmc.Player().play(playurl,listItem)
|
|
|
|
elif setup == "default":
|
2015-07-20 14:25:59 +10:00
|
|
|
if xbmc.getCondVisibility("Window.IsActive(home)"):
|
|
|
|
self.setListItemProps(server, id, listItem, result)
|
|
|
|
xbmc.Player().play(playurl,listItem)
|
|
|
|
else:
|
|
|
|
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-08-06 18:09:45 +10:00
|
|
|
def audioSubsPref(self, url, mediaSources):
|
|
|
|
|
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
# Present the list of audio to select from
|
|
|
|
audioStreamsList = {}
|
|
|
|
audioStreams = []
|
|
|
|
selectAudioIndex = ""
|
|
|
|
subtitleStreamsList = {}
|
|
|
|
subtitleStreams = ['No subtitles']
|
|
|
|
selectSubsIndex = ""
|
|
|
|
playurlprefs = "%s" % url
|
|
|
|
|
|
|
|
mediaStream = mediaSources[0].get('MediaStreams')
|
|
|
|
for stream in mediaStream:
|
|
|
|
index = stream['Index']
|
|
|
|
# Since Emby returns all possible tracks together, have to sort them.
|
|
|
|
if 'Audio' in stream['Type']:
|
|
|
|
try:
|
|
|
|
track = stream['Language']
|
|
|
|
audioStreamsList[track] = index
|
|
|
|
audioStreams.append(track)
|
|
|
|
except:
|
|
|
|
track = stream['Codec']
|
|
|
|
audioStreamsList[track] = index
|
|
|
|
audioStreams.append(track)
|
|
|
|
|
|
|
|
elif 'Subtitle' in stream['Type']:
|
|
|
|
try:
|
|
|
|
track = stream['Language']
|
|
|
|
subtitleStreamsList[track] = index
|
|
|
|
subtitleStreams.append(track)
|
|
|
|
except:
|
|
|
|
track = stream['Codec']
|
|
|
|
subtitleStreamsList[track] = index
|
|
|
|
subtitleStreams.append(track)
|
|
|
|
|
|
|
|
if len(audioStreams) > 1:
|
|
|
|
resp = xbmcgui.Dialog().select("Choose the audio stream", audioStreams)
|
|
|
|
if resp > -1:
|
|
|
|
# User selected audio
|
|
|
|
selected = audioStreams[resp]
|
|
|
|
selected_audioIndex = audioStreamsList[selected]
|
|
|
|
playurlprefs += "&AudioStreamIndex=%s" % selected_audioIndex
|
|
|
|
selectAudioIndex = str(selected_audioIndex)
|
|
|
|
else: return False
|
|
|
|
else: # There's only one audiotrack.
|
|
|
|
audioIndex = audioStreamsList[audioStreams[0]]
|
|
|
|
playurlprefs += "&AudioStreamIndex=%s" % audioIndex
|
|
|
|
selectAudioIndex = str(audioIndex)
|
|
|
|
|
|
|
|
if len(subtitleStreams) > 1:
|
|
|
|
resp = xbmcgui.Dialog().select("Choose the subtitle stream", subtitleStreams)
|
|
|
|
if resp == 0:
|
|
|
|
# User selected no subtitles
|
|
|
|
pass
|
|
|
|
elif resp > -1:
|
|
|
|
# User selected subtitles
|
|
|
|
selected = subtitleStreams[resp]
|
|
|
|
selected_subsIndex = subtitleStreamsList[selected]
|
|
|
|
playurlprefs += "&SubtitleStreamIndex=%s" % selected_subsIndex
|
|
|
|
selectSubsIndex = str(selected_subsIndex)
|
|
|
|
else: return False
|
|
|
|
|
|
|
|
# Reset the method with the new playurl
|
|
|
|
WINDOW.setProperty("%splaymethod" % playurlprefs, "Transcode")
|
|
|
|
WINDOW.setProperty("%sAudioStreamIndex" % playurlprefs, selectAudioIndex)
|
|
|
|
WINDOW.setProperty("%sSubtitleStreamIndex" % playurlprefs, selectSubsIndex)
|
|
|
|
|
|
|
|
return playurlprefs
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
def setArt(self, list,name,path):
|
|
|
|
if name=='thumb' or name=='fanart_image' or name=='small_poster' or name=='tiny_poster' or name == "medium_landscape" or name=='medium_poster' or name=='small_fanartimage' or name=='medium_fanartimage' or name=='fanart_noindicators':
|
|
|
|
list.setProperty(name, path)
|
|
|
|
else:
|
|
|
|
list.setArt({name:path})
|
|
|
|
return list
|
|
|
|
|
|
|
|
def setListItemProps(self, server, id, listItem, result):
|
|
|
|
# set up item and item info
|
|
|
|
thumbID = id
|
|
|
|
eppNum = -1
|
|
|
|
seasonNum = -1
|
|
|
|
tvshowTitle = ""
|
|
|
|
|
|
|
|
if(result.get("Type") == "Episode"):
|
|
|
|
thumbID = result.get("SeriesId")
|
|
|
|
seasonNum = result.get("ParentIndexNumber")
|
|
|
|
eppNum = result.get("IndexNumber")
|
|
|
|
tvshowTitle = result.get("SeriesName")
|
|
|
|
|
2015-03-15 05:17:16 +11:00
|
|
|
self.setArt(listItem,'poster', API().getArtwork(result, "Primary"))
|
|
|
|
self.setArt(listItem,'tvshow.poster', API().getArtwork(result, "SeriesPrimary"))
|
|
|
|
self.setArt(listItem,'clearart', API().getArtwork(result, "Art"))
|
|
|
|
self.setArt(listItem,'tvshow.clearart', API().getArtwork(result, "Art"))
|
|
|
|
self.setArt(listItem,'clearlogo', API().getArtwork(result, "Logo"))
|
|
|
|
self.setArt(listItem,'tvshow.clearlogo', API().getArtwork(result, "Logo"))
|
|
|
|
self.setArt(listItem,'discart', API().getArtwork(result, "Disc"))
|
|
|
|
self.setArt(listItem,'fanart_image', API().getArtwork(result, "Backdrop"))
|
|
|
|
self.setArt(listItem,'landscape', API().getArtwork(result, "Thumb"))
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
listItem.setProperty('IsPlayable', 'true')
|
|
|
|
listItem.setProperty('IsFolder', 'false')
|
|
|
|
|
|
|
|
# Process Studios
|
2015-03-15 05:17:16 +11:00
|
|
|
studios = API().getStudios(result)
|
2015-03-19 07:49:49 +11:00
|
|
|
if studios == []:
|
|
|
|
studio = ""
|
|
|
|
else:
|
|
|
|
studio = studios[0]
|
2015-03-14 08:24:59 +11:00
|
|
|
listItem.setInfo('video', {'studio' : studio})
|
|
|
|
|
|
|
|
details = {
|
2015-05-07 01:02:16 +10:00
|
|
|
'title' : result.get("Name", "Missing Name"),
|
2015-03-14 08:24:59 +11:00
|
|
|
'plot' : result.get("Overview")
|
|
|
|
}
|
|
|
|
|
|
|
|
if(eppNum > -1):
|
|
|
|
details["episode"] = str(eppNum)
|
|
|
|
|
|
|
|
if(seasonNum > -1):
|
|
|
|
details["season"] = str(seasonNum)
|
|
|
|
|
|
|
|
if tvshowTitle != None:
|
2015-04-14 04:56:36 +10:00
|
|
|
details["TVShowTitle"] = tvshowTitle
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
listItem.setInfo( "Video", infoLabels=details )
|
|
|
|
|
|
|
|
people = API().getPeople(result)
|
|
|
|
|
|
|
|
# Process Genres
|
|
|
|
genre = API().getGenre(result)
|
|
|
|
|
|
|
|
listItem.setInfo('video', {'director' : people.get('Director')})
|
|
|
|
listItem.setInfo('video', {'writer' : people.get('Writer')})
|
|
|
|
listItem.setInfo('video', {'mpaa': result.get("OfficialRating")})
|
2015-05-07 01:02:16 +10:00
|
|
|
listItem.setInfo('video', {'genre': API().getGenre(result)})
|
2015-03-23 15:54:16 +11:00
|
|
|
|
2015-03-28 12:34:09 +11:00
|
|
|
def seekToPosition(self, seekTo):
|
|
|
|
|
|
|
|
#Set a loop to wait for positive confirmation of playback
|
|
|
|
count = 0
|
|
|
|
while not xbmc.Player().isPlaying():
|
|
|
|
count = count + 1
|
|
|
|
if count >= 10:
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
xbmc.sleep(500)
|
|
|
|
|
|
|
|
#Jump to resume point
|
2015-07-20 11:35:14 +10:00
|
|
|
jumpBackSec = int(addon.getSetting("resumeJumpBack"))
|
2015-03-28 12:34:09 +11:00
|
|
|
seekToTime = seekTo - jumpBackSec
|
|
|
|
count = 0
|
|
|
|
while xbmc.Player().getTime() < (seekToTime - 5) and count < 11: # only try 10 times
|
|
|
|
count = count + 1
|
|
|
|
#xbmc.Player().pause
|
|
|
|
#xbmc.sleep(100)
|
|
|
|
xbmc.Player().seekTime(seekToTime)
|
|
|
|
xbmc.sleep(100)
|
|
|
|
#xbmc.Player().play()
|
|
|
|
|
|
|
|
def PLAYAllItems(self, items, startPositionTicks):
|
|
|
|
utils.logMsg("PlayBackUtils", "== ENTER: PLAYAllItems ==")
|
|
|
|
utils.logMsg("PlayBackUtils", "Items : " + str(items))
|
2015-04-14 04:56:36 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
|
|
|
|
username = WINDOW.getProperty('currUser')
|
|
|
|
userid = WINDOW.getProperty('userId%s' % username)
|
|
|
|
server = WINDOW.getProperty('server%s' % username)
|
2015-03-28 12:34:09 +11:00
|
|
|
|
|
|
|
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
|
|
|
playlist.clear()
|
|
|
|
started = False
|
|
|
|
|
|
|
|
for itemID in items:
|
|
|
|
|
|
|
|
utils.logMsg("PlayBackUtils", "Adding Item to Playlist : " + itemID)
|
2015-04-26 09:51:07 +10:00
|
|
|
item_url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json" % itemID
|
|
|
|
jsonData = self.downloadUtils.downloadUrl(item_url)
|
2015-04-14 04:56:36 +10:00
|
|
|
|
2015-04-26 09:51:07 +10:00
|
|
|
item_data = jsonData
|
2015-03-28 12:34:09 +11:00
|
|
|
added = self.addPlaylistItem(playlist, item_data, server, userid)
|
|
|
|
if(added and started == False):
|
|
|
|
started = True
|
|
|
|
utils.logMsg("PlayBackUtils", "Starting Playback Pre")
|
|
|
|
xbmc.Player().play(playlist)
|
|
|
|
|
|
|
|
if(started == False):
|
|
|
|
utils.logMsg("PlayBackUtils", "Starting Playback Post")
|
|
|
|
xbmc.Player().play(playlist)
|
|
|
|
|
|
|
|
#seek to position
|
|
|
|
seekTime = 0
|
|
|
|
if(startPositionTicks != None):
|
|
|
|
seekTime = (startPositionTicks / 1000) / 10000
|
|
|
|
|
|
|
|
if seekTime > 0:
|
|
|
|
self.seekToPosition(seekTime)
|
2015-04-08 00:21:54 +10:00
|
|
|
|
|
|
|
def PLAYAllEpisodes(self, items):
|
2015-04-14 04:56:36 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
|
|
|
|
username = WINDOW.getProperty('currUser')
|
|
|
|
userid = WINDOW.getProperty('userId%s' % username)
|
|
|
|
server = WINDOW.getProperty('server%s' % username)
|
2015-04-08 00:21:54 +10:00
|
|
|
|
|
|
|
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
|
|
|
playlist.clear()
|
|
|
|
|
|
|
|
for item in items:
|
|
|
|
|
2015-04-26 09:51:07 +10:00
|
|
|
item_url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&ImageTypeLimit=1" % item["Id"]
|
|
|
|
jsonData = self.downloadUtils.downloadUrl(item_url)
|
2015-04-08 00:21:54 +10:00
|
|
|
|
2015-04-26 09:51:07 +10:00
|
|
|
item_data = jsonData
|
2015-04-08 00:21:54 +10:00
|
|
|
self.addPlaylistItem(playlist, item_data, server, userid)
|
|
|
|
|
|
|
|
xbmc.Player().play(playlist)
|
2015-03-28 12:34:09 +11:00
|
|
|
|
|
|
|
def AddToPlaylist(self, itemIds):
|
|
|
|
utils.logMsg("PlayBackUtils", "== ENTER: PLAYAllItems ==")
|
2015-04-14 04:56:36 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
|
|
|
|
username = WINDOW.getProperty('currUser')
|
|
|
|
userid = WINDOW.getProperty('userId%s' % username)
|
|
|
|
server = WINDOW.getProperty('server%s' % username)
|
2015-03-28 12:34:09 +11:00
|
|
|
|
|
|
|
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
|
|
|
|
|
|
|
for itemID in itemIds:
|
|
|
|
|
|
|
|
utils.logMsg("PlayBackUtils", "Adding Item to Playlist : " + itemID)
|
2015-04-26 09:51:07 +10:00
|
|
|
item_url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json" % itemID
|
|
|
|
jsonData = self.downloadUtils.downloadUrl(item_url)
|
2015-03-28 12:34:09 +11:00
|
|
|
|
2015-04-26 09:51:07 +10:00
|
|
|
item_data = jsonData
|
2015-03-28 12:34:09 +11:00
|
|
|
self.addPlaylistItem(playlist, item_data, server, userid)
|
|
|
|
|
|
|
|
return playlist
|
|
|
|
|
|
|
|
def addPlaylistItem(self, playlist, item, server, userid):
|
|
|
|
|
|
|
|
id = item.get("Id")
|
|
|
|
|
|
|
|
playurl = PlayUtils().getPlayUrl(server, id, item)
|
|
|
|
utils.logMsg("PlayBackUtils", "Play URL: " + playurl)
|
|
|
|
thumbPath = API().getArtwork(item, "Primary")
|
|
|
|
listItem = xbmcgui.ListItem(path=playurl, iconImage=thumbPath, thumbnailImage=thumbPath)
|
|
|
|
self.setListItemProps(server, id, listItem, item)
|
|
|
|
|
2015-04-14 04:56:36 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
|
|
|
|
username = WINDOW.getProperty('currUser')
|
|
|
|
userid = WINDOW.getProperty('userId%s' % username)
|
|
|
|
server = WINDOW.getProperty('server%s' % username)
|
|
|
|
|
2015-03-28 12:34:09 +11:00
|
|
|
# Can not play virtual items
|
|
|
|
if (item.get("LocationType") == "Virtual") or (item.get("IsPlaceHolder") == True):
|
|
|
|
|
|
|
|
xbmcgui.Dialog().ok(self.language(30128), self.language(30129))
|
|
|
|
return False
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
2015-04-14 04:56:36 +10:00
|
|
|
watchedurl = "%s/mediabrowser/Users/%s/PlayedItems/%s" % (server, userid, id)
|
|
|
|
positionurl = "%s/mediabrowser/Users/%s/PlayingItems/%s" % (server, userid, id)
|
|
|
|
deleteurl = "%s/mediabrowser/Items/%s" % (server, id)
|
2015-03-28 12:34:09 +11:00
|
|
|
|
|
|
|
# set the current playing info
|
|
|
|
WINDOW = xbmcgui.Window( 10000 )
|
|
|
|
WINDOW.setProperty(playurl + "watchedurl", watchedurl)
|
|
|
|
WINDOW.setProperty(playurl + "positionurl", positionurl)
|
|
|
|
WINDOW.setProperty(playurl + "deleteurl", "")
|
|
|
|
|
2015-07-05 01:04:04 +10:00
|
|
|
if item.get("Type") == "Episode" and addon.getSetting("offerDeleteTV")=="true":
|
2015-03-28 12:34:09 +11:00
|
|
|
WINDOW.setProperty(playurl + "deleteurl", deleteurl)
|
2015-07-05 01:04:04 +10:00
|
|
|
if item.get("Type") == "Movie" and addon.getSetting("offerDeleteMovies")=="true":
|
2015-07-20 11:35:14 +10:00
|
|
|
WINDOW.setProperty(playurl + "deleteurl", deleteurl)
|
2015-03-28 12:34:09 +11:00
|
|
|
|
|
|
|
WINDOW.setProperty(playurl + "runtimeticks", str(item.get("RunTimeTicks")))
|
|
|
|
WINDOW.setProperty(playurl+"type", item.get("Type"))
|
|
|
|
WINDOW.setProperty(playurl + "item_id", id)
|
|
|
|
|
|
|
|
if (item.get("Type") == "Episode"):
|
|
|
|
WINDOW.setProperty(playurl + "refresh_id", item.get("SeriesId"))
|
|
|
|
else:
|
|
|
|
WINDOW.setProperty(playurl + "refresh_id", id)
|
|
|
|
|
|
|
|
utils.logMsg("PlayBackUtils", "PlayList Item Url : " + str(playurl))
|
|
|
|
|
|
|
|
playlist.add(playurl, listItem)
|
|
|
|
|
2015-03-28 22:16:55 +11:00
|
|
|
return True
|