[39052] | 1 | |
---|
| 2 | import re |
---|
| 3 | import urllib |
---|
| 4 | from lib import jsunpack |
---|
| 5 | import sys |
---|
| 6 | from lib.net import Net |
---|
| 7 | |
---|
| 8 | MAX_TRIES = 5 |
---|
| 9 | |
---|
| 10 | class YouWatchResolver(object): |
---|
| 11 | name = "youwatch" |
---|
[39652] | 12 | domains = ["youwatch.org", "chouhaa.info", "ay8ou8ohth.com"] |
---|
| 13 | pattern = '(?://|\.)(youwatch\.org|chouhaa\.info|ay8ou8ohth\.com)/(?:embed-)?([A-Za-z0-9]+)' |
---|
[39052] | 14 | |
---|
| 15 | def __init__(self): |
---|
| 16 | self.net = Net() |
---|
| 17 | url = str(sys.argv[1]) |
---|
| 18 | host = self.get_host_and_id(url)[0] |
---|
| 19 | media_id = self.get_host_and_id(url)[1] |
---|
| 20 | |
---|
| 21 | return self.get_media_url(host, media_id) |
---|
| 22 | |
---|
| 23 | def get_host_and_id(self, url): |
---|
| 24 | r = re.search(self.pattern, url, re.I) |
---|
| 25 | if r: |
---|
| 26 | return r.groups() |
---|
| 27 | else: |
---|
| 28 | return False |
---|
| 29 | |
---|
| 30 | def get_media_url(self, host, media_id): |
---|
| 31 | web_url = self.get_url(host, media_id) |
---|
| 32 | web_url = self.net.http_GET(web_url)._response.url |
---|
| 33 | headers = {'Referer': web_url} |
---|
| 34 | |
---|
| 35 | tries = 0 |
---|
| 36 | while tries < MAX_TRIES: |
---|
| 37 | html = self.net.http_GET(web_url).content |
---|
| 38 | html = html.replace('\n', '') |
---|
| 39 | r = re.search('<iframe\s+src\s*=\s*"([^"]+)', html) |
---|
| 40 | if r: |
---|
| 41 | web_url = r.group(1) |
---|
| 42 | else: |
---|
| 43 | break |
---|
| 44 | tries += 1 |
---|
| 45 | |
---|
| 46 | html = self.net.http_GET(web_url, headers=headers).content |
---|
| 47 | r = re.search('file\s*:\s*"([^"]+)', html) |
---|
| 48 | if r: |
---|
| 49 | print r.group(1) + '|' + urllib.urlencode({'Referer': web_url}) |
---|
| 50 | |
---|
| 51 | def get_url(self, host, media_id): |
---|
| 52 | return 'http://youwatch.org/embed-%s.html' % media_id |
---|
| 53 | |
---|
| 54 | sys.stdout = YouWatchResolver() |
---|