source: titan/mediathek/localhoster/youwatch.py @ 40041

Last change on this file since 40041 was 39652, checked in by obi, 7 years ago

fix youwatch

File size: 1.5 KB
Line 
1
2import re
3import urllib
4from lib import jsunpack
5import sys
6from lib.net import Net
7
8MAX_TRIES = 5
9
10class YouWatchResolver(object):
11    name = "youwatch"
12    domains = ["youwatch.org", "chouhaa.info", "ay8ou8ohth.com"]
13    pattern = '(?://|\.)(youwatch\.org|chouhaa\.info|ay8ou8ohth\.com)/(?:embed-)?([A-Za-z0-9]+)'
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
54sys.stdout = YouWatchResolver()
Note: See TracBrowser for help on using the repository browser.