This repository has been archived by the owner on Sep 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.py
executable file
·226 lines (206 loc) · 6.4 KB
/
default.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
import urllib,urllib2,re,os,htmlentitydefs
import xbmcplugin,xbmcgui,xbmcaddon
from BeautifulSoup import BeautifulStoneSoup
__settings__ = xbmcaddon.Addon(id='plugin.video.5by5')
__language__ = __settings__.getLocalizedString
home = __settings__.getAddonInfo('path')
icon = xbmc.translatePath( os.path.join( home, 'icon.png' ) )
# options
option_label = __settings__.getSetting( "label" )
option_banner = __settings__.getSetting( "banner" )
def converthtml(text):
def fixup(m):
text = m.group(0)
if text[:2] == "&#":
# character reference
try:
if text[:3] == "&#x":
return unichr(int(text[3:-1], 16))
else:
return unichr(int(text[2:-1]))
except ValueError:
pass
else:
# named entity
try:
text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
except KeyError:
pass
return text # leave as is
return re.sub("&#?\w+;", fixup, text)
def getShows():
url='http://5by5.tv/rss-boxee'
req = urllib2.Request(url)
response = urllib2.urlopen(req)
link=response.read()
response.close()
soup = BeautifulStoneSoup(link)
shows = soup('item')
for show in shows:
name = show.title.string
url = show.link.string
url = url.replace('rss://', 'http://')
description = show.description.string
aired = show.pubdate.string
year = aired[12:16]
day = aired[5:7]
month = aired[8:11]
if month == 'Jan':
month = '01'
elif month == 'Feb':
month = '02'
elif month == 'Mar':
month = '03'
elif month == 'Apr':
month = '04'
elif month == 'May':
month = '05'
elif month == 'Jun':
month = '06'
elif month == 'Jul':
month = '07'
elif month == 'Aug':
month = '08'
elif month == 'Sep':
month = '09'
elif month == 'Oct':
month = '10'
elif month == 'Nov':
month = '11'
elif month == 'Dec':
month = '12'
aired = year+'-'+month+'-'+day
img = show('boxee:image')[0]
img = ' '.join(img)
img = img.replace('<boxee:image>', '')
img = img.replace('-big.jpg', '-large.jpg')
if option_banner == "true":
img = img.replace('/cover_art/', '/images/')
addDir(name,url,description,aired,1,img)
def index(url):
req = urllib2.Request(url)
response = urllib2.urlopen(req)
link=response.read()
response.close()
soup = BeautifulStoneSoup(link)
eps = soup('item')
eps.reverse()
for ep in eps:
name = ep.title.string
name = unicode(name).encode("utf-8")
name = converthtml(name)
url = ep.link.string
description = ep.description.string
description = unicode(description).encode("utf-8")
description = converthtml(description)
img = ep('boxee:image')[0]
img = ' '.join(img)
img = img.replace('<boxee:image>', '')
img = img.replace('-big.jpg', '-large.jpg')
if option_banner == "true":
img = img.replace('/cover_art/', '/images/')
cast = ep('boxee:cast')[0]
cast = ' '.join(cast)
cast = cast.replace('<boxee:cast>', '')
cast = unicode(cast).encode("utf-8")
cast = converthtml(cast)
aired = ep.pubdate.string
year = aired[12:16]
day = aired[5:7]
month = aired[8:11]
if month == 'Jan':
month = '01'
elif month == 'Feb':
month = '02'
elif month == 'Mar':
month = '03'
elif month == 'Apr':
month = '04'
elif month == 'May':
month = '05'
elif month == 'Jun':
month = '06'
elif month == 'Jul':
month = '07'
elif month == 'Aug':
month = '08'
elif month == 'Sep':
month = '09'
elif month == 'Oct':
month = '10'
elif month == 'Nov':
month = '11'
elif month == 'Dec':
month = '12'
aired = year+'-'+month+'-'+day
# Unrelated Video Override
if name == "#9: 7 Inches":
url = "http://audio.5by5.tv/broadcasts/talkshow/2010/talkshow-009.mp3"
if url.find('.mp4') != -1:
label = 'Video'
if (option_label == "3" or option_label == "2"):
name = name+" (Video)"
addLink(name,url,description,1,img,label,cast,aired,"video")
elif url.find('.mp3') != -1:
label = 'Audio'
if (option_label == "3" or option_label == "1"):
name = name+" (Audio)"
addLink(name,url,description,1,img,label,cast,aired,"audio")
def get_params():
param=[]
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
def addLink(name,url,description,length,iconimage,label,cast,aired,medium):
ok=True
liz=xbmcgui.ListItem(name, label, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
if medium == "video":
liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": description, "Duration": length, "Cast": cast, "Aired": aired } )
elif medium == "audio":
liz.setInfo( type="Music", infoLabels={ "Title": name, "Lyrics": description, "Artist": cast, "Date": aired } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
return ok
def addDir(name,url,description,aired,mode,iconimage):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": description, "Aired": aired } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
params=get_params()
url=None
name=None
mode=None
try:
url=urllib.unquote_plus(params["url"])
except:
pass
try:
name=urllib.unquote_plus(params["name"])
except:
pass
try:
mode=int(params["mode"])
except:
pass
print "Mode: "+str(mode)
print "URL: "+str(url)
print "Name: "+str(name)
if mode==None:
print ""
getShows()
elif mode==1:
print ""+url
index(url)
xbmcplugin.endOfDirectory(int(sys.argv[1]))