Skip to content

Instantly share code, notes, and snippets.

@henryjfry
Created January 19, 2020 12:45
Show Gist options
  • Save henryjfry/1016703863b63275d71af7ca4ab04172 to your computer and use it in GitHub Desktop.
Save henryjfry/1016703863b63275d71af7ca4ab04172 to your computer and use it in GitHub Desktop.
Openinfo Context Menu + TMDB Helper ~/.kodi/addons/script.extendedinfo/resources/lib/DialogVideoList.py
@ch.action('contextmenu', 500)
def context_menu(self):
Utils.show_busy()
if self.listitem.getProperty('dbid') and self.listitem.getProperty('dbid') != 0:
dbid = self.listitem.getProperty('dbid')
else:
dbid = 0
item_id = self.listitem.getProperty('id')
if self.type == 'tv':
imdb_id = Utils.fetch(TheMovieDB.get_tvshow_ids(item_id), 'imdb_id')
tvdb_id = Utils.fetch(TheMovieDB.get_tvshow_ids(item_id), 'tvdb_id')
else:
imdb_id = TheMovieDB.get_imdb_id_from_movie_id(item_id)
item_1 = False
if self.listitem.getProperty('TVShowTitle'):
listitems = ['Play first episode']
else:
listitems = ['Play']
listitems += ['Play - TMDB Helper']
item_1 = True
if self.listitem.getProperty('dbid'):
listitems += ['Remove from library']
else:
listitems += ['Add to library']
listitems += ['Trailer']
selection = xbmcgui.Dialog().select(heading='Choose option', list=listitems)
if selection == 0:
if self.listitem.getProperty('TVShowTitle'):
url = 'plugin://plugin.video.openmeta/tv/play/%s/1/1' % tvdb_id
PLAYER.play_from_button(url, listitem=None, window=self, dbid=0)
else:
# window_id = xbmcgui.getCurrentWindowDialogId()
# xbmc.log(str(window_id)+'===>OPENINFO', level=xbmc.LOGNOTICE)
url = 'plugin://plugin.video.openmeta/movies/play/tmdb/%s' % item_id
# xbmc.executebuiltin('Dialog.Close(%s, true)' % window_id)
# xbmc.executebuiltin('RunPlugin(%s)' % url)
if self.listitem.getProperty('dbid'):
dbid = self.listitem.getProperty('dbid')
# url = ''
else:
dbid = 0
# url = 'plugin://plugin.video.openmeta/movies/play/tmdb/%s' % item_id
PLAYER.play_from_button(url, listitem=None, window=self, type='movieid', dbid=dbid)
if selection == 1 and item_1 == True:
if self.type == 'tv':
url = 'plugin://plugin.video.themoviedb.helper?info=play&tvdb_id=%s&type=episode&season=%s&episode=%s' % (item_id, self.listitem.getProperty('season'), self.listitem.getProperty('episode'))
else:
url = 'plugin://plugin.video.themoviedb.helper?info=play&tmdb_id=%s&type=movie' % (item_id)
# xbmc.log(str(self.info)+'===>OPENINFO', level=xbmc.LOGNOTICE)
# xbmc.log(str(self.data)+'===>OPENINFO', level=xbmc.LOGNOTICE)
# xbmc.log(str(self.info['poster_original'])+'===>OPENINFO', level=xbmc.LOGNOTICE)
# self.close()
# Utils.hide_busy()
# xbmc.executebuiltin('RunPlugin(%s)' % url)
xbmc.log(str(url)+'===>OPENINFO', level=xbmc.LOGNOTICE)
PLAYER.play_from_button(url, listitem=None, window=self)
if selection == 1 and item_1 == False:
if self.listitem.getProperty('TVShowTitle'):
TVLibrary = xbmcaddon.Addon('plugin.video.openmeta').getSetting('tv_library_folder')
if self.listitem.getProperty('dbid'):
Utils.get_kodi_json(method='VideoLibrary.RemoveTVShow', params='{"tvshowid": %s}' % dbid)
if os.path.exists(xbmc.translatePath('%s%s/' % (TVLibrary, tvdb_id))):
shutil.rmtree(xbmc.translatePath('%s%s/' % (TVLibrary, tvdb_id)))
Utils.after_add(type='tv')
Utils.notify(header='[B]%s[/B]' % self.listitem.getProperty('TVShowTitle'), message='Removed from library', icon=self.listitem.getProperty('poster'), time=5000, sound=False)
xbmc.sleep(250)
self.update(force_update=True)
self.getControl(500).selectItem(self.position)
else:
if xbmcgui.Dialog().yesno('OpenInfo', 'Add [B]%s[/B] to library?' % self.listitem.getProperty('TVShowTitle')):
xbmc.executebuiltin('RunPlugin(plugin://plugin.video.openmeta/tv/add_to_library/%s)' % tvdb_id)
Utils.after_add(type='tv')
Utils.notify(header='[B]%s[/B] added to library' % self.listitem.getProperty('TVShowTitle'), message='Exit & re-enter to refresh', icon=self.listitem.getProperty('poster'), time=5000, sound=False)
else:
if self.listitem.getProperty('dbid'):
if xbmcgui.Dialog().yesno('OpenInfo', 'Remove [B]%s[/B] from library?' % self.listitem.getProperty('title')):
Utils.get_kodi_json(method='VideoLibrary.RemoveMovie', params='{"movieid": %s}' % dbid)
MovieLibrary = xbmcaddon.Addon('plugin.video.openmeta').getSetting('movies_library_folder')
if os.path.exists(xbmc.translatePath('%s%s/' % (MovieLibrary, imdb_id))):
shutil.rmtree(xbmc.translatePath('%s%s/' % (MovieLibrary, imdb_id)))
Utils.after_add(type='movie')
Utils.notify(header='[B]%s[/B]' % self.listitem.getProperty('title'), message='Removed from library', icon=self.listitem.getProperty('poster'), time=5000, sound=False)
xbmc.sleep(250)
self.update(force_update=True)
self.getControl(500).selectItem(self.position)
else:
if xbmcgui.Dialog().yesno('OpenInfo', 'Add [B]%s[/B] to library?' % self.listitem.getProperty('title')):
xbmc.executebuiltin('RunPlugin(plugin://plugin.video.openmeta/movies/add_to_library/tmdb/%s)' % item_id)
Utils.after_add(type='movie')
Utils.notify(header='[B]%s[/B] added to library' % self.listitem.getProperty('title'), message='Exit & re-enter to refresh', icon=self.listitem.getProperty('poster'), time=5000, sound=False)
if selection == 2:
if self.listitem.getProperty('TVShowTitle'):
url = 'plugin://script.extendedinfo?info=playtvtrailer&&id=' + item_id
else:
url = 'plugin://script.extendedinfo?info=playtrailer&&id=' + item_id
PLAYER.play(url, listitem=None, window=self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment