From 722c7b63a9fff9bfdcfbba014f2e09a93f93e983 Mon Sep 17 00:00:00 2001 From: fatshotty Date: Mon, 19 Apr 2021 10:32:18 +0200 Subject: [PATCH 1/5] add contextual menu for search item on KOD via tmdb_id --- addon.xml | 4 ++ externalsearch.py | 68 +++++++++++++++++++ .../resource.language.en_gb/strings.po | 8 ++- .../resource.language.it_it/strings.po | 7 +- updatetvshow.py | 3 +- 5 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 externalsearch.py diff --git a/addon.xml b/addon.xml index 68d0cd20..ea492595 100644 --- a/addon.xml +++ b/addon.xml @@ -16,6 +16,10 @@ String.IsEqual(ListItem.dbtype,tvshow) + + + !String.IsEmpty(ListItem.Property(tmdb_id)) + diff --git a/externalsearch.py b/externalsearch.py new file mode 100644 index 00000000..d6312ca8 --- /dev/null +++ b/externalsearch.py @@ -0,0 +1,68 @@ +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.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 + + # IMDB: the imdb of the selected ListItem + # this field is the Kodi's core field (not TMDB) + # + # imdb = xbmc.getInfoLabel('ListItem.IMDBNumber') + + # 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 + # + # addon = xbmc.getInfoLabel('ListItem.Property(Addon.ID)') + + # YEAR: the year of the selected ListItem + # this field is the Kodi's core field + # + # year = xbmc.getInfoLabel('ListItem.Year') + + + tmdb = xbmc.getInfoLabel('ListItem.Property(tmdb_id)') + mediatype = xbmc.getInfoLabel('ListItem.DBTYPE') + title = xbmc.getInfoLabel('ListItem.Title') + + + logstr = "Selected ListItem is: 'TMDB: {}' - 'Title: {}' - 'Type: {}'".format(tmdb, title, mediatype) + logger.info(logstr) + + item = Item( + action="Search", + channel="globalsearch", + contentType= mediatype, + mode="search", + text= title, + type= mediatype, + infoLabels= { + 'tmdb_id': tmdb + }, + 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() diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 08bf7ce2..fb0adeb1 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -3975,7 +3975,7 @@ msgstr "" msgctxt "#70292" msgid "[%s] File no longer exist on this server." msgstr "" - + msgctxt "#70293" msgid "[%s] The file is processing or has been deleted." msgstr "" @@ -6478,4 +6478,8 @@ msgstr "" msgctxt "#80050" msgid "Downloading..." -msgstr "" \ No newline at end of file +msgstr "" + +msgctxt "#90001" +msgid "Search on KOD" +msgstr "Search on KOD..." diff --git a/resources/language/resource.language.it_it/strings.po b/resources/language/resource.language.it_it/strings.po index a1e89d49..307be3f8 100644 --- a/resources/language/resource.language.it_it/strings.po +++ b/resources/language/resource.language.it_it/strings.po @@ -3974,7 +3974,7 @@ msgstr "Errore, in conversione" msgctxt "#70292" msgid "[%s] File no longer exist on this server." msgstr "[%s] Il file non è più presente nel server." - + msgctxt "#70293" msgid "[%s] The file is processing or has been deleted." msgstr "[%s] Il file video è ancora in elaborazione o è stato rimosso." @@ -6480,3 +6480,8 @@ msgstr "Rimuovi episodi in locale" msgctxt "#80050" msgid "Downloading..." msgstr "Download in corso..." + + +msgctxt "#90001" +msgid "Search on KOD" +msgstr "Cerca con KOD..." diff --git a/updatetvshow.py b/updatetvshow.py index f0b9287f..159009a3 100644 --- a/updatetvshow.py +++ b/updatetvshow.py @@ -107,7 +107,8 @@ if __name__ == '__main__': path = search_paths(sys.listitem.getVideoInfoTag().getDbId()) if path: item = Item(action="update_tvshow", channel="videolibrary", path=path) - item.tourl() + # Why? I think it is not necessary, just commented + # item.tourl() xbmc.executebuiltin("RunPlugin(plugin://plugin.video.kod/?" + item.tourl() + ")") else: dialog = xbmcgui.Dialog() From 67a33353460bcd9f5e0850e20d2c255b9f600cda Mon Sep 17 00:00:00 2001 From: fatshotty Date: Mon, 19 Apr 2021 16:20:55 +0200 Subject: [PATCH 2/5] get tmdb from imdb or title/year --- addon.xml | 2 +- externalsearch.py | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/addon.xml b/addon.xml index ea492595..8262d7a5 100644 --- a/addon.xml +++ b/addon.xml @@ -18,7 +18,7 @@ - !String.IsEmpty(ListItem.Property(tmdb_id)) + String.IsEqual(ListItem.dbtype,tvshow) | String.IsEqual(ListItem.dbtype,movie) diff --git a/externalsearch.py b/externalsearch.py index d6312ca8..154102ff 100644 --- a/externalsearch.py +++ b/externalsearch.py @@ -6,6 +6,7 @@ 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 @@ -21,30 +22,34 @@ def execute_search(): # These following lines are commented and keep in the code just as reminder. # In future, they could be used to filter the search outcome - # IMDB: the imdb of the selected ListItem - # this field is the Kodi's core field (not TMDB) - # - # imdb = xbmc.getInfoLabel('ListItem.IMDBNumber') - # 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 # # addon = xbmc.getInfoLabel('ListItem.Property(Addon.ID)') - # YEAR: the year of the selected ListItem - # this field is the Kodi's core field - # - # year = xbmc.getInfoLabel('ListItem.Year') - - tmdb = xbmc.getInfoLabel('ListItem.Property(tmdb_id)') + 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: 'TMDB: {}' - 'Title: {}' - 'Type: {}'".format(tmdb, title, mediatype) + 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", @@ -53,7 +58,8 @@ def execute_search(): text= title, type= mediatype, infoLabels= { - 'tmdb_id': tmdb + 'tmdb_id': tmdbid, + 'year': year }, folder= False ) From 8ce63d4e4600e593cbda63e3eeb833e74feebcc3 Mon Sep 17 00:00:00 2001 From: fatshotty Date: Mon, 19 Apr 2021 21:12:41 +0200 Subject: [PATCH 3/5] fix menu visibility --- addon.xml | 4 ++-- externalsearch.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addon.xml b/addon.xml index 8262d7a5..445be873 100644 --- a/addon.xml +++ b/addon.xml @@ -14,11 +14,11 @@ - String.IsEqual(ListItem.dbtype,tvshow) + String.StartsWith(Container.FolderPath, 'plugin://plugin.video.kod/') + String.IsEqual(ListItem.dbtype,tvshow) - String.IsEqual(ListItem.dbtype,tvshow) | String.IsEqual(ListItem.dbtype,movie) + !String.StartsWith(Container.FolderPath, 'plugin://plugin.video.kod/') + String.IsEqual(ListItem.dbtype,tvshow) | String.IsEqual(ListItem.dbtype,movie) diff --git a/externalsearch.py b/externalsearch.py index 154102ff..49653837 100644 --- a/externalsearch.py +++ b/externalsearch.py @@ -9,6 +9,8 @@ sys.path.insert(0, librerias) from core import tmdb from core.item import Item +__addon__ = config.get_addon_core() +addon_name = __addon__.getAddonInfo('name') def execute_search(): """ @@ -25,8 +27,6 @@ def execute_search(): # 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 # - # addon = xbmc.getInfoLabel('ListItem.Property(Addon.ID)') - tmdbid = xbmc.getInfoLabel('ListItem.Property(tmdb_id)') mediatype = xbmc.getInfoLabel('ListItem.DBTYPE') @@ -34,6 +34,7 @@ def execute_search(): 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) From bfb9e7ecd385b39754674690b71e7f4a2a31767e Mon Sep 17 00:00:00 2001 From: fatshotty Date: Mon, 19 Apr 2021 21:16:30 +0200 Subject: [PATCH 4/5] remove obsolete code --- externalsearch.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/externalsearch.py b/externalsearch.py index 49653837..be94e640 100644 --- a/externalsearch.py +++ b/externalsearch.py @@ -9,9 +9,6 @@ sys.path.insert(0, librerias) from core import tmdb from core.item import Item -__addon__ = config.get_addon_core() -addon_name = __addon__.getAddonInfo('name') - def execute_search(): """ Gather the selected ListItem's attributes in order to compute the `Item` parameters @@ -26,7 +23,6 @@ def execute_search(): # 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') @@ -34,7 +30,6 @@ def execute_search(): 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) From eafae197a22f1e07206f9581e0daceb25886ee98 Mon Sep 17 00:00:00 2001 From: fatshotty Date: Tue, 20 Apr 2021 10:57:39 +0200 Subject: [PATCH 5/5] fix menu visibility --- addon.xml | 4 ++-- externalsearch.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/addon.xml b/addon.xml index 445be873..94322fde 100644 --- a/addon.xml +++ b/addon.xml @@ -14,11 +14,11 @@ - String.StartsWith(Container.FolderPath, 'plugin://plugin.video.kod/') + String.IsEqual(ListItem.dbtype,tvshow) + String.StartsWith(ListItem.FileNameAndPath, 'plugin://plugin.video.kod/') + String.IsEqual(ListItem.dbtype,tvshow) - !String.StartsWith(Container.FolderPath, 'plugin://plugin.video.kod/') + String.IsEqual(ListItem.dbtype,tvshow) | String.IsEqual(ListItem.dbtype,movie) + !String.StartsWith(ListItem.FileNameAndPath, 'plugin://plugin.video.kod/') + [String.IsEqual(ListItem.dbtype,tvshow) | String.IsEqual(ListItem.dbtype,movie)] diff --git a/externalsearch.py b/externalsearch.py index be94e640..52635f18 100644 --- a/externalsearch.py +++ b/externalsearch.py @@ -29,6 +29,18 @@ def execute_search(): 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)