forked from Gothicawakening/plugin.program.shortlist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon.py
More file actions
213 lines (163 loc) · 7.51 KB
/
Copy pathaddon.py
File metadata and controls
213 lines (163 loc) · 7.51 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
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
import sys
import urllib
import urlparse
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__ = xbmc.translatePath( __addon__.getAddonInfo('profile') )
__language__ = __addon__.getLocalizedString
addon_handle = int(sys.argv[1])
args = urlparse.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.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 is not "":
name = nameNice.lower( ) + ".db"
# Build database
database = []
# No need to save it's it's done below
else:
xbmc.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 thumbnail and poster
li = xbmcgui.ListItem(item.title, iconImage='DefaultVideo.png')
li.setArt( { 'thumb' : item.thumb, 'poster' : item.poster, 'fanart' : item.fanart } )
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.urlencode( {'action': 'delete', 'dbName' : dbName[0], 'filename': filename } )
script = 'XBMC.RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Remove from Shortlist', script, ) )
commands.append( ( __language__( 30001 ), script, ) )
params = urllib.urlencode( {'action': 'moveUp', 'dbName' : dbName[0], 'filename': filename} )
script = 'XBMC.RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Move Up', script, ) )
commands.append( ( __language__( 30002 ), script, ) )
params = urllib.urlencode( {'action': 'moveDn', 'dbName' : dbName[0], 'filename': filename } )
script = 'XBMC.RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Move Down', script, ) )
commands.append( ( __language__( 30003 ), script, ) )
params = urllib.urlencode( {'action': 'moveTop', 'dbName' : dbName[0], 'filename': filename } )
script = 'XBMC.RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Move To Top', script, ) )
commands.append( ( __language__( 30004 ), script, ) )
params = urllib.urlencode( {'action': 'moveBottom', 'dbName' : dbName[0], 'filename': filename } )
script = 'XBMC.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 ), script, ) )
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, iconImage='DefaultFolder.png')
# li.setProperty('isFolder', 'true')
# li.setProperty('isPlayable', 'true')
filename = build_url({'dbName': db})
is_folder = True
# Build the context menu items
commands = []
params = urllib.urlencode( {'action': 'deleteList', 'databaseName': db } )
script = 'XBMC.RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Delete Shortlist', script, ) )
commands.append( ( __language__( 30007 ), script, ) )
params = urllib.urlencode( {'action': 'createList' } )
script = 'XBMC.RunPlugin("plugin://plugin.program.shortlist/?%s")' % params
# commands.append( ( 'Create Shortlist', script, ) )
commands.append( ( __language__( 30008 ), script, ) )
li.addContextMenuItems( commands )
# xbmc.log( filename, xbmc.LOGNOTICE);
xbmcplugin.addDirectoryItem(handle=addon_handle, url=filename, listitem=li, isFolder=True)
xbmcplugin.endOfDirectory(addon_handle)