Redirect /Extras calls by e.g. Video Extras plugin

- Could start playing a movie, e.g. when starting up Kodi
This commit is contained in:
tomkat83 2016-04-09 15:46:51 +02:00
parent 2cde3814d7
commit ffa8e10099
2 changed files with 76 additions and 41 deletions

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
################################################################################################# ###############################################################################
import os import os
import sys import sys
@ -10,24 +10,24 @@ import xbmc
import xbmcaddon import xbmcaddon
import xbmcgui import xbmcgui
################################################################################################# ###############################################################################
addon_ = xbmcaddon.Addon(id='plugin.video.plexkodiconnect') addon_ = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
addon_path = addon_.getAddonInfo('path').decode('utf-8') addon_path = addon_.getAddonInfo('path').decode('utf-8')
base_resource = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8') base_resource = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8')
sys.path.append(base_resource) sys.path.append(base_resource)
################################################################################################# ###############################################################################
import entrypoint import entrypoint
import utils import utils
################################################################################################# ###############################################################################
enableProfiling = False enableProfiling = False
class Main:
class Main:
# MAIN ENTRY POINT # MAIN ENTRY POINT
def __init__(self): def __init__(self):
@ -79,10 +79,11 @@ class Main:
embyid = params.get('id',[""])[0] embyid = params.get('id',[""])[0]
entrypoint.getExtraFanArt(embyid,embypath) entrypoint.getExtraFanArt(embyid,embypath)
if "/Extras" in sys.argv[0] or "/VideoFiles" in sys.argv[0]: # Called by e.g. 3rd party plugin video extras
embypath = sys.argv[2][1:] if ("/Extras" in sys.argv[0] or "/VideoFiles" in sys.argv[0] or
embyid = params.get('id',[""])[0] "/Extras" in sys.argv[2]):
entrypoint.getVideoFiles(embyid,embypath) plexId = params.get('id', [None])[0]
entrypoint.getVideoFiles(plexId, params)
if modes.get(mode): if modes.get(mode):
# Simple functions # Simple functions

View file

@ -241,11 +241,11 @@ def doPlayback(itemid, dbid):
string = xbmcaddon.Addon().getLocalizedString string = xbmcaddon.Addon().getLocalizedString
# Not yet connected to a PMS server # Not yet connected to a PMS server
xbmcgui.Dialog().notification( xbmcgui.Dialog().notification(
heading=addonName, addonName,
message=string(39210), string(39210),
icon=xbmcgui.NOTIFICATION_ERROR, xbmcgui.NOTIFICATION_ERROR,
time=7000, 7000,
sound=True) True)
return xbmcplugin.setResolvedUrl( return xbmcplugin.setResolvedUrl(
int(sys.argv[1]), False, xbmcgui.ListItem()) int(sys.argv[1]), False, xbmcgui.ListItem())
@ -1259,32 +1259,66 @@ def getRecentEpisodes(viewid, mediatype, tagname, limit):
xbmcplugin.endOfDirectory(handle=int(sys.argv[1])) xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
##### GET VIDEO EXTRAS FOR LISTITEM #####
def getVideoFiles(embyId,embyPath): def getVideoFiles(plexId, params):
#returns the video files for the item as plugin listing, can be used for browsing the actual files or videoextras etc. """
emby = embyserver.Read_EmbyServer() GET VIDEO EXTRAS FOR LISTITEM
if not embyId:
if "plugin.video.emby" in embyPath: returns the video files for the item as plugin listing, can be used for
embyId = embyPath.split("/")[-2] browsing the actual files or videoextras etc.
if embyId: """
item = emby.getItem(embyId) if plexId is None:
putils = playutils.PlayUtils(item) filename = params.get('filename')
if putils.isDirectPlay(): if filename is not None:
#only proceed if we can access the files directly. TODO: copy local on the fly if accessed outside filename = filename[0]
filelocation = putils.directPlay() import re
if not filelocation.endswith("/"): regex = re.compile(r'''library/metadata/(\d+)''')
filelocation = filelocation.rpartition("/")[0] filename = regex.findall(filename)
dirs, files = xbmcvfs.listdir(filelocation) try:
plexId = filename[0]
except IndexError:
pass
if plexId is None:
utils.logMsg(title, 'No Plex ID found, abort getting Extras', 0)
return xbmcplugin.endOfDirectory(int(sys.argv[1]))
item = PlexFunctions.GetPlexMetadata(plexId)
try:
path = item[0][0][0].attrib['file']
except:
utils.logMsg(title, 'Could not get file path for item %s'
% plexId, -1)
return xbmcplugin.endOfDirectory(int(sys.argv[1]))
# Assign network protocol
if path.startswith('\\\\'):
path = path.replace('\\\\', 'smb://')
path = path.replace('\\', '/')
# Plex returns Windows paths as e.g. 'c:\slfkjelf\slfje\file.mkv'
elif '\\' in path:
path = path.replace('\\', '\\\\')
# Directory only, get rid of filename (!! exists() needs / or \ at end)
path = path.replace(os.path.basename(path), '')
# Only proceed if we can access this folder
if xbmcvfs.exists(path):
# Careful, returns encoded strings!
dirs, files = xbmcvfs.listdir(path)
for file in files: for file in files:
file = filelocation + file file = path + file.decode('utf-8')
li = xbmcgui.ListItem(file, path=file) li = xbmcgui.ListItem(file, path=file)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=file, listitem=li) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
url=file.encode('utf-8'),
listitem=li)
for dir in dirs: for dir in dirs:
dir = filelocation + dir dir = path + dir.decode('utf-8')
li = xbmcgui.ListItem(dir, path=dir) li = xbmcgui.ListItem(dir, path=dir)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=dir, listitem=li, isFolder=True) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
url=dir.encode('utf-8'),
listitem=li,
isFolder=True)
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(int(sys.argv[1]))
##### GET EXTRAFANART FOR LISTITEM ##### ##### GET EXTRAFANART FOR LISTITEM #####
def getExtraFanArt(embyId,embyPath): def getExtraFanArt(embyId,embyPath):