-
Notifications
You must be signed in to change notification settings - Fork 16
/
plugin.py
86 lines (62 loc) · 2.56 KB
/
plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# pylint: disable=wrong-import-position
import os
import sys
try:
from urllib.parse import parse_qs
except ImportError:
from urlparse import parse_qs
import xbmcvfs
import xbmcgui
import xbmcplugin
import xbmcaddon
__addon__ = xbmcaddon.Addon()
__handle__ = int(sys.argv[1])
__args__ = parse_qs(sys.argv[2][1:])
xbmcplugin.setContent(__handle__, 'movies')
RESOURCES_PATH = xbmcvfs.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources'))
LIB_RESOURCES_PATH = xbmcvfs.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib'))
sys.path.append(RESOURCES_PATH)
sys.path.append(LIB_RESOURCES_PATH)
from connect import logger, strings, kodi_rpc
logger.debug(u'RESOURCES_PATHs: {}, {}'.format(RESOURCES_PATH, LIB_RESOURCES_PATH))
logger.debug(u'__file__: {}'.format(__file__))
def main():
logger.debug(u'argv: {}'.format(sys.argv[2][1:]))
logger.debug(u'args: {}'.format(str(__args__)))
entities = __args__.get('entities', [''])[0].split('x')
total_items = len(entities)
logger.debug(u'entities: {}'.format(str(entities)))
if not entities:
xbmcplugin.addDirectoryItem(__handle__, '', xbmcgui.ListItem(strings.NO_ITEMS_FOUND), isFolder=False)
for entity in entities:
entity_type = entity[:1]
entity_id = entity[1:]
if not entity_id:
continue
entity_id = int(entity_id)
if entity_type == 'm':
details = kodi_rpc.get_movie_details(entity_id)
logger.debug(details)
label = details.get('label', 'N/A')
plot = details.get('plot', 'N/A')
url = details.get('file', '')
fanart = details.get('fanart')
thumbnail = details.get('thumbnail')
item = xbmcgui.ListItem(label)
item.setProperty('IsPlayable', 'true')
item.setInfo('video', {"plot": plot})
if fanart:
item.setArt({"fanart": fanart})
if thumbnail:
item.setArt({"thumbnail": thumbnail, "poster": thumbnail})
xbmcplugin.addDirectoryItem(__handle__, url, item, totalItems=total_items)
elif entity_type == 't':
details = kodi_rpc.get_tvshow_details(entity_id)
logger.debug(details)
label = details.get('label', 'N/A')
plot = details.get('plot', 'N/A')
item = xbmcgui.ListItem(label)
item.setInfo('video', {"plot": plot})
xbmcplugin.addDirectoryItem(__handle__, '', item, totalItems=total_items)
xbmcplugin.endOfDirectory(__handle__)
main()