-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathvid.cgi
executable file
·464 lines (418 loc) · 15.4 KB
/
vid.cgi
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
#!/usr/bin/python
import cgitb #; cgitb.enable() # for debugging
import cgi # for getting query keys/values
from urllib import unquote
from json import dumps, loads
from sites.Web import Web
web = Web()
def main():
keys = get_keys()
if 'url' in keys:
get_video_url(keys['url'])
elif 'download' in keys:
get_download(keys['download'])
else:
print_error("expected 'url' or 'download' not found")
def get_video_url(siteurl):
url = get_url(siteurl)
meta = web.get_meta(url)
if not 'Content-Type' in meta or ('video' not in meta['Content-Type'].lower() and 'application/octet-stream' not in meta['Content-Type'].lower()):
print_error('no video content at %s' % url)
return
typ = meta['Content-Type']
if '/' in typ: typ = typ[typ.find('/')+1:]
siz = ''
if 'Content-Length' in meta:
length = int(meta['Content-Length'])
siz = get_size(length)
print dumps( {
'url' : url,
'type' : typ,
'size' : siz,
})
def get_url(siteurl):
is_supported(siteurl)
sites = {
'videobam.com/' : { 'begend' : ['"', '"'], 'unquote' : 1 },
'xhamster.com/' : { 'begend' : ['"', '"'], 'unquote' : 1 },
'videarn.com/' : { 'begend' : ["src='", "'"], 'unquote' : 1 },
'youporn.com/' : { 'begend' : ['href="', '&'], 'unquote' : 1 },
'redtube.com/' : { 'begend' : ['&flv_url=', '&'], 'unquote' : 1 },
'vine.co/' : { 'begend' : ['source src="', '"'], 'unquote' : 1 },
}
if 'beeg.com' in siteurl: return get_site_beeg(siteurl)
if 'xvideos.com/' in siteurl: return get_site_xvideos(siteurl)
if 'fapmenow.com/' in siteurl: return get_site_fapmenow(siteurl)
if 'vimeo.com/' in siteurl: return get_site_vimeo(siteurl)
if 'tumblr.com/' in siteurl: return get_site_tumblr(siteurl)
if '4tube.com/' in siteurl: return get_site_4tube(siteurl)
if 'xtube.com' in siteurl: return get_site_xtube(siteurl)
if 'youjizz.com' in siteurl: return get_site_youjizz(siteurl)
if 'dailymotion.com' in siteurl: return get_site_dailymotion(siteurl)
if 'mobypicture.com' in siteurl: return get_site_mobypicture(siteurl)
if 'sexykarma.com' in siteurl: return get_site_sexykarma(siteurl)
if 'fapjacks.com' in siteurl: return get_site_fapjacks(siteurl)
if 'setsdb.org' in siteurl: return get_site_setsdb(siteurl)
if 'ashemaletube.com' in siteurl: return get_site_ast(siteurl)
if 'spankbang.com' in siteurl: return get_site_spankbang(siteurl)
if 'fapdu.com' in siteurl: return get_site_fapdu(siteurl)
if 'pornably.com' in siteurl: return get_site_pornably(siteurl)
if 'vporn.com' in siteurl: return get_site_vporn(siteurl)
if 'pornhub.com' in siteurl: return get_site_pornhub(siteurl)
if 'tube8.com' in siteurl: return get_site_tube8(siteurl)
if 'drtuber.com' in siteurl: return get_site_drtuber(siteurl)
if 'vk.com/video' in siteurl: return get_site_vk(siteurl)
if 'motherless.com' in siteurl: return get_site_motherless(siteurl)
if 'seenive.com' in siteurl: return get_site_seenive(siteurl)
if 'cliphunter.com' in siteurl: return get_site_cliphunter(siteurl)
if 'spankwire.com' in siteurl: return get_site_spankwire(siteurl)
if 'kinkylicious.com' in siteurl: return get_site_kinkylicious(siteurl)
site_key = None
for key in sites.keys():
if key in siteurl:
supported = True
site_key = key
if site_key == None:
raise Exception('site not supported, <a href="http://www.reddit.com/message/compose/?to=4_pr0n&subject=rip.rarchives.com&message=Support%%20this%%20video%%20site:%%20`%s`">ask 4_pr0n to support it</a>' % siteurl)
source = web.getter(siteurl)
ext_inds = get_extension_indexes(source)
index = get_deepest_ind(source, ext_inds)
url = between(source, index, sites[key]['begend'][0], sites[key]['begend'][1])
url = url.replace('\\/', '/')
while sites[site_key]['unquote'] > 0 and '%' in url:
sites[site_key]['unquote'] -= 1
url = unquote(url)
return url
def get_site_beeg(siteurl):
r = web.get(siteurl)
if not "'file': '" in r:
raise Exception('could not find file: at %s' % siteurl)
u = web.between(r, "'file': '", "'")[0]
return u
def get_site_xvideos(siteurl):
r = web.get(siteurl)
u = web.between(r, 'flv_url=', '&')[0]
u = unquote(u)
return u
def get_site_fapmenow(siteurl):
r = web.getter(siteurl)
if not '"video_src" href="' in r:
raise Exception('could not find video_src at %s' % siteurl)
return web.between(r, '"video_src" href="', '"')[0]
def get_site_vimeo(siteurl):
r = web.getter(siteurl)
if not "window.addEvent('domready'" in r:
raise Exception('could not find domready at %s' % siteurl)
chunk = web.between(r, "window.addEvent('domready'", 'window.addEvent(')[0]
ts = web.between(chunk, '"timestamp":', ',')[0]
sig = web.between(chunk, '"signature":"', '"')[0]
vid = web.between(chunk, '"video":{"id":', ',')[0]
url = 'http://player.vimeo.com/play_redirect'
url += '?clip_id=%s' % vid
url += '&sig=%s' % sig
url += '&time=%s' % ts
url += '&quality=hd&codecs=H264,VP8,VP6&type=moogaloop_local&embed_location=&seek=0'
return url
def get_site_tumblr(siteurl):
r = web.getter(siteurl)
if not 'source src=\\x22' in r:
raise Exception('could not find source src at %s' % siteurl)
url = web.between(r, 'source src=\\x22', '\\x22')[0]
return url
def get_site_4tube(siteurl):
r = web.getter(siteurl)
if "playerFallbackFile = '" in r:
return unquote(web.between(r, "playerFallbackFile = '", "'")[0])
elif 'sources: [{"file":"' in r:
return web.between(r, 'sources: [{"file":"', '"')[0].replace('\\/', '/')
else:
raise Exception('could not find sources-file or playerFallbackFile at %s' % siteurl)
def get_site_xtube(siteurl):
r = web.getter(siteurl)
if 'videoMp4 = "' in r:
return web.between(r, 'videoMp4 = "', '"')[0].replace('\\/', '/')
raise Exception('could not find videoMp4 at %s' % siteurl)
def get_site_youjizz(siteurl):
u = siteurl
if '?' in u: u = u[:u.find('?')]
if '#' in u: u = u[:u.find('#')]
if not u.endswith('.html'):
raise Exception('could not find .html in %s' % siteurl)
num = u[u.rfind('-')+1:u.rfind('.html')]
if not num.isdigit():
raise Exception('video id not numeric at %s' % siteurl)
u = 'http://www.youjizz.com/videos/embed/%s' % num
r = web.getter(u)
if not 'encodeURIComponent("' in r:
raise Exception('could not find encodeURIComponent at %s' % u)
return web.between(r, 'encodeURIComponent("', '"')[0]
def get_site_dailymotion(siteurl):
back = siteurl[siteurl.find('dailymotion.com')+len('dailymotion.com'):]
u = 'http://www.dailymotion.com/family_filter?enable=false&urlback=%s' % back
r = web.get(u, headers={'family_filter' : 'off', 'masscast' : 'null'} )
if not '<meta name="twitter:player" value="' in r:
raise Exception('unable to find embed at %s' % u)
embed = web.between(r, '<meta name="twitter:player" value="', '"')[0]
r = web.get(embed)
if not 'var info = ' in r:
raise Exception('unable to find var info at %s' % embed)
chunk = web.between(r, 'var info = ', 'fields = ')[0].strip()
while chunk.endswith(','): chunk = chunk[:-1]
json = loads(chunk)
video = None
for key in ['stream_h264_hd1080_url','stream_h264_hd_url', 'stream_h264_hq_url','stream_h264_url', 'stream_h264_ld_url']:
if key in json and json[key] != None:
video = json[key]
break
if video == None:
raise Exception('unable to find stream at %s' % embed)
return video
def get_site_mobypicture(siteurl):
r = web.get(siteurl)
fs = web.between(r, 'file: "', '"')
if len(fs) == 0:
raise Exception('could not find file: at %s' % siteurl)
return fs[0]
def get_site_sexykarma(siteurl):
r = web.get(siteurl)
fs = web.between(r, "playlist = [ { url: escape('", "'")
if len(fs) == 0:
raise Exception('could not find playlist=[{url:escape( at %s' % siteurl)
return fs[0]
def get_site_fapjacks(siteurl):
r = web.get(siteurl)
fs = web.between(r, 'type="video/mp4" src="', '"')
if len(fs) == 0:
raise Exception('could not find type=video/mp4 at %s' % siteurl)
return fs[0]
def get_site_setsdb(siteurl):
r = web.get(siteurl)
if not '<iframe src="' in r:
raise Exception('could not find iframe at %s' % siteurl)
embed = web.between(r, '<iframe src="', '"')[0]
embed = embed.replace('&', '&')
r = web.get(embed)
hds = ['amp;url720=', 'amp;url=480', 'amp;url=360', 'amp;url=240']
for hd in hds:
if hd in r:
url = web.between(r, hd, '&')[0]
return url
raise Exception('could not find video at %s' % embed)
def get_site_ast(siteurl):
r = web.get(siteurl)
if not "'file': \"" in r:
raise Exception('could not find file: at %s' % siteurl)
return web.between(r, "'file': \"", '"')[0]
def get_site_spankbang(siteurl):
r = web.get(siteurl)
if not 'jwplayer("video_container")' in r:
raise Exception('could not find video_container at %s' % siteurl)
chunks = web.between(r, 'jwplayer("video_container")', '});')
url = ''
for chunk in chunks:
if not 'file: "' in chunk: continue
url = web.between(chunk, 'file: "', '"')[0]
url = 'http://spankbang.com%s' % url
if url == '':
raise Exception('unable to find file: at %s' % siteurl)
return url
def get_site_fapdu(siteurl):
r = web.get(siteurl)
if not '"file" : "' in r:
raise Exception('could not find file: at %s' % siteurl)
f = web.between(r, '"file" : "', '"')[0]
return f
def get_site_pornably(siteurl):
r = web.get(siteurl)
if not 'preload="metadata" src="' in r:
raise Exception('could not find metadata src at %s' % siteurl)
f = web.between(r, 'preload="metadata" src="', '"')[0]
return f
def get_site_vporn(siteurl):
r = web.get(siteurl)
if 'flashvars.videoUrlHD = "' in r:
f = web.between(r, 'flashvars.videoUrlHD = "', '"')[0]
elif 'videoUrlLow = "' in r:
f = web.between(r, 'videoUrlLow = "', '"')[0]
else:
raise Exception('could not find videourlhd at %s' % siteurl)
return f
def get_site_pornhub(siteurl):
r = web.get(siteurl)
import sites.aes as aes
if 'video_title":"' in r:
title = web.between(r, 'video_title":"', '"')[0]
else:
raise Exception('could not find videourlhd at %s' % siteurl)
if 'quality_480p":"' in r:
v = web.between(r, 'quality_480p":"', '"')[0]
else:
raise Exception('could not find videourlhd at %s' % siteurl)
import urllib2
v = urllib2.unquote(v)
f = aes.decrypt(v, title.replace("+", " "), 256)
return f
def get_site_tube8(siteurl):
r = web.get(siteurl)
import sites.aes as aes
if 'video_title":"' in r:
title = web.between(r, 'video_title":"', '"')[0]
else:
raise Exception('could not find video title at %s' % siteurl)
if 'video_url":"' in r:
v = web.between(r, 'video_url":"', '"')[0]
else:
raise Exception('could not find video url at %s' % siteurl)
import urllib2
v = urllib2.unquote(v) # probably not needed
return aes.decrypt(v, title, 256)
def get_site_drtuber(siteurl):
r = web.get(siteurl)
import re
r = re.sub(r"' \+ '",'',r) # this breaks easiest
a = "".join(re.findall(r'params \+= \'(.*?)\'',r))
v = a.split('=')[-1]
import hashlib
m = hashlib.md5()
m.update(v+'PT6l13umqV8K827')
a = a+"&pkey="+m.hexdigest()
import urllib2
v = urllib2.unquote(a)
r = web.get("http://www.drtuber.com/player/config.php?"+v)
# to be safe probably should use unquote
return web.between(r, '<video_file>', '</video_file>')[0].replace('&', '&')
def get_site_vk(siteurl):
r = web.get(siteurl)
highest_res = None
for size in ['720', '480', '360', '240']:
if '\\"url%s\\":\\"' % size in r:
highest_res = web.between(r, '\\"url%s\\":\\"' % size, '\\"')[0]
if highest_res == None:
raise Exception('could not find video link url<res>:')
return highest_res.replace('\\/', '/').replace('\\\\', '')
def get_site_motherless(siteurl):
r = web.get(siteurl)
if not "__fileurl = '" in r:
raise Exception('could not find __fileurl= at ' % siteurl)
return web.between(r, "__fileurl = '", "'")[0]
def get_site_seenive(siteurl):
r = web.get(siteurl)
if not 'source src="' in r:
raise Exception('could not find source src= at %s' % siteurl)
return web.between(r, 'source src="', '"')[0]
def cliphunt_decrypt(txt):
d = {'$': ':', '&': '.', '(': '=', '-': '-',
'_': '_', '^': '&', 'a': 'h', 'c': 'c',
'b': 'b', 'e': 'v', 'd': 'e', 'g': 'f',
'f': 'o', 'i': 'd', 'm': 'a', 'l': 'n',
'n': 'm', 'q': 't', 'p': 'u', 'r': 's',
'w': 'w', 'v': 'p', 'y': 'l', 'x': 'r',
'z': 'i', '=': '/', '?': '?' }
result = ''
for i in txt:
if i.isdigit():
result += i
elif txt[i] in d:
result += d[i]
else:
raise Exception('do not have decryption for %s' % i)
return result
def get_site_cliphunter(siteurl):
if 'm.cliphunter.com' in siteurl:
siteurl = siteurl.replace('m.cliphunter.com', 'cliphunter.com')
r = web.get(siteurl)
if not "var flashVars = {d: '" in r:
raise Exception('could not find flashVars at %s' % siteurl)
chunk = loads(web.between(r, "var flashVars = {d: '", "'")[0].decode('base64'))
if not 'url' in chunk:
raise Exception('could not find url in chunk: %s' % chunk)
url = loads(chunk['url'].decode('base64'))
if not 'u' in url:
raise Exception('could not find "u" in "url": %s' % url)
u = url['u']
if not 'l' in u:
raise Exception('could not find "l" in "u": %s' % u)
return cliphunt_decrypt(u['l'])
def get_site_spankwire(siteurl):
r = web.get(siteurl)
vid = None
for qual in ['720', '480', '320', '240', '180']:
if 'flashvars.quality_%sp = "' % qual in r:
vid = web.between(r, 'flashvars.quality_%sp = "' % qual, '"')[0]
if vid != '': break
if vid == None:
raise Exception('could not find flashvars.quality_XXXp at %s' % siteurl)
return unquote(vid)
def get_site_kinkylicious(siteurl):
vid = None
if '/video/' in siteurl:
vid = siteurl[siteurl.find('/video/')+len('/video/'):]
if '/' in vid: vid = vid[:vid.find('/')]
if '?' in vid: vid = vid[:vid.find('?')]
if '#' in vid: vid = vid[:vid.find('#')]
else:
r = web.get(siteurl)
if 'var video_id = "' in r:
vid = web.between(r, 'var video_id = "', '"')[0]
elif "so.addVariable('videoid','" in r:
vid = web.between(r, "so.addVariable('videoid','", "'")[0]
if vid == None:
raise Exception('unable to determine video id at %s' % siteurl)
return 'http://kinkylicious.com/vdata/%s.flv' % vid
def is_supported(url):
for not_supported in ['youtube.com/']:
if not_supported in url:
raise Exception('%s is not supported' % not_supported)
def get_deepest_ind(source, ext_inds):
deep_ind = 0
for (ext, ind) in ext_inds:
if ind > deep_ind:
extension = ext
deep_ind = ind
return deep_ind
def between(text, i, before, after):
start = text.rfind(before, 0, i)
end = text.find(after, i)
if start == -1 or end == -1:
raise Exception('could not find begin=%s end=%s around %s' % (before, after, text))
return text[start+len(before):end]
""" Returns human-readable filesize for file """
def get_size(byt):
b = 1024 * 1024 * 1024
a = ['g','m','k','']
for i in a:
if byt >= b:
return '%.2f%sb' % (float(byt) / float(b), i)
b /= 1024
return '0b'
def get_extension_indexes(source):
extensions = ['.mp4', '.flv']
result = []
for ext in extensions:
index = -1
while True:
index = source.lower().find(ext.lower(), index + 1)
if index == -1:
break
result.append( (ext, index) )
if result == []:
raise Exception("mp4 or flv video not found")
return result
""" Retrieves key/value pairs from query, puts in dict """
def get_keys():
form = cgi.FieldStorage()
keys = {}
for key in form.keys():
keys[key] = form[key].value
return keys
""" Print error in JSON format """
def print_error(text):
print dumps( { 'error' : text } )
if __name__ == '__main__':
print "Content-Type: application/json"
print ""
try:
main()
except Exception, e:
print_error(str(e))
print "\n"