forked from Gothicawakening/plugin.program.shortlist
-
Notifications
You must be signed in to change notification settings - Fork 3
/
addon.py
267 lines (205 loc) · 9.19 KB
/
addon.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import sys
import xbmcvfs
import urllib.request, urllib.parse, urllib.error
import urllib.parse
import xbmcgui
import xbmcplugin
import xbmcaddon
import os
import pickle
from shortlistitem import ShortlistItem
from database import *
base_url = sys.argv[0]
__addon__ = xbmcaddon.Addon(id='plugin.program.shortlist')
__addondir__ = xbmcvfs.translatePath( __addon__.getAddonInfo('profile') )
__language__ = __addon__.getLocalizedString
addon_handle = int(sys.argv[1])
args = urllib.parse.parse_qs(sys.argv[2][1:])
xbmcplugin.addSortMethod( addon_handle, xbmcplugin.SORT_METHOD_PLAYLIST_ORDER)
xbmcplugin.addSortMethod( addon_handle, xbmcplugin.SORT_METHOD_TITLE)
xbmcplugin.addSortMethod( addon_handle, xbmcplugin.SORT_METHOD_DURATION)
xbmcplugin.addSortMethod( addon_handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
xbmcplugin.addSortMethod( addon_handle, xbmcplugin.SORT_METHOD_VIDEO_RATING)
action = args.get( 'action' )
dbName = args.get( 'dbName' )
databaseName = args.get( 'databaseName' )
def build_url(query):
return base_url + '?' + urllib.parse.urlencode(query)
if action is not None:
# Process action
filename = args.get( 'filename' )
# Load database
if dbName is not None:
name = dbName[0].lower() + ".db"
database = getDatabaseByName( name )
else:
name = ""
database = None
if action[0] == 'delete':
# Delets specified item
if filename is not None:
deleteItem( database, filename[0] )
elif action[0] == 'moveUp':
# Move item up in the list
if filename is not None:
moveUp( database, filename[0] )
elif action[0] == 'moveDn':
# Move item up in the list
if filename is not None:
moveDown( database, filename[0] )
elif action[0] == 'moveTop':
# Move item to start the list
if filename is not None:
moveToTop( database, filename[0] )
elif action[0] == 'moveBottom':
# Move item to end the list
if filename is not None:
moveToBottom( database, filename[0] )
elif action[0] == 'deleteList':
# Delete a list database files
if databaseName is not None:
# Delete files\
nameNice = databaseName[0]
name = nameNice.lower() + ".db"
filename = __addondir__ + name
dialog = xbmcgui.Dialog()
# ret = dialog.yesno('Kodi', 'Do you want to delete the "' + nameNice + '" shortlist?')
ret = dialog.yesno('Kodi', __language__( 30009 ) + ' "' + nameNice + '" ' + __language__( 30010 ) )
if ret == True:
os.remove( filename )
elif action[0] == 'createList':
# Add a new list to the database
dialog = xbmcgui.Dialog()
nameNice = dialog.input(__language__( 30011 ), type=xbmcgui.INPUT_ALPHANUM)
database = None
if nameNice is not None and nameNice != "":
name = nameNice.lower( ) + ".db"
# Build database
database = []
# No need to save it's it's done below
elif action[0] == 'renameList':
# Rename a list for the database
dialog = xbmcgui.Dialog()
nameNice = dialog.input(__language__( 30013 ), type=xbmcgui.INPUT_ALPHANUM)
database = None
if nameNice is not None and nameNice != "":
newname = nameNice.lower( ) + ".db"
newfilename = __addondir__ + newname
nameNice = databaseName[0]
name = nameNice.lower() + ".db"
filename = __addondir__ + name
# name = newname
debug = "SHORTLIST: Action Rename: " + filename + " TO " + newfilename
xbmc.log(debug, level=xbmc.LOGINFO)
os.rename(filename, newfilename)
else:
log("SHORTLIST: Action Unknown: " + action)
if database is not None:
saveDatabaseByName( database, name )
# Refresh the file list
xbmc.executebuiltin("Container.Refresh")
else:
# Show lists
if dbName is not None:
# Show list of movies
xbmcplugin.setContent(addon_handle, 'movies')
# Load database
name = dbName[0].lower() + ".db"
database = getDatabaseByName( name )
# Add each item to the directory
count = 0
for item in database:
# Create a listitem with art
li = xbmcgui.ListItem(item.title)
li.setArt( { 'thumb' : item.thumb,
'poster' : item.poster,
'fanart' : item.fanart,
'banner' : item.banner,
'clearart' : item.clearart,
'clearlogo' : item.clearlogo,
'landscape' : item.landscape,
'icon' : item.icon
} )
filename = item.filename
# Add some video info
info = {}
info['year'] = item.year
info['duration'] = item.duration
info['rating'] = item.rating
info['plot'] = item.plot
info['plotoutline'] = item.plotoutline
info['title'] = item.title
info['count'] = count
li.setInfo( 'video', info )
# Build the context menu items
commands = []
params = urllib.parse.urlencode( {'action': 'delete', 'dbName' : dbName[0], 'filename': filename } )
script = 'RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Remove from Shortlist', script, ) )
commands.append( ( __language__( 30001 ), script, ) )
params = urllib.parse.urlencode( {'action': 'moveUp', 'dbName' : dbName[0], 'filename': filename} )
script = 'RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Move Up', script, ) )
commands.append( ( __language__( 30002 ), script, ) )
params = urllib.parse.urlencode( {'action': 'moveDn', 'dbName' : dbName[0], 'filename': filename } )
script = 'RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Move Down', script, ) )
commands.append( ( __language__( 30003 ), script, ) )
params = urllib.parse.urlencode( {'action': 'moveTop', 'dbName' : dbName[0], 'filename': filename } )
script = 'RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Move To Top', script, ) )
commands.append( ( __language__( 30004 ), script, ) )
params = urllib.parse.urlencode( {'action': 'moveBottom', 'dbName' : dbName[0], 'filename': filename } )
script = 'RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Move To Bottom', script, ) )
commands.append( ( __language__( 30005 ), script, ) )
# commands.append( ( 'Show Info', 'Action(Info)', ) )
commands.append( ( __language__( 30006 ), 'Action(Info)', ) )
li.addContextMenuItems( commands )
# Add listitem to directory
xbmcplugin.addDirectoryItem(handle=addon_handle, url=filename, listitem=li)
count = count + 1
xbmcplugin.endOfDirectory(addon_handle)
else:
# Show available lists
xbmcplugin.setContent(addon_handle, 'files')
# Add each item to the directory
dbList = listDatabases()
for db in dbList:
li = xbmcgui.ListItem( db )
# li.setProperty('isFolder', 'true')
# li.setProperty('isPlayable', 'true')
filename = build_url({'dbName': db})
is_folder = True
# Build the context menu items
commands = []
params = urllib.parse.urlencode( {'action': 'deleteList', 'databaseName': db } )
script = 'RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Delete Shortlist', script, ) )
commands.append( ( __language__( 30007 ), script, ) )
params = urllib.parse.urlencode( {'action': 'createList' } )
script = 'RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Create Shortlist', script, ) )
commands.append( ( __language__( 30008 ), script, ) )
params = urllib.parse.urlencode( {'action': 'renameList', 'databaseName': db } )
script = 'RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Rename Shortlist', script, ) )
commands.append( ( __language__( 30013 ), script, ) )
li.addContextMenuItems( commands )
# log( filename, LOGNOTICE);
xbmcplugin.addDirectoryItem(handle=addon_handle, url=filename, listitem=li, isFolder=True)
xbmcplugin.endOfDirectory(addon_handle)
try:
dialog
except NameError:
dialog = None
if dialog is not None:
del dialog
try:
li
except NameError:
li = None
if li is not None:
del li
del ShortlistItem
del addItem, addItemToDatabase, itemExists, deleteItem, deleteItemFromDatabase, moveUp, moveDown, moveToTop, moveToBottom, getDatabase, getDatabaseByName, saveDatabase, saveDatabaseByName, listDatabases