[39052] | 1 | |
---|
| 2 | import re |
---|
| 3 | import urllib |
---|
| 4 | from lib import jsunpack |
---|
| 5 | import sys |
---|
| 6 | from lib.net import Net |
---|
| 7 | |
---|
| 8 | class VidziResolver(object): |
---|
| 9 | name = "vidzi" |
---|
| 10 | domains = ["vidzi.tv"] |
---|
| 11 | pattern = '(?://|\.)(vidzi\.tv)/(?:embed-)?([0-9a-zA-Z]+)' |
---|
| 12 | |
---|
| 13 | def __init__(self): |
---|
| 14 | self.net = Net() |
---|
| 15 | url = str(sys.argv[1]) |
---|
| 16 | host = self.get_host_and_id(url)[0] |
---|
| 17 | media_id = self.get_host_and_id(url)[1] |
---|
| 18 | |
---|
| 19 | return self.get_media_url(host, media_id) |
---|
| 20 | |
---|
| 21 | def get_host_and_id(self, url): |
---|
| 22 | r = re.search(self.pattern, url, re.I) |
---|
| 23 | if r: |
---|
| 24 | return r.groups() |
---|
| 25 | else: |
---|
| 26 | return False |
---|
| 27 | |
---|
| 28 | def get_media_url(self, host, media_id): |
---|
| 29 | web_url = self.get_url(host, media_id) |
---|
| 30 | html = self.net.http_GET(web_url).content |
---|
| 31 | |
---|
| 32 | if '404 Not Found' in html: |
---|
| 33 | print 'File Not Found or removed' |
---|
| 34 | |
---|
| 35 | r = re.search('file\s*:\s*"([^"]+)', html) |
---|
| 36 | if r: |
---|
| 37 | return r.group(1) + '|' + urllib.urlencode({'Referer': 'http://vidzi.tv/nplayer/jwplayer.flash.swf'}) |
---|
| 38 | else: |
---|
| 39 | for match in re.finditer('(eval\(function.*?)</script>', html, re.DOTALL): |
---|
| 40 | js_data = jsunpack.unpack(match.group(1)) |
---|
| 41 | r = re.search('file\s*:\s*"([^"]+)', js_data) |
---|
| 42 | if r: |
---|
| 43 | print r.group(1) |
---|
| 44 | |
---|
[39354] | 45 | # print 'Unable to locate link' |
---|
[39052] | 46 | |
---|
| 47 | def get_url(self, host, media_id): |
---|
| 48 | return 'http://%s/embed-%s.html' % (host, media_id) |
---|
| 49 | |
---|
| 50 | sys.stdout = VidziResolver() |
---|