/[projects]/misc/xbmc/plugin.video.todic/default.py
ViewVC logotype

Annotation of /misc/xbmc/plugin.video.todic/default.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1630 - (hide annotations) (download) (as text)
Sun Nov 27 11:05:43 2011 UTC (12 years, 6 months ago) by torben
File MIME type: text/x-python
File size: 4253 byte(s)
add progresswhile loading listings
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 torben 1630 l = len(m)
31 torben 1629 for name,url in m:
32     listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
33     u = sys.argv[0] + "?mode=1&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)
34 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l)
35 torben 1629 xbmcplugin.endOfDirectory(int(sys.argv[1]))
36    
37    
38     def buildList(url,title):
39     print '[TODIC]:'+str(url)
40     link = open_url(url)
41     ty=re.compile('<meta type=\'(.+?)\'').findall(link)
42     print '[TOD]'+str(ty[0])
43     m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link)
44 torben 1630 l=len(m)
45 torben 1629 for name,url,thumb in m:
46     if ty[0] == 'clipList':
47     mode = '50'
48     folder = False
49     else:
50     mode = '2'
51     folder = True
52    
53     listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
54     u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)
55 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
56 torben 1629 xbmcplugin.endOfDirectory(int(sys.argv[1]))
57    
58     def buildSubList(url,title):
59     print '[TODIC]:'+str(url)
60     link = open_url(url)
61     m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link)
62 torben 1630 l = len(m)
63 torben 1629 for name,url,thumb in m:
64     listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
65     u = sys.argv[0] + "?mode=50&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)
66 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = False, totalItems = l)
67 torben 1629 xbmcplugin.endOfDirectory(int(sys.argv[1]))
68    
69    
70    
71     def play_video(url, name):
72     link = open_url(url)
73     match=re.compile('<url>(.+?)</url>').findall(link)
74     url = match[0]
75     print '[TODIC]:'+str(url)
76     image = xbmc.getInfoImage( 'ListItem.Thumb' )
77     listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)
78     # listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png')
79     listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
80     xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem)
81     xbmc.sleep(200)
82    
83    
84     def get_params():
85     param=[]
86     paramstring=sys.argv[2]
87     if len(paramstring)>=2:
88     params=sys.argv[2]
89     cleanedparams=params.replace('?','')
90     if (params[len(params)-1]=='/'):
91     params=params[0:len(params)-2]
92     pairsofparams=cleanedparams.split('&')
93     param={}
94     for i in range(len(pairsofparams)):
95     splitparams={}
96     splitparams=pairsofparams[i].split('=')
97     if (len(splitparams))==2:
98     param[splitparams[0]]=splitparams[1]
99     return param
100    
101     params = get_params()
102     url = None
103     name = None
104     mode = None
105    
106     params = get_params()
107     url = None
108     name = None
109     mode = None
110    
111     try:
112     url = urllib.unquote_plus(params["url"])
113     except:
114     pass
115     try:
116     name = urllib.unquote_plus(params["name"])
117     except:
118     pass
119     try:
120     mode = int(params["mode"])
121     except:
122     pass
123    
124    
125     if mode == None:
126     #build main menu
127     rootMenu()
128    
129     elif mode == 1:
130     #build list of movie starting letters
131     buildList(url, name)
132    
133     elif mode == 2:
134     #build list of series
135     buildSubList(url, name)
136    
137     elif mode == 50:
138     play_video(url, name)
139    
140    
141    
142     xbmcplugin.endOfDirectory(int(sys.argv[1]))

  ViewVC Help
Powered by ViewVC 1.1.20