forked from dethfeet/plugin.video.tele5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.py
146 lines (121 loc) · 5.01 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
import xbmcplugin
import xbmcgui
import sys
import urllib, urllib2
import re
import httplib
from pyamf import AMF0, AMF3
from pyamf import remoting
from pyamf.remoting.client import RemotingService
import urlresolver
import json
thisPlugin = int(sys.argv[1])
baseUrl = "http://www.tele5.de/play"
def mainPage():
page = load_page(baseUrl)
_regex_extractShows = re.compile("<table class=\"play hidden\">(.*?)</table>", re.DOTALL)
shows = _regex_extractShows.search(page).group(1)
_regex_extractShow = re.compile("<li>.*?href=\"(.*?)\".*?src=\"(.*?)\".*?<span>(.*?)</span>",re.DOTALL)
for show in _regex_extractShow.finditer(shows):
img = baseUrl+'/../'+show.group(2)
title = unicode(show.group(3).replace("\n"," "), "latin-1")
addDirectoryItem(title, parameters={"action":"show", "link":show.group(1)}, pic=img, folder=True)
xbmcplugin.endOfDirectory(thisPlugin)
def showPage(link):
link = urllib.unquote(link)
css_class = urllib.unquote(link)[1:]
page = load_page(baseUrl+'/../'+link)
_regex_extractEpisodes = re.compile("<table class=\""+css_class+" hidden\">(.*?)</table>", re.DOTALL)
episodes = _regex_extractEpisodes.search(page).group(1)
_regex_extractEpisode = re.compile("<li>.*?href=\"(.*?)\".*?src=\"(.*?)\".*?alt=\"(.*?)\"",re.DOTALL)
for episode in _regex_extractEpisode.finditer(episodes):
img = baseUrl+'/../'+episode.group(2)
title = episode.group(3).replace("\n"," ")
addDirectoryItem(title, parameters={"action":"episode", "link":episode.group(1)}, pic=img, folder=False)
xbmcplugin.endOfDirectory(thisPlugin)
def episodePage(link):
link = urllib.unquote(link)
episode = link[1:]
clip_info = get_clip_info(episode)
try:
filename = clip_info[0]['filename']
stream_url = clip_info[0]['path']
item = xbmcgui.ListItem(path=stream_url)
item.setProperty('PlayPath', filename);
except KeyError:
if clip_info[0]['path'] == "/":
#YouTube oder Soundcloud
_regexExtractIframe = re.compile("<iframe .*?src=\"(.*?)\".*?></iframe>")
iframe_src = _regexExtractIframe.search(clip_info[0]['quelle']).group(1)
if iframe_src.find('soundcloud'):
#Soundcloud
_regexExtractSoundcloudId = re.compile("tracks%2F(.*?)&")
soundcloudId = _regexExtractSoundcloudId.search(iframe_src).group(1)
soundcloudPage = load_page("https://api.soundcloud.com/i1/tracks/"+soundcloudId+"/streams?client_id=0f8fdbbaa21a9bd18210986a7dc2d72c&format=json")
soundcloudJson = json.loads(soundcloudPage)
stream_url = soundcloudJson['http_mp3_128_url']
else:
#YouTube
stream_url = urlresolver.resolve(iframe_src)
else:
stream_url = baseUrl+"/../"+clip_info[0]['path']
item = xbmcgui.ListItem(path=stream_url)
xbmcplugin.setResolvedUrl(thisPlugin, True, item)
return False
def load_page(url):
print url
req = urllib2.Request(url)
response = urllib2.urlopen(req)
link = response.read()
response.close()
return link
def addDirectoryItem(name, parameters={}, pic="", folder=True):
li = xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=pic)
if not folder:
li.setProperty('IsPlayable', 'true')
url = sys.argv[0] + '?' + urllib.urlencode(parameters)
return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=li, isFolder=folder)
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 build_amf_request(clip_name):
env = remoting.Envelope(amfVersion=3)
env.bodies.append(
(
"/1",
remoting.Request(
target="tele5.getContentPlayer",
body=[clip_name],
envelope=env
)
)
)
return env
def get_clip_info(clip_name):
conn = httplib.HTTPConnection("www.tele5.de")
envelope = build_amf_request(clip_name)
conn.request("POST", "/gateway/gateway.php", str(remoting.encode(envelope).read()), {'content-type': 'application/x-amf'})
response = conn.getresponse().read()
response = remoting.decode(response).bodies[0][1].body
return response
if not sys.argv[2]:
mainPage()
else:
params = get_params()
if params['action'] == "show":
showPage(params['link'])
if params['action'] == "episode":
episodePage(params['link'])