1 |
torben |
1629 |
''' |
2 |
|
|
Todic plugin for XBMC |
3 |
|
|
Version 0.0.2 |
4 |
|
|
''' |
5 |
|
|
|
6 |
|
|
import sys |
7 |
|
|
import cgi as urlparse |
8 |
|
|
|
9 |
|
|
import xbmc |
10 |
|
|
import xbmcaddon |
11 |
|
|
import xbmcgui |
12 |
|
|
import xbmcplugin |
13 |
|
|
import urllib |
14 |
|
|
import urllib2, re |
15 |
|
|
|
16 |
|
|
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
17 |
|
|
__key__ = __addon__.getSetting('xbmckey').lower() |
18 |
|
|
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
19 |
|
|
|
20 |
|
|
def open_url(url): |
21 |
|
|
req = urllib2.Request(url) |
22 |
|
|
content = urllib2.urlopen(req) |
23 |
|
|
data = content.read() |
24 |
|
|
content.close() |
25 |
|
|
return data |
26 |
|
|
|
27 |
|
|
def rootMenu(): |
28 |
|
|
link = open_url(__backend__) |
29 |
|
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url>').findall(link) |
30 |
|
|
for name,url in m: |
31 |
|
|
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
32 |
|
|
u = sys.argv[0] + "?mode=1&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
33 |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
34 |
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
35 |
|
|
|
36 |
|
|
|
37 |
|
|
def buildList(url,title): |
38 |
|
|
print '[TODIC]:'+str(url) |
39 |
|
|
link = open_url(url) |
40 |
|
|
ty=re.compile('<meta type=\'(.+?)\'').findall(link) |
41 |
|
|
print '[TOD]'+str(ty[0]) |
42 |
|
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link) |
43 |
|
|
for name,url,thumb in m: |
44 |
|
|
if ty[0] == 'clipList': |
45 |
|
|
mode = '50' |
46 |
|
|
folder = False |
47 |
|
|
else: |
48 |
|
|
mode = '2' |
49 |
|
|
folder = True |
50 |
|
|
|
51 |
|
|
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
52 |
|
|
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
53 |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder) |
54 |
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
55 |
|
|
|
56 |
|
|
def buildSubList(url,title): |
57 |
|
|
print '[TODIC]:'+str(url) |
58 |
|
|
link = open_url(url) |
59 |
|
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link) |
60 |
|
|
for name,url,thumb in m: |
61 |
|
|
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
62 |
|
|
u = sys.argv[0] + "?mode=50&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
63 |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = False) |
64 |
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
def play_video(url, name): |
69 |
|
|
link = open_url(url) |
70 |
|
|
match=re.compile('<url>(.+?)</url>').findall(link) |
71 |
|
|
url = match[0] |
72 |
|
|
print '[TODIC]:'+str(url) |
73 |
|
|
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
74 |
|
|
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
75 |
|
|
# listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png') |
76 |
|
|
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
77 |
|
|
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
78 |
|
|
xbmc.sleep(200) |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
def get_params(): |
82 |
|
|
param=[] |
83 |
|
|
paramstring=sys.argv[2] |
84 |
|
|
if len(paramstring)>=2: |
85 |
|
|
params=sys.argv[2] |
86 |
|
|
cleanedparams=params.replace('?','') |
87 |
|
|
if (params[len(params)-1]=='/'): |
88 |
|
|
params=params[0:len(params)-2] |
89 |
|
|
pairsofparams=cleanedparams.split('&') |
90 |
|
|
param={} |
91 |
|
|
for i in range(len(pairsofparams)): |
92 |
|
|
splitparams={} |
93 |
|
|
splitparams=pairsofparams[i].split('=') |
94 |
|
|
if (len(splitparams))==2: |
95 |
|
|
param[splitparams[0]]=splitparams[1] |
96 |
|
|
return param |
97 |
|
|
|
98 |
|
|
params = get_params() |
99 |
|
|
url = None |
100 |
|
|
name = None |
101 |
|
|
mode = None |
102 |
|
|
|
103 |
|
|
params = get_params() |
104 |
|
|
url = None |
105 |
|
|
name = None |
106 |
|
|
mode = None |
107 |
|
|
|
108 |
|
|
try: |
109 |
|
|
url = urllib.unquote_plus(params["url"]) |
110 |
|
|
except: |
111 |
|
|
pass |
112 |
|
|
try: |
113 |
|
|
name = urllib.unquote_plus(params["name"]) |
114 |
|
|
except: |
115 |
|
|
pass |
116 |
|
|
try: |
117 |
|
|
mode = int(params["mode"]) |
118 |
|
|
except: |
119 |
|
|
pass |
120 |
|
|
|
121 |
|
|
|
122 |
|
|
if mode == None: |
123 |
|
|
#build main menu |
124 |
|
|
rootMenu() |
125 |
|
|
|
126 |
|
|
elif mode == 1: |
127 |
|
|
#build list of movie starting letters |
128 |
|
|
buildList(url, name) |
129 |
|
|
|
130 |
|
|
elif mode == 2: |
131 |
|
|
#build list of series |
132 |
|
|
buildSubList(url, name) |
133 |
|
|
|
134 |
|
|
elif mode == 50: |
135 |
|
|
play_video(url, name) |
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |