-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
170 lines (141 loc) · 4.53 KB
/
Copy pathhelpers.py
File metadata and controls
170 lines (141 loc) · 4.53 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/python
import xbmc
import xbmcplugin
import xbmcgui
import json
from datetime import datetime
from infotagger.listitem import ListItemInfoTag
import time
# from random import choice
JSON_MAP = {
'episode_properties': [
'title',
'playcount',
'season',
'episode',
'showtitle',
'originaltitle',
'plot',
'votes',
'file',
'rating',
'ratings',
'userrating',
'resume',
'tvshowid',
'firstaired',
'art',
'streamdetails',
'runtime',
'director',
'writer',
'cast',
'dateadded',
'lastplayed'
],
'tvshow_properties': [
'title',
'studio',
'year',
'plot',
'cast',
'rating',
'ratings',
'userrating',
'votes',
'genre',
'episode',
'season',
'runtime',
'mpaa',
'premiered',
'playcount',
'lastplayed',
'sorttitle',
'originaltitle',
'art',
'tag',
'dateadded',
'imdbnumber'
]
}
def logjson(msg):
xbmc.log(msg=json.dumps(msg, sort_keys=True, indent=4, separators=(',', ': ')), level=xbmc.LOGINFO)
def logtext(msg):
xbmc.log(msg=msg, level=xbmc.LOGINFO)
def getPath(li):
return li['file']
def isFolder(li):
return li['isFolder']
def set_plugincontent(id, content=None,category=None):
if category:
xbmcplugin.setPluginCategory(id, category)
if content:
xbmcplugin.setContent(id, content)
def buildListItem(iteminfo):
watchedepisodes = iteminfo.pop('watchedepisodes', '')
art = iteminfo.pop('art', '')
cast = iteminfo.pop('cast', '')
label = iteminfo.pop('label', '')
if 'tvshowid' in iteminfo:
isFolder = True
iteminfo['mediatype'] = 'tvshow'
iteminfo['dbid'] = iteminfo.pop('tvshowid', '')
iteminfo['path'] = 'videodb://tvshows/titles/%s/' % iteminfo['dbid']
if 'episodeid' in iteminfo:
isFolder = False
iteminfo['mediatype'] = 'episode'
iteminfo['path'] = iteminfo.pop('file', '')
iteminfo['premiered'] = iteminfo.pop('firstaired', '')
iteminfo['dbid'] = iteminfo.pop('episodeid', '')
iteminfo['tvshowtitle'] = iteminfo.pop('showtitle', '')
streamdetails = iteminfo.pop('streamdetails', '')
ratings = iteminfo.pop('ratings', '')
resume = iteminfo.pop('resume', None)
runtime = iteminfo.pop('runtime', '')
li = xbmcgui.ListItem(label=label, path=iteminfo['path'], offscreen=True)
li.setIsFolder(isFolder)
li.setArt(art)
info_tag = ListItemInfoTag(li, 'video')
info_tag.set_info(iteminfo)
info_tag.set_cast(cast)
if resume is not None:
info_tag._info_tag.setResumePoint(resume['position'],resume['total'])
info_tag.set_stream_details(streamdetails)
return li
def finalizeList(id, items, category=None, content=None):
xbmcplugin.addDirectoryItems(id, [(item.getPath(), item, item.isFolder()) for item in items if item])
xbmcplugin.endOfDirectory(handle=id)
set_plugincontent(id, category=category, content=content)
def get_date(date_time):
# Hack for broken embedded python
# https://forum.kodi.tv/showthread.php?tid=112916
# https://bugs.python.org/issue27400
try:
date_time_obj = datetime.strptime(date_time, '%Y-%m-%d %H:%M:%S')
except TypeError:
date_time_obj = datetime(*(time.strptime(date_time, '%Y-%m-%d %H:%M:%S')[0:6]))
date_obj = date_time_obj.date()
return str(date_obj)
def json_call(method, properties=None, sort=None, query_filter=None, limit=None, params=None, item=None, options=None, limits=None):
json_string = {'jsonrpc': '2.0', 'id': 1, 'method': method, 'params': {}}
if properties is not None:
json_string['params']['properties'] = properties
if limit is not None:
json_string['params']['limits'] = {'start': 0, 'end': int(limit)}
if sort is not None:
json_string['params']['sort'] = sort
if query_filter is not None:
json_string['params']['filter'] = query_filter
if options is not None:
json_string['params']['options'] = options
if limits is not None:
json_string['params']['limits'] = limits
if item is not None:
json_string['params']['item'] = item
if params is not None:
json_string['params'].update(params)
jsonrpc_call = json.dumps(json_string)
result = xbmc.executeJSONRPC(jsonrpc_call)
result = json.loads(result)
return result