forked from AddonScriptorDE/plugin.video.southpark_de
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.py
180 lines (166 loc) · 7.75 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib,urllib2,re,xbmcplugin,xbmcgui,sys,xbmcaddon,base64,socket
socket.setdefaulttimeout(30)
pluginhandle = int(sys.argv[1])
xbox = xbmc.getCondVisibility("System.Platform.xbox")
addon = xbmcaddon.Addon(id='plugin.video.southpark_de')
translation = addon.getLocalizedString
language=addon.getSetting("language")
forceViewMode=addon.getSetting("forceViewMode")
if forceViewMode=="true":
forceViewMode=True
else:
forceViewMode=False
viewMode=str(addon.getSetting("viewMode"))
playIntro=addon.getSetting("playIntro")
if language=="0":
language=""
elif language=="1":
language="en"
def index():
addLink(translation(30003),"",'playRandom',"","")
content = getUrl("http://www.southpark.de/alle-episoden")
content = content[content.find('content_epfinder'):]
content = content[:content.find('content_carouselwrap')]
match=re.compile('data-promoId="(.+?)"', re.DOTALL).findall(content)
promoId=match[0]
match=re.compile('href="(.+?)">(.+?)</a>', re.DOTALL).findall(content)
for url, staffel in match:
if url.find("/random")==-1:
addDir(str(translation(30001))+" "+staffel,"http://www.southpark.de/feeds/full-episode/carousel/"+staffel+"/"+promoId,'listVideos',"")
xbmcplugin.endOfDirectory(pluginhandle)
if forceViewMode==True:
xbmc.executebuiltin('Container.SetViewMode('+viewMode+')')
def playRandom():
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear()
i=1
for i in range(1,100,1):
if xbox==True:
url="plugin://video/SouthPark.de/?url=http://www.southpark.de/alle-episoden/random&mode=playVideo"
else:
url="plugin://plugin.video.southpark_de/?url=http://www.southpark.de/alle-episoden/random&mode=playVideo"
listitem = xbmcgui.ListItem("South Park: "+translation(30003)+" "+str(i))
i=i+1
playlist.add(url,listitem)
def listVideos(url):
xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_LABEL)
content = getUrl(url)
spl=content.split('title:')
for i in range(1,len(spl),1):
entry=spl[i]
match=re.compile("'(.+?)',", re.DOTALL).findall(entry)
title=match[0]
title=cleanTitle(title)
match=re.compile("episodenumber:'(.+?)'", re.DOTALL).findall(entry)
episode=match[0]
nr="S"+episode[0:2]+"E"+episode[2:4]
match=re.compile("description:'(.+?)'", re.DOTALL).findall(entry)
desc=match[0]
match=re.compile("url:'(.+?)'", re.DOTALL).findall(entry)
url=match[0]
match=re.compile("thumbnail:'(.+?)'", re.DOTALL).findall(entry)
thumb=match[0]
thumb=thumb[:thumb.find("?")]
addLink(nr+" - "+title,url,'playVideo',thumb,desc)
xbmcplugin.endOfDirectory(pluginhandle)
if forceViewMode==True:
xbmc.executebuiltin('Container.SetViewMode('+viewMode+')')
def playVideo(url):
content = getUrl(url)
matchTitle=re.compile('<h1 itemprop="name">(.+?)</h1>', re.DOTALL).findall(content)
matchDesc=re.compile('<h2 itemprop="description">(.+?)</h2>', re.DOTALL).findall(content)
matchSE=re.compile('/s(.+?)e(.+?)-', re.DOTALL).findall(content)
match=re.compile('http://media.mtvnservices.com/mgid:arc:episode:southpark.de:(.+?)"', re.DOTALL).findall(content)
if len(match)>0:
content = getUrl("http://www.southpark.de/feeds/video-player/mrss/mgid%3Aarc%3Aepisode%3Asouthpark.de%3A"+match[0]+"?lang="+language)
spl=content.split('<item>')
urlFull="stack://"
start=2
if playIntro=="true":
start=1
for i in range(start,len(spl),1):
entry=spl[i]
match=re.compile('<media:content type="text/xml" medium="video" duration="(.+?)" isDefault="true" url="(.+?)"', re.DOTALL).findall(entry)
url=match[0][1].replace("&","&")
content = getUrl(url)
matchMp4=re.compile('width="(.+?)" height="(.+?)" type="video/mp4" bitrate="(.+?)">(.+?)<src>(.+?)</src>', re.DOTALL).findall(content)
matchFlv=re.compile('width="(.+?)" height="(.+?)" type="video/x-flv" bitrate="(.+?)">(.+?)<src>(.+?)</src>', re.DOTALL).findall(content)
urlNew=""
bitrate=0
if len(matchMp4)>0:
match=matchMp4
elif len(matchFlv)>0:
match=matchFlv
for temp1,temp2,br,temp3,url in match:
if int(br)>bitrate:
bitrate=int(br)
urlNew=url
if urlNew.find("/mtvnorigin/")>=0:
urlNew="http://mtvni.rd.llnwd.net/44620"+urlNew[urlNew.find("/mtvnorigin/"):]
elif urlNew.find("/mtviestor/")>=0:
urlNew="http://mtvni.rd.llnwd.net/44620/cdnorigin"+urlNew[urlNew.find("/mtviestor/"):]
urlFull+=urlNew+" , "
urlFull=urlFull[:-3]
listitem = xbmcgui.ListItem(path=urlFull)
title="S"+matchSE[0][0]+"E"+matchSE[0][1]+" - "+matchTitle[0]
desc=matchDesc[0]
listitem.setInfo( type="Video", infoLabels={ "Title": title , "Plot": desc } )
return xbmcplugin.setResolvedUrl(pluginhandle, True, listitem)
else:
xbmc.executebuiltin('XBMC.Notification(Info:,'+str(translation(30004))+'!,5000)')
def cleanTitle(title):
title=title.replace("<","<").replace(">",">").replace("&","&").replace("'","\\").replace(""","\"").replace("ß","ß").replace("–","-")
title=title.replace("Ä","Ä").replace("Ü","Ü").replace("Ö","Ö").replace("ä","ä").replace("ü","ü").replace("ö","ö")
title=title.replace("\\'","'").strip()
return title
def getUrl(url):
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0')
response = urllib2.urlopen(req)
link=response.read()
response.close()
return link
def parameters_string_to_dict(parameters):
''' Convert parameters encoded in a URL to a dict. '''
paramDict = {}
if parameters:
paramPairs = parameters[1:].split("&")
for paramsPair in paramPairs:
paramSplits = paramsPair.split('=')
if (len(paramSplits)) == 2:
paramDict[paramSplits[0]] = paramSplits[1]
return paramDict
def addLink(name,url,mode,iconimage,desc):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name , "Plot": desc } )
liz.setProperty('IsPlayable', 'true')
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz)
return ok
def addDir(name,url,mode,iconimage):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
params=parameters_string_to_dict(sys.argv[2])
mode=params.get('mode')
url=params.get('url')
if type(url)==type(str()):
url=urllib.unquote_plus(url)
if mode == 'listVideos':
listVideos(url)
elif mode == 'sortDirection':
sortDirection(url)
elif mode == 'playVideo':
playVideo(url)
elif mode == 'search':
search()
elif mode == 'playRandom':
playRandom()
else:
index()