Migliorie contextmenu
This commit is contained in:
@@ -12,10 +12,6 @@
|
||||
</extension>
|
||||
<extension point="kodi.context.item">
|
||||
<menu id="kodi.core.main">
|
||||
<item library="updatetvshow.py">
|
||||
<label>70269</label>
|
||||
<visible>String.IsEqual(ListItem.dbtype,tvshow)</visible>
|
||||
</item>
|
||||
<item library="contextmenu.py">
|
||||
<label>90001</label>
|
||||
<visible>!String.StartsWith(ListItem.FileNameAndPath, plugin://plugin.video.kod/) + [ String.IsEqual(ListItem.dbtype, tvshow) | String.IsEqual(ListItem.dbtype, movie) | String.IsEqual(ListItem.dbtype, season) | String.IsEqual(ListItem.dbtype, episode) ]</visible>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import os
|
||||
from platformcode import config, logger
|
||||
import xbmc, sys, xbmcgui, os
|
||||
|
||||
@@ -11,17 +10,11 @@ addon_id = config.get_addon_core().getAddonInfo('id')
|
||||
|
||||
LOCAL_FILE = os.path.join(config.get_runtime_path(), "platformcode/contextmenu/contextmenu.json")
|
||||
f = open(LOCAL_FILE)
|
||||
try:
|
||||
contextmenu_settings = jsontools.load( f.read() )
|
||||
except:
|
||||
contextmenu_settings = []
|
||||
contextmenu_settings = jsontools.load(open(LOCAL_FILE).read())
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
|
||||
def build_menu():
|
||||
|
||||
tmdbid = xbmc.getInfoLabel('ListItem.Property(tmdb_id)')
|
||||
mediatype = xbmc.getInfoLabel('ListItem.DBTYPE')
|
||||
title = xbmc.getInfoLabel('ListItem.Title')
|
||||
@@ -35,41 +28,28 @@ def build_menu():
|
||||
logger.info(filePath)
|
||||
logger.info(containerPath)
|
||||
|
||||
contextmenumodules = []
|
||||
contextmenu = []
|
||||
contextmenuitems = []
|
||||
contextmenuactions = []
|
||||
|
||||
for itemmodule in contextmenu_settings:
|
||||
logger.debug('check contextmenu', itemmodule)
|
||||
module = __import__(itemmodule, None, None, [itemmodule])
|
||||
|
||||
# if module.check_condition():
|
||||
logger.info('Add contextmenu item ->', itemmodule)
|
||||
contextmenumodules.append( module )
|
||||
module_item_actions = module.get_menu_items()
|
||||
contextmenuitems.extend([item for item, fn in module_item_actions])
|
||||
contextmenuactions.extend([fn for item, fn in module_item_actions])
|
||||
|
||||
|
||||
contextmenuitems = []
|
||||
contextmenuactions = []
|
||||
empty = False
|
||||
if len(contextmenumodules) == 0:
|
||||
if len(contextmenuitems) == 0:
|
||||
logger.info('No contextmodule found, build an empty one')
|
||||
contextmenucontextmenuitems.append( empty_item() )
|
||||
empty = True
|
||||
else:
|
||||
support.dbg()
|
||||
for itemmodule in contextmenumodules:
|
||||
module_item_actions = itemmodule.get_menu_items()
|
||||
contextmenuitems = contextmenuitems + [item for item, fn in module_item_actions ]
|
||||
contextmenuactions = contextmenuactions + [fn for item, fn in module_item_actions ]
|
||||
contextmenuitems.append(empty_item())
|
||||
contextmenuactions.append(lambda: None)
|
||||
|
||||
ret = xbmcgui.Dialog().contextmenu(contextmenuitems)
|
||||
|
||||
if not empty and ret > -1:
|
||||
module_function = contextmenuactions[ ret ]
|
||||
logger.info( 'Contextmenu module index', ret, 'for -> {}', itemmodule )
|
||||
if module_function:
|
||||
module_function()
|
||||
else:
|
||||
logger.warn('No function for menu item: {}'.format(contextmenuitems[ret]) )
|
||||
if ret > -1:
|
||||
logger.info('Contextmenu module index', ret, ', label=' + contextmenuitems[ret])
|
||||
contextmenuactions[ret]()
|
||||
|
||||
|
||||
def empty_item():
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
import xbmc, sys, xbmcgui, os
|
||||
from platformcode import config, logger
|
||||
|
||||
# incliuding folder libraries
|
||||
librerias = xbmc.translatePath(os.path.join(config.get_runtime_path(), 'lib'))
|
||||
sys.path.insert(0, librerias)
|
||||
|
||||
|
||||
from core import tmdb
|
||||
from core.item import Item
|
||||
|
||||
def execute_search():
|
||||
"""
|
||||
Gather the selected ListItem's attributes in order to compute the `Item` parameters
|
||||
and perform the KOD's globalsearch.
|
||||
Globalsearch will be executed specifing the content-type of the selected ListItem
|
||||
|
||||
NOTE: this method needs the DBTYPE and TMDB_ID specified as ListItem's properties
|
||||
"""
|
||||
|
||||
# These following lines are commented and keep in the code just as reminder.
|
||||
# In future, they could be used to filter the search outcome
|
||||
|
||||
# ADDON: maybe can we know if the current windows is related to a specific addon?
|
||||
# we could skip the ContextMenu if we already are in KOD's window
|
||||
|
||||
tmdbid = xbmc.getInfoLabel('ListItem.Property(tmdb_id)')
|
||||
mediatype = xbmc.getInfoLabel('ListItem.DBTYPE')
|
||||
title = xbmc.getInfoLabel('ListItem.Title')
|
||||
year = xbmc.getInfoLabel('ListItem.Year')
|
||||
imdb = xbmc.getInfoLabel('ListItem.IMDBNumber')
|
||||
# folderPath = xbmc.getInfoLabel('Container.FolderPath')
|
||||
# filePath = xbmc.getInfoLabel('ListItem.FileNameAndPath')
|
||||
# logger.info("****")
|
||||
# logger.info( xbmc.getCondVisibility("String.Contains(Container.FolderPath, 'plugin.video.kod')") )
|
||||
# logger.info( xbmc.getCondVisibility("String.Contains(ListItem.FileNameAndPath, 'plugin.video.kod')") )
|
||||
# logger.info( xbmc.getCondVisibility("String.IsEqual(ListItem.dbtype,tvshow)") )
|
||||
# logger.info( xbmc.getCondVisibility("String.IsEqual(ListItem.dbtype,movie)") )
|
||||
# logger.info("****")
|
||||
|
||||
# visible = xbmc.getCondVisibility("!String.StartsWith(ListItem.FileNameAndPath, 'plugin://plugin.video.kod/') + [String.IsEqual(ListItem.dbtype,tvshow) | String.IsEqual(ListItem.dbtype,movie)]")
|
||||
|
||||
logstr = "Selected ListItem is: 'IMDB: {}' - TMDB: {}' - 'Title: {}' - 'Year: {}'' - 'Type: {}'".format(imdb, tmdbid, title, year, mediatype)
|
||||
logger.info(logstr)
|
||||
|
||||
if not tmdbid and imdb:
|
||||
logger.info('No TMDBid found. Try to get by IMDB')
|
||||
it = Item(contentType= mediatype, infoLabels={'imdb_id' : imdb})
|
||||
tmdb.set_infoLabels(it)
|
||||
tmdbid = it.infoLabels.get('tmdb_id', '')
|
||||
|
||||
if not tmdbid:
|
||||
logger.info('No TMDBid found. Try to get by Title/Year')
|
||||
it = Item(contentTitle= title, contentType= mediatype, infoLabels={'year' : year})
|
||||
tmdb.set_infoLabels(it)
|
||||
tmdbid = it.infoLabels.get('tmdb_id', '')
|
||||
|
||||
|
||||
item = Item(
|
||||
action="Search",
|
||||
channel="globalsearch",
|
||||
contentType= mediatype,
|
||||
mode="search",
|
||||
text= title,
|
||||
type= mediatype,
|
||||
infoLabels= {
|
||||
'tmdb_id': tmdbid,
|
||||
'year': year
|
||||
},
|
||||
folder= False
|
||||
)
|
||||
|
||||
logger.info("Invoking Item: {}".format(item.tostring()))
|
||||
|
||||
itemurl = item.tourl()
|
||||
xbmc.executebuiltin("RunPlugin(plugin://plugin.video.kod/?" + itemurl + ")")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
execute_search()
|
||||
@@ -1,5 +1,4 @@
|
||||
[
|
||||
"platformcode.contextmenu.search_on_kod",
|
||||
"platformcode.contextmenu.search_on_channels",
|
||||
"platformcode.contextmenu.search",
|
||||
"platformcode.contextmenu.update_tv_show"
|
||||
]
|
||||
@@ -10,9 +10,11 @@ from core import tmdb
|
||||
from core.item import Item
|
||||
|
||||
addon_id = config.get_addon_core().getAddonInfo('id')
|
||||
global item_is_coming_from_kod
|
||||
|
||||
|
||||
def check_condition():
|
||||
global item_is_coming_from_kod
|
||||
logger.debug('check item condition')
|
||||
mediatype = xbmc.getInfoLabel('ListItem.DBTYPE')
|
||||
|
||||
@@ -33,17 +35,15 @@ def check_condition():
|
||||
item_is_coming_from_kod = pattern.search(filePath)
|
||||
|
||||
if item_is_coming_from_kod:
|
||||
logger.debug("item IS already managed by KOD", item_is_coming_from_kod)
|
||||
logger.debug("item IS already managed by KOD")
|
||||
|
||||
# logger.info('container is KOD? {}'.format(we_are_in_kod) )
|
||||
|
||||
return mediatype and item_is_coming_from_kod # and not we_are_in_kod
|
||||
return mediatype
|
||||
|
||||
|
||||
def get_menu_items():
|
||||
logger.debug('get menu item')
|
||||
if check_condition():
|
||||
return config.get_localized_string(90003) , execute
|
||||
return [(config.get_localized_string(90003 if item_is_coming_from_kod else 90005), execute)]
|
||||
else:
|
||||
return []
|
||||
|
||||
@@ -69,6 +69,10 @@ def execute():
|
||||
year = xbmc.getInfoLabel('ListItem.Year')
|
||||
imdb = xbmc.getInfoLabel('ListItem.IMDBNumber')
|
||||
|
||||
if mediatype in ('episode', 'season'):
|
||||
mediatype = 'tvshow'
|
||||
title = xbmc.getInfoLabel('ListItem.TVShowTitle')
|
||||
|
||||
logstr = "Selected ListItem is: 'IMDB: {}' - TMDB: {}' - 'Title: {}' - 'Year: {}'' - 'Type: {}'".format(imdb, tmdbid, title, year, mediatype)
|
||||
logger.info(logstr)
|
||||
|
||||
@@ -90,13 +94,10 @@ def execute():
|
||||
except:
|
||||
logger.info("Cannot find TMDB via title/year")
|
||||
|
||||
|
||||
if not tmdbid:
|
||||
# We can continue searching by 'title (year)'
|
||||
logger.info( "No TMDB found, proceed with title/year:", title , "(" , year, ")" )
|
||||
|
||||
|
||||
|
||||
# User wants to search on other channels
|
||||
logger.info("Search on other channels")
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
import xbmc, sys, xbmcgui, os
|
||||
from platformcode import config, logger
|
||||
|
||||
# incliuding folder libraries
|
||||
librerias = xbmc.translatePath(os.path.join(config.get_runtime_path(), 'lib'))
|
||||
sys.path.insert(0, librerias)
|
||||
import re
|
||||
|
||||
from core import tmdb
|
||||
from core.item import Item
|
||||
|
||||
addon_id = config.get_addon_core().getAddonInfo('id')
|
||||
|
||||
|
||||
def check_condition():
|
||||
logger.debug('[SOK] check item condition')
|
||||
mediatype = xbmc.getInfoLabel('ListItem.DBTYPE')
|
||||
|
||||
folderPath = xbmc.getInfoLabel('Container.FolderPath')
|
||||
filePath = xbmc.getInfoLabel('ListItem.Path')
|
||||
fileNameAndPath = xbmc.getInfoLabel('ListItem.FileNameAndPath')
|
||||
|
||||
logger.debug('Container:',folderPath )
|
||||
logger.debug('listitem mediatype:',mediatype )
|
||||
logger.debug('filenamepath:', fileNameAndPath )
|
||||
logger.info('filepath:', filePath )
|
||||
|
||||
item_is_coming_from_kod = addon_id in filePath
|
||||
if not item_is_coming_from_kod:
|
||||
videolibpath = config.get_setting("videolibrarypath")
|
||||
if filePath.startswith(videolibpath):
|
||||
pattern = re.compile("\[.*\][\\\/]?$")
|
||||
item_is_coming_from_kod = pattern.search(filePath)
|
||||
|
||||
if item_is_coming_from_kod:
|
||||
logger.debug("item IS already managed by KOD", item_is_coming_from_kod)
|
||||
|
||||
# logger.info('[SOK] container is KOD? {}'.format(we_are_in_kod) )
|
||||
|
||||
return mediatype and not item_is_coming_from_kod # and not we_are_in_kod
|
||||
|
||||
def get_menu_items():
|
||||
logger.debug('get menu item')
|
||||
if check_condition():
|
||||
return config.get_localized_string(90005) , execute
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
def execute():
|
||||
"""
|
||||
Gather the selected ListItem's attributes in order to compute the `Item` parameters
|
||||
and perform the KOD's globalsearch.
|
||||
Globalsearch will be executed specifing the content-type of the selected ListItem
|
||||
|
||||
NOTE: this method needs the DBTYPE and TMDB_ID specified as ListItem's properties
|
||||
"""
|
||||
|
||||
# These following lines are commented and keep in the code just as reminder.
|
||||
# In future, they could be used to filter the search outcome
|
||||
|
||||
# ADDON: maybe can we know if the current windows is related to a specific addon?
|
||||
# we could skip the ContextMenu if we already are in KOD's window
|
||||
|
||||
tmdbid = xbmc.getInfoLabel('ListItem.Property(tmdb_id)')
|
||||
mediatype = xbmc.getInfoLabel('ListItem.DBTYPE')
|
||||
title = xbmc.getInfoLabel('ListItem.Title')
|
||||
year = xbmc.getInfoLabel('ListItem.Year')
|
||||
imdb = xbmc.getInfoLabel('ListItem.IMDBNumber')
|
||||
|
||||
logstr = "Selected ListItem is: 'IMDB: {}' - TMDB: {}' - 'Title: {}' - 'Year: {}'' - 'Type: {}'".format(imdb, tmdbid, title, year, mediatype)
|
||||
logger.info(logstr)
|
||||
|
||||
if not tmdbid and imdb:
|
||||
logger.info('No TMDBid found. Try to get by IMDB')
|
||||
it = Item(contentType= mediatype, infoLabels={'imdb_id' : imdb})
|
||||
try:
|
||||
tmdb.set_infoLabels(it)
|
||||
tmdbid = it.infoLabels.get('tmdb_id', '')
|
||||
except:
|
||||
logger.info("Cannot find TMDB via imdb")
|
||||
|
||||
if not tmdbid:
|
||||
logger.info('No TMDBid found. Try to get by Title/Year')
|
||||
it = Item(contentTitle= title, contentType= mediatype, infoLabels={'year' : year})
|
||||
try:
|
||||
tmdb.set_infoLabels(it)
|
||||
tmdbid = it.infoLabels.get('tmdb_id', '')
|
||||
except:
|
||||
logger.info("Cannot find TMDB via title/year")
|
||||
|
||||
|
||||
if not tmdbid:
|
||||
# We can continue searching by 'title (year)'
|
||||
logger.info( "No TMDB found, proceed with title/year:", title , "(" , year, ")" )
|
||||
|
||||
|
||||
logger.info("Search on KOD (gobalsearch)")
|
||||
|
||||
item = Item(
|
||||
action="Search",
|
||||
channel="globalsearch",
|
||||
contentType= mediatype,
|
||||
mode="search",
|
||||
text= title,
|
||||
type= mediatype,
|
||||
infoLabels= {
|
||||
'tmdb_id': tmdbid,
|
||||
'year': year
|
||||
},
|
||||
folder= False
|
||||
)
|
||||
|
||||
logger.info("Invoking Item:", item.tostring() )
|
||||
|
||||
itemurl = item.tourl()
|
||||
xbmc.executebuiltin("RunPlugin(plugin://plugin.video.kod/?" + itemurl + ")")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ def execute_sql(sql):
|
||||
|
||||
def check_condition():
|
||||
# support.dbg()
|
||||
dbid = xbmc.getInfoLabel('ListItem.DBID')
|
||||
dbid = xbmc.getInfoLabel('ListItem.TvShowDBID')
|
||||
path = search_paths(dbid)
|
||||
if path:
|
||||
return True
|
||||
@@ -117,14 +117,14 @@ def check_condition():
|
||||
def get_menu_items():
|
||||
logger.debug('get menu item')
|
||||
if check_condition():
|
||||
return config.get_localized_string(70269) , execute
|
||||
return [(config.get_localized_string(70269), execute)]
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
|
||||
def execute():
|
||||
dbid = xbmc.getInfoLabel('ListItem.DBID')
|
||||
dbid = xbmc.getInfoLabel('ListItem.TvShowDBID')
|
||||
path = search_paths(dbid)
|
||||
if path:
|
||||
item = Item(action="update_tvshow", channel="videolibrary", path=path)
|
||||
|
||||
118
updatetvshow.py
118
updatetvshow.py
@@ -1,118 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import xbmc, sys, xbmcgui, os, xbmcvfs, traceback
|
||||
from platformcode import config, logger
|
||||
|
||||
librerias = xbmc.translatePath(os.path.join(config.get_runtime_path(), 'lib'))
|
||||
sys.path.insert(0, librerias)
|
||||
|
||||
from core.item import Item
|
||||
from lib.sambatools import libsmb as samba
|
||||
from core import scrapertools
|
||||
|
||||
|
||||
def exists(path, silent=False, vfs=True):
|
||||
path = xbmc.translatePath(path)
|
||||
try:
|
||||
if vfs:
|
||||
result = bool(xbmcvfs.exists(path))
|
||||
if not result and not path.endswith('/') and not path.endswith('\\'):
|
||||
result = bool(xbmcvfs.exists(join(path, ' ').rstrip()))
|
||||
return result
|
||||
elif path.lower().startswith("smb://"):
|
||||
return samba.exists(path)
|
||||
else:
|
||||
return os.path.exists(path)
|
||||
except:
|
||||
logger.error("ERROR when checking the path: %s" % path)
|
||||
if not silent:
|
||||
logger.error(traceback.format_exc())
|
||||
return False
|
||||
|
||||
def join(*paths):
|
||||
list_path = []
|
||||
if paths[0].startswith("/"):
|
||||
list_path.append("")
|
||||
for path in paths:
|
||||
if path:
|
||||
list_path += path.replace("\\", "/").strip("/").split("/")
|
||||
|
||||
if scrapertools.find_single_match(paths[0], r'(^\w+:\/\/)'):
|
||||
return str("/".join(list_path))
|
||||
else:
|
||||
return str(os.sep.join(list_path))
|
||||
|
||||
|
||||
def search_paths(Id):
|
||||
records = execute_sql('SELECT idPath FROM tvshowlinkpath WHERE idShow LIKE "%s"' % Id)
|
||||
if len(records) >= 1:
|
||||
for record in records:
|
||||
path_records = execute_sql('SELECT strPath FROM path WHERE idPath LIKE "%s"' % record[0])
|
||||
for path in path_records:
|
||||
if config.get_setting('videolibrarypath') in path[0] and exists(join(path[0], 'tvshow.nfo')):
|
||||
return path[0]
|
||||
return ''
|
||||
|
||||
|
||||
def execute_sql(sql):
|
||||
logger.debug()
|
||||
file_db = ""
|
||||
records = None
|
||||
|
||||
# We look for the archive of the video database according to the version of kodi
|
||||
video_db = config.get_platform(True)['video_db']
|
||||
if video_db:
|
||||
file_db = os.path.join(xbmc.translatePath("special://userdata/Database"), video_db)
|
||||
|
||||
# alternative method to locate the database
|
||||
if not file_db or not os.path.exists(file_db):
|
||||
file_db = ""
|
||||
for f in os.path.listdir(xbmc.translatePath("special://userdata/Database")):
|
||||
path_f = os.path.join(xbmc.translatePath("special://userdata/Database"), f)
|
||||
|
||||
if os.path.pathoos.pathols.isfile(path_f) and f.lower().startswith('myvideos') and f.lower().endswith('.db'):
|
||||
file_db = path_f
|
||||
break
|
||||
|
||||
if file_db:
|
||||
logger.debug("DB file: %s" % file_db)
|
||||
conn = None
|
||||
try:
|
||||
import sqlite3
|
||||
conn = sqlite3.connect(file_db)
|
||||
cursor = conn.cursor()
|
||||
|
||||
logger.debug("Running sql: %s" % sql)
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
|
||||
records = cursor.fetchall()
|
||||
if sql.lower().startswith("select"):
|
||||
if len(records) == 1 and records[0][0] is None:
|
||||
records = []
|
||||
|
||||
conn.close()
|
||||
logger.debug("Query executed. Records: %s" % len(records))
|
||||
|
||||
except:
|
||||
logger.error("Error executing sql query")
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
else:
|
||||
logger.debug("Database not found")
|
||||
|
||||
return records
|
||||
|
||||
if __name__ == '__main__':
|
||||
path = search_paths(sys.listitem.getVideoInfoTag().getDbId())
|
||||
if path:
|
||||
item = Item(action="update_tvshow", channel="videolibrary", path=path)
|
||||
# Why? I think it is not necessary, just commented
|
||||
# item.tourl()
|
||||
xbmc.executebuiltin("RunPlugin(plugin://plugin.video.kod/?" + item.tourl() + ")")
|
||||
else:
|
||||
dialog = xbmcgui.Dialog()
|
||||
title = sys.listitem.getVideoInfoTag().getTitle()
|
||||
if dialog.yesno(title, config.get_localized_string(70817) % title, nolabel=config.get_localized_string(70170), yeslabel=config.get_localized_string(30022)):
|
||||
item = Item(action="new_search", channel="search", mode="tvshow", search_text=sys.listitem.getVideoInfoTag().getTitle())
|
||||
xbmc.executebuiltin("ActivateWindow(10025,plugin://plugin.video.kod/?" + item.tourl() + ")")
|
||||
Reference in New Issue
Block a user