forked from 5-star/plugin.video.last_played
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon.py
More file actions
173 lines (167 loc) · 7.11 KB
/
Copy pathaddon.py
File metadata and controls
173 lines (167 loc) · 7.11 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
171
172
173
# -*- coding: utf-8 -*-
import sys
import json
import xbmc
import xbmcplugin
import xbmcaddon
import xbmcvfs
import xbmcgui
from xbmcplugin import addDirectoryItem, endOfDirectory
try:
from urllib.parse import parse_qs, urlencode
except ImportError:
from urlparse import parse_qs
from urllib import urlencode
addon = xbmcaddon.Addon()
addon_handle = int(sys.argv[1])
args = parse_qs(sys.argv[2][1:])
menu = args.get('menu', None)
try: list_size = int(addon.getSetting('list_size'))
except Exception: list_size=0
try: top_size = int(addon.getSetting('top_size'))
except Exception: top_size=0
single_list = addon.getSetting('single_list')
group_by = addon.getSetting('group_by')
show_date = addon.getSetting('show_date')
show_time = addon.getSetting('show_time')
enable_debug = addon.getSetting('enable_debug')
lang = addon.getLocalizedString
if addon.getSetting('custom_path_enable') == "true" and addon.getSetting('custom_path') != "":
txtpath = addon.getSetting('custom_path')
else:
txtpath = xbmcvfs.translatePath(addon.getAddonInfo('profile'))
txtfile = txtpath + "lastPlayed.json"
imgPath=xbmcvfs.translatePath(xbmcaddon.Addon().getAddonInfo('path'))
group_by_type=lang(30018)
def url(pQuery):
return sys.argv[0] + '?' + urlencode(pQuery)
def list_items(selGroup, nbrLines):
xbmcplugin.setContent(addon_handle, "files")
if xbmcvfs.exists(txtfile):
f = xbmcvfs.File(txtfile)
nbr=0 # nbr of line on screen (selected)
idx=0 # idx of line on the json file
try: lines = json.load(f)
except: lines = []
for line in lines:
if nbr>=nbrLines: break
if group_by == group_by_type: group = line["type"]
else: group = line["source"]
if len(line)>3 and (group==selGroup or selGroup=='*'):
nbr=nbr+1
desc=''
if show_date == "true": desc = desc + line["date"].strip() + ' '
if show_time == "true": desc = desc + line["time"].strip() + ' '
show = ''
if 'show' in line: show=line["show"] + " "
if 'season' in line and line["season"]!='' and str(line["season"])!="-1":
if 'episode' in line and line["episode"]!='' and str(line["episode"])!="-1":
show = show + str(line["season"])+"x"+str(line["episode"]) + " "
desc=desc + show + line["title"]
if 'artist' in line and line["artist"]!='': desc=desc+" - "+str(line["artist"])
xpath=""
infolabels={'title': desc, 'year': line['year'], "mediatype": line['type'], 'Top250': line['id']}
li = xbmcgui.ListItem(label=desc)
li.setInfo('video', infolabels)
li.setArt({ "poster" : line["thumbnail"].strip() })
li.setArt({ "thumbnail" : line["thumbnail"].strip() })
li.setArt({ "fanart" : line["fanart"].strip() })
li.setProperty('IsPlayable', 'true')
command = []
command.append((lang(30008), "RunPlugin(plugin://plugin.video.last_played?menu=remove&id="+str(idx)+")"))
if line["file"][:6]=="plugin":
command.append((lang(30031)+line["source"], "PlayMedia(" + line["file"] + ")"))
li.addContextMenuItems(command)
xurl=line["file"]
if "video" in line and line["video"]!="": xurl=line["video"]
addDirectoryItem(addon_handle, xurl, li)
idx = idx + 1
f.close()
if single_list == "true" and nbr == 0:
li = xbmcgui.ListItem(lang(30030))
li.setProperty('IsPlayable', 'false')
addDirectoryItem(addon_handle, "", li, isFolder = True)
def list_groups():
if xbmcvfs.exists(txtfile):
groups = []
f = xbmcvfs.File(txtfile)
try:
lines = json.load(f);
except Exception:
lines = []
for line in lines:
if len(line)>5:
if group_by == group_by_type:
group = line["type"]
else:
group = line["source"]
if group not in groups:
groups.append(group)
if group_by == group_by_type:
nm = group
ic = imgPath+'/resources/' + group + '.png'
else:
nm = group
ads = group.split("/")
if len(ads) > 2: nm = ads[2]
if group==lang(30002): ic = imgPath+'/resources/movie.png'
elif group==lang(30003): ic = imgPath+'/resources/episode.png'
elif group==lang(30004): ic = imgPath+'/resources/musicvideo.png'
else:
try:
la = xbmcaddon.Addon(nm)
nm = la.getAddonInfo('name')
ic = la.getAddonInfo('icon')
except Exception:
ic = imgPath+'/resources/addons.png'
li = xbmcgui.ListItem(nm)
li.setArt({'thumbnail':ic})
addDirectoryItem(addon_handle, url({'menu': group}), li, True)
f.close()
# Menu
if menu is None or menu[0]=="top":
if single_list == "true":
list_items("*", list_size)
else:
xbmcplugin.setContent(addon_handle, "menu")
list_items("*", top_size)
if top_size>0: addDirectoryItem(addon_handle, "", xbmcgui.ListItem(label=""), False)
list_groups()
if enable_debug == "true":
addDirectoryItem(addon_handle, url({'menu': 'showlist'}), xbmcgui.ListItem(lang(30014)), True)
if xbmcvfs.exists(txtfile):
addDirectoryItem(addon_handle, url({'menu': 'deletelist'}), xbmcgui.ListItem(lang(30015)), True)
else:
addDirectoryItem(addon_handle, url({'menu': 'deletelist'}), xbmcgui.ListItem(lang(30016)), True)
endOfDirectory(addon_handle)
elif menu[0] == 'remove':
lid = args.get('id', None)
if xbmcvfs.exists(txtfile) and lid is not None:
f = xbmcvfs.File(txtfile)
lines = json.load(f)
f.close()
osz = len(lines)
lines.remove(lines[int(lid[0])])
# to avoid accidental cleaning, update empty file only it had only one line before
if len(lines)>0 or osz==1:
f = xbmcvfs.File(txtfile, 'w')
json.dump(lines, f)
f.close()
xbmc.executebuiltin("ActivateWindow(Videos,plugin://plugin.video.last_played?menu=top)")
elif menu[0] == 'showlist':
if xbmcvfs.exists(txtfile):
f = xbmcvfs.File(txtfile)
lines = json.load(f)
f.close()
for line in lines:
addDirectoryItem(addon_handle, url({}), xbmcgui.ListItem(str(line)), False)
endOfDirectory(addon_handle)
elif menu[0] == 'deletelist':
if xbmcvfs.exists(txtfile):
lines = []
f = xbmcvfs.File(txtfile, 'w')
json.dump(lines, f)
f.close()
else:
list_items(menu[0], list_size)
endOfDirectory(addon_handle)