forked from pkscout/context.item.extras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.py
94 lines (78 loc) · 2.87 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
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 Thomas Amland
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import xbmc
import xbmcvfs
import routing
import xbmcaddon
import xbmcplugin
from xbmcgui import Dialog, ListItem
from urllib import urlencode, quote_plus
plugin = routing.Plugin()
@plugin.route("/")
def browse():
args = plugin.args
if 'path' not in args:
# back navigation workaround: just silently fail and we'll
# eventually end outside the plugin dir
xbmcplugin.endOfDirectory(plugin.handle, succeeded=False)
return
current_path = args['path'][0]
if not current_path.endswith('/'):
current_path += '/'
dirs = []
files = []
if xbmcvfs.exists(current_path):
dirs, files = xbmcvfs.listdir(current_path)
for name in dirs:
li = ListItem(name)
if 'fanart' in args:
li.setArt({'fanart': args['fanart'][0]})
path = os.path.join(current_path, name)
params = {
b'path': path,
b'title': args['title'][0],
b'fanart': args['fanart'][0],
}
url = 'plugin://context.item.extras/?' + urlencode(params)
xbmcplugin.addDirectoryItem(plugin.handle, url, li, isFolder=True)
for name in files:
li = ListItem(name)
if 'fanart' in args:
li.setArt({'fanart': args['fanart'][0]})
url = os.path.join(current_path, name)
xbmcplugin.addDirectoryItem(plugin.handle, url, li, isFolder=False)
if 'isroot' in args:
li = ListItem("Search on Youtube")
li.setProperty("specialsort", "bottom")
url = plugin.url_for(youtube, q=args['title'][0] + ' Extras')
xbmcplugin.addDirectoryItem(plugin.handle, url, li, isFolder=True)
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.endOfDirectory(plugin.handle)
@plugin.route("/youtube")
def youtube():
query = plugin.args['q'][0]
kb = xbmc.Keyboard(query, 'Search')
kb.doModal()
if kb.isConfirmed():
edited_query = kb.getText()
if edited_query:
url = b"plugin://plugin.video.youtube/search/?q=" + \
quote_plus(edited_query)
xbmc.executebuiltin(b'Container.Update(\"%s\")' % url)
if __name__ == '__main__':
plugin.run()