Skip to content

Commit f924c20

Browse files
CroneterCroneter
Croneter
authored and
Croneter
committed
Add PKC setting in "Appearance Tweaks" for dedicated context menu entry "Extras" for movies and TV shows
1 parent 77ade67 commit f924c20

File tree

12 files changed

+124
-89
lines changed

12 files changed

+124
-89
lines changed

addon.xml

+14-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@
1212
</extension>
1313
<extension point="xbmc.service" library="service.py" start="login">
1414
</extension>
15-
<extension point="kodi.context.item" library="contextmenu.py">
16-
<item>
15+
<extension point="kodi.context.item">
16+
<menu id="kodi.core.main">
17+
<item library="context_extras.py">
18+
<!-- Extras -->
19+
<label>30235</label>
20+
<visible>[String.IsEqual(Window(10000).Property(plex_context_show_extras),true) + [[[String.IsEqual(ListItem.DBTYPE,movie) | String.IsEqual(ListItem.DBTYPE,tvshow)] + !String.IsEmpty(ListItem.DBID)] | !String.IsEmpty(ListItem.Property(plexid))]]</visible>
21+
<!-- [String.IsEqual(Window(10000).Property(plex_context_show_extras)) -->
22+
</item>
23+
<item library="context_menu.py">
24+
<!-- Plex options -->
1725
<label>30401</label>
18-
<description>30416</description>
19-
<visible>[!IsEmpty(ListItem.DBID) + !StringCompare(ListItem.DBID,-1) | !IsEmpty(ListItem.Property(plexid))]</visible>
26+
<!-- Settings for the Plex Server -->
27+
<description>30416</description>
28+
<visible>[[!String.IsEmpty(ListItem.DBID) + !String.IsEqual(ListItem.DBID,-1)] | !String.IsEmpty(ListItem.Property(plexid))]</visible>
2029
</item>
30+
</menu>
2131
</extension>
2232
<extension point="xbmc.addon.metadata">
2333
<!-- see e.g. https://github.com/xbmc/xbmc/pull/14136 -->

context_extras.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Grabs the Plex id for the Kodi item the context menu was called for
4+
and displays a menu displaying extras like trailers.
5+
"""
6+
from xbmc import executebuiltin
7+
8+
from resources.lib.contextmenu.common import plex_id_from_listitem
9+
10+
11+
def main():
12+
plex_id = plex_id_from_listitem()
13+
if plex_id is None:
14+
return
15+
handle = ('plugin://plugin.video.plexkodiconnect?mode=extras&plex_id=%s'
16+
% plex_id)
17+
executebuiltin('ActivateWindow(videos,\"%s\",return)' % handle)
18+
19+
20+
if __name__ == "__main__":
21+
main()

context_menu.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Grabs kodi_id and kodi_type for the Kodi item the context menu was called for
4+
and sends a request to our main Python instance that the PKC context menu needs
5+
to be displayed
6+
"""
7+
from urllib.parse import urlencode
8+
9+
from xbmc import sleep
10+
from xbmcgui import Window
11+
12+
from resources.lib.contextmenu.common import kodi_item_from_listitem
13+
14+
15+
def main():
16+
kodi_id, kodi_type = kodi_item_from_listitem()
17+
args = {
18+
'kodi_id': kodi_id,
19+
'kodi_type': kodi_type
20+
}
21+
window = Window(10000)
22+
while window.getProperty('plexkodiconnect.command'):
23+
sleep(20)
24+
window.setProperty('plexkodiconnect.command',
25+
'CONTEXT_menu?%s' % urlencode(args))
26+
27+
28+
if __name__ == "__main__":
29+
main()

contextmenu.py

-49
This file was deleted.

resources/language/resource.language.en_gb/strings.po

+5
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,11 @@ msgctxt "#39057"
10181018
msgid "Customize Paths"
10191019
msgstr ""
10201020

1021+
# PKC Settings - Appearance Tweaks
1022+
msgctxt "#39058"
1023+
msgid "Show 'Extras' in Kodi context menu (reboot Kodi)"
1024+
msgstr ""
1025+
10211026
# PKC Settings - Appearance Tweaks
10221027
msgctxt "#39059"
10231028
msgid "Recently Added: Append show title to episode"

resources/lib/contextmenu/__init__.py

Whitespace-only changes.

resources/lib/contextmenu/common.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
from xbmc import getInfoLabel
3+
4+
from ..plex_db import PlexDB
5+
6+
7+
def kodi_item_from_listitem():
8+
kodi_id = getInfoLabel('ListItem.DBID') or None
9+
kodi_type = getInfoLabel('ListItem.DBTYPE') or None
10+
return int(kodi_id) if kodi_id else None, kodi_type
11+
12+
13+
def plex_id_from_listitem():
14+
plex_id = getInfoLabel('ListItem.Property(plexid)')
15+
plex_id = int(plex_id) if plex_id else None
16+
if plex_id is None:
17+
kodi_id, kodi_type = kodi_item_from_listitem()
18+
if kodi_id is None or kodi_type is None:
19+
return
20+
with PlexDB(lock=False) as plexdb:
21+
item = plexdb.item_by_kodi_id(kodi_id, kodi_type)
22+
if item:
23+
plex_id = item['plex_id']
24+
return plex_id

resources/lib/context_entry.py resources/lib/contextmenu/menu.py

+15-21
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
from logging import getLogger
44
import xbmc
55

6-
from .plex_api import API
7-
from .plex_db import PlexDB
8-
from . import context
9-
from . import plex_functions as PF
10-
from . import utils
11-
from . import variables as v
12-
from . import app
6+
from .common import plex_id_from_listitem
7+
8+
from ..windows import contextmenu as dialog
9+
10+
from ..plex_api import API
11+
from .. import plex_functions as PF
12+
from .. import utils
13+
from .. import variables as v
14+
from .. import app
1315

1416
###############################################################################
1517

16-
LOG = getLogger('PLEX.context_entry')
18+
LOG = getLogger('PLEX.context.menu')
1719

1820
OPTIONS = {
1921
'Refresh': utils.lang(30410),
@@ -43,7 +45,7 @@ def __init__(self, kodi_id=None, kodi_type=None):
4345
"""
4446
self.kodi_id = kodi_id
4547
self.kodi_type = kodi_type
46-
self.plex_id = self._get_plex_id(self.kodi_id, self.kodi_type)
48+
self.plex_id = plex_id_from_listitem()
4749
if self.kodi_type:
4850
self.plex_type = v.PLEX_TYPE_FROM_KODI_TYPE[self.kodi_type]
4951
else:
@@ -62,23 +64,15 @@ def __init__(self, kodi_id=None, kodi_type=None):
6264
if self._select_menu():
6365
self._action_menu()
6466

65-
@staticmethod
66-
def _get_plex_id(kodi_id, kodi_type):
67-
plex_id = xbmc.getInfoLabel('ListItem.Property(plexid)') or None
68-
if not plex_id and kodi_id and kodi_type:
69-
with PlexDB() as plexdb:
70-
item = plexdb.item_by_kodi_id(kodi_id, kodi_type)
71-
if item:
72-
plex_id = item['plex_id']
73-
return plex_id
74-
7567
def _select_menu(self):
7668
"""
7769
Display select dialog
7870
"""
7971
options = []
8072
# if user uses direct paths, give option to initiate playback via PMS
81-
if self.api and self.api.extras():
73+
if (utils.window('plex_context_show_extras') != 'true'
74+
and self.api
75+
and self.api.extras()):
8276
options.append(OPTIONS['Extras'])
8377
if app.SYNC.direct_paths and self.kodi_type in v.KODI_VIDEOTYPES:
8478
options.append(OPTIONS['PMS_Play'])
@@ -91,7 +85,7 @@ def _select_menu(self):
9185
options.append(OPTIONS['Delete'])
9286
# Addon settings
9387
options.append(OPTIONS['Addon'])
94-
context_menu = context.ContextMenu(
88+
context_menu = dialog.ContextMenuDialog(
9589
"script-plex-context.xml",
9690
v.ADDON_PATH,
9791
"default",

resources/lib/playback_starter.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# -*- coding: utf-8 -*-
33
from logging import getLogger
44

5-
from . import utils, playback, context_entry, transfer, backgroundthread
5+
from . import utils, playback, transfer, backgroundthread
6+
from .contextmenu import menu
67

78
###############################################################################
89

@@ -50,6 +51,6 @@ def run(self):
5051
params['offset'],
5152
resolve=resolve)
5253
elif mode == 'context_menu':
53-
context_entry.ContextMenu(kodi_id=params.get('kodi_id'),
54-
kodi_type=params.get('kodi_type'))
54+
menu.ContextMenu(kodi_id=params.get('kodi_id'),
55+
kodi_type=params.get('kodi_type'))
5556
LOG.debug('Finished PlaybackTask')

resources/lib/service_entry.py

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def __init__(self):
9090
for prop in WINDOW_PROPERTIES:
9191
utils.window(prop, clear=True)
9292

93+
# Show a dedicated context menu entry for "Extras"?
94+
utils.window('plex_context_show_extras',
95+
value=utils.settings('plex_context_show_extras'))
96+
9397
clientinfo.getDeviceId()
9498

9599
self.startup_completed = False

resources/lib/context.py resources/lib/windows/contextmenu.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
#!/usr/bin/env python
21
# -*- coding: utf-8 -*-
32
from logging import getLogger
43
import xbmcgui
54

6-
from . import utils
7-
from . import path_ops
8-
from . import variables as v
5+
from .. import utils
6+
from .. import path_ops
7+
from .. import variables as v
98

10-
###############################################################################
11-
12-
LOG = getLogger('PLEX.context')
9+
log = getLogger('PLEX.context.dialog')
1310

1411
ACTION_PARENT_DIR = 9
1512
ACTION_PREVIOUS_MENU = 10
@@ -19,10 +16,8 @@
1916
LIST = 155
2017
USER_IMAGE = 150
2118

22-
###############################################################################
23-
2419

25-
class ContextMenu(xbmcgui.WindowXMLDialog):
20+
class ContextMenuDialog(xbmcgui.WindowXMLDialog):
2621
def __init__(self, *args, **kwargs):
2722
self._options = []
2823
self.selected_option = None
@@ -45,7 +40,7 @@ def onInit(self):
4540
if utils.window('plexAvatar'):
4641
self.getControl(USER_IMAGE).setImage(utils.window('plexAvatar'))
4742
height = 479 + (len(self._options) * 55)
48-
LOG.debug("options: %s", self._options)
43+
log.debug("options: %s", self._options)
4944
self.list_ = self.getControl(LIST)
5045
for option in self._options:
5146
self.list_.addItem(self._add_listitem(option))
@@ -60,7 +55,7 @@ def onAction(self, action):
6055
if self.getFocusId() == LIST:
6156
option = self.list_.getSelectedItem()
6257
self.selected_option = option.getLabel()
63-
LOG.info('option selected: %s', self.selected_option)
58+
log.info('option selected: %s', self.selected_option)
6459
self.close()
6560

6661
def _add_editcontrol(self, x, y, height, width, password=None):

resources/settings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
-->
168168

169169
<category label="39073"><!-- Appearance Tweaks -->
170+
<setting id="plex_context_show_extras" type="bool" label="39058" default="true" /><!-- Show 'Extras' in Kodi context menu (reboot Kodi) -->
170171
<setting label="[COLOR yellow]$ADDON[plugin.video.plexkodiconnect 39085][/COLOR]" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=refreshplaylist)" option="close" /><!-- Reload Kodi node files to apply all the settings below -->
171172
<setting id="widgetLimit" type="slider" label="39077" default="30" range="10,10,100" option="int" /><!-- Maximum number of videos to show in widgets -->
172173
<setting type="lsep" />

0 commit comments

Comments
 (0)