forked from daniel-lundin/dreamfilm-xbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolvers.py
254 lines (197 loc) · 8.38 KB
/
resolvers.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import urllib
import urllib2
import json
import HTMLParser
import re
import binascii
from vendor import packer
def vk_streams(html):
""" Finds streams for vk.com player """
start = html.index('<embed')
end = html.index('>', start + 1)
embed_tag = html[start:end]
fv_idx = embed_tag.index('flashvars')
flashvars = embed_tag[fv_idx + 10:-1]
params = flashvars.split('&')
formats = []
for param in params:
parts = param.split('=')
key = parts[0]
value = parts[1]
if key.startswith('url'):
if '?' in value:
value = value[0:value.find('?')]
formats.append((key, value))
return formats
def google_streams(html):
""" Finds streams for docs.google.com player """
FLASHVARS_START = 'flashVars":{'
start = html.find(FLASHVARS_START) + len(FLASHVARS_START)
end = html.find('}', start)
flashvars = html[start:end]
d = flashvars.decode('unicode-escape')
decoded = urllib2.unquote(urllib2.unquote(d))
urls = [l for l in decoded.split('url=') if 'mp4' in l and l.startswith('https')]
streams = []
for u in urls:
q = 'quality='
quality = u[u.find(q) + len(q): u.find(',', u.find(q))]
streams.append((quality, u[:-1]))
return streams
def leanback_streams(html):
SOURCE_START = "source src=\""
start = html.find(SOURCE_START) + len(SOURCE_START)
end = html.find('"', start + 1)
return [('', html[start:end])]
def mailru_streams(url):
req = urllib2.Request(url)
resp = urllib2.urlopen(req)
html = resp.read()
cookie_string = resp.headers.getheader('Set-Cookie').split(';')[0]
headers = {
'Cookie': cookie_string
}
metadata_url_start = html.find('metadataUrl') + len('metadataUrl":"')
metadata_url_end = html.find('"', metadata_url_start)
metadata_url = html[metadata_url_start:metadata_url_end]
metadata_response = urllib2.urlopen(metadata_url)
metadata = json.loads(metadata_response.read())
# XBMC player needs cookies to play these
xbmc_cookies = '|Cookie=' + urllib.quote(cookie_string)
streams = [(v['key'], v['url'] + xbmc_cookies) for v in metadata['videos']]
return streams
def _okru_to_res(string):
string = string.strip()
resolution = string
if string == 'full':
resolution = '1080p'
elif string == 'hd':
resolution = '720p'
elif string == 'sd':
resolution = '480p'
elif string == 'low':
resolution = '360p'
elif string == 'lowest':
resolution = '240p'
elif string == 'mobile':
resolution = '144p'
return resolution
def okru_streams(url):
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
}
id = re.search('\d+', url).group(0)
json_url = 'http://ok.ru/dk?cmd=videoPlayerMetadata&mid=' + id
req = urllib2.Request(json_url, headers=HEADERS)
response = urllib2.urlopen(req)
source = response.read()
response.close()
json_source = json.loads(source)
sources = []
for source in json_source['videos']:
name = _okru_to_res(source['name'])
link = '%s|User-Agent=%s&Accept=%s'
link = link % (source['url'], HEADERS['User-Agent'], HEADERS['Accept'])
item = (name, link)
sources.append(item)
return sources
def vkpass_streams(url, recursive_call=False):
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Referer': 'http://www.dreamfilmhd.org/API/api.php'
}
req = urllib2.Request(url, headers=HEADERS)
response = urllib2.urlopen(req)
html = response.read()
response.close()
return _vkpass_streams_from_html(html, recursive_call)
def _extract_packed_videourls(html):
eval_start = html.find('eval(function(p,a,c,k,e')
eval_end = html.find('</script>', eval_start)
packed_script = html[eval_start : eval_end]
unpacked_script = packer.unpack(packed_script)
return _extract_source_tags(unpacked_script, single_quotes=False)
def _extract_source_tags(html, single_quotes=True):
source_tags = re.findall(r'(<source.*?\/>)', html)
if source_tags:
streams = []
for source_tag in source_tags:
if single_quotes:
match = re.search(r"src='(.*?)'.*?label='(.*?)'", source_tag)
else:
match = re.search(r'src="(.*?)".*?label="(.*?)"', source_tag)
if match:
streams.append((match.group(2), match.group(1)))
return streams
def _vkpass_streams_from_html(html, recursive_call):
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
}
# Look for p,a,c,k,e,d js files
if html.find('eval(function(p,a,c,k,e') != -1:
return _extract_packed_videourls(html);
# Look for video tag
source_tags = re.findall(r'(<source.*?\/>)', html)
if source_tags:
return _extract_source_tags(html)
identifier = "vsource=["
if identifier not in html:
binurl = re.search(r"src= \"javascript:decodeURIComponent\(escape\(window.atob\(\\'(?P<binurl>.*)\\'\)\)\)\"", html) #\(\\\'(?P<binurl>.*)\\\'\)\)', html)
if binurl:
url = binascii.a2b_base64(binurl.group('binurl'))
return _vkpass_streams_from_html(url, True)
# No match, try clear text decoding
redirect_url = re.search('src=\"(?P<url>.*?)\?', html)
if redirect_url and not recursive_call:
return vkpass_streams(redirect_url.group('url'), True)
else:
return None
vsource_start = html.index(identifier) + len(identifier) - 1
vsource_end = html.index("]", vsource_start + 1) + 1
file_start = html.find('file:', vsource_start)
formats = []
while file_start != -1 and file_start < vsource_end:
quote_start = file_start + 6
quote_end = html.find('"', quote_start + 1)
url = html[quote_start : quote_end]
label_start = html.find('label:', quote_end)
quote_start = label_start + 7
quote_end = html.find('"', quote_start + 1)
label = html[quote_start : quote_end]
link = '%s|User-Agent=%s&Accept=%s'
link = link % (url, HEADERS['User-Agent'], HEADERS['Accept'])
formats.append((label, link))
file_start = html.find('file:', quote_end)
return formats
def picasa_streams(url):
m = re.search('picasaweb.google.com/(?P<user>[^/]+)/(?P<album>[^?]+)\?authkey=(?P<authkey>[^#]+)#?(?P<photoid>[^?]+)?', url)
json_url = 'https://picasaweb.google.com/data/entry/base'
json_url += '/user/' + m.group('user')
json_url += '/album/' + m.group('album')
json_url += '/photoid/' + m.group('photoid')
json_url += '?alt=json'
json_url += '&authkey=' + m.group('authkey')
response = urllib2.urlopen(json_url)
data = json.load(response)
response.close()
sources = []
for l in data['entry']['media$group']['media$content']:
if l["type"].startswith("video"):
name = "{height}p".format(height=l["height"])
link = l["url"]
item = (name, link)
sources.append(item)
return sources
if __name__ == '__main__':
#print mailru_streams('http://videoapi.my.mail.ru/videos/embed/mail/mr.whoare/video/_myvideo/505.html')
#response = urllib2.urlopen("http://vkpass.com/token/bdrxwnlzfjpq/m123m/film/po-17915/watching.html?cap&c1_file=http://dreamvtt.com/srt/1/Poker.Night.2014.720p.BluRay.x264.YIFY.vtt&c1_label=English")
#html = response.read()
#print vkpass_streams(html)
#print okru_streams('http://www.ok.ru/video/30025452153')
#url = 'https://picasaweb.google.com/111770605384240810365/GameOfThronesS04?authkey=Gv1sRgCPLtx-O2nPmYFw#6151744529773049170'
url = 'https://picasaweb.google.com/105596503743456265443/Random?authkey=Gv1sRgCMaE9_Kn5b2L8QE'
url = 'http://vkpass.com/token/bdrxwnlzfjpq/vklhash/Pw7Iy8MztzzwN6xh7nOhf6o80rxCAYIhP8xiQFZ2fGXGWU7DkuzOqurGGBoJoMTvOUqd6XOGaWciR1FfSDFw7Q=='
print(vkpass_streams(url))