import re import urllib from lib import jsunpack import sys from lib.net import Net MAX_TRIES = 5 class YouWatchResolver(object): name = "youwatch" domains = ["youwatch.org", "chouhaa.info", "ay8ou8ohth.com"] pattern = '(?://|\.)(youwatch\.org|chouhaa\.info|ay8ou8ohth\.com)/(?:embed-)?([A-Za-z0-9]+)' def __init__(self): self.net = Net() url = str(sys.argv[1]) host = self.get_host_and_id(url)[0] media_id = self.get_host_and_id(url)[1] return self.get_media_url(host, media_id) def get_host_and_id(self, url): r = re.search(self.pattern, url, re.I) if r: return r.groups() else: return False def get_media_url(self, host, media_id): web_url = self.get_url(host, media_id) web_url = self.net.http_GET(web_url)._response.url headers = {'Referer': web_url} tries = 0 while tries < MAX_TRIES: html = self.net.http_GET(web_url).content html = html.replace('\n', '') r = re.search('