source: titan/mediathek/localhoster/thevideo.py @ 40134

Last change on this file since 40134 was 40035, checked in by obi, 7 years ago

[tithek] hoster fix thevideo

File size: 3.8 KB
Line 
1
2import re
3import json
4import urllib2
5import time
6from lib import helpers
7import sys
8from lib.net import Net
9import lib.common as common
10from lib import jsunpack
11
12INTERVALS = 5
13
14class TheVideoResolver(object):
15    name = "thevideo"
16    domains = ["thevideo.me"]
17    pattern = '(?://|\.)(thevideo\.me)/(?:embed-|download/)?([0-9a-zA-Z]+)'
18
19    def __init__(self):
20        self.net = Net()
21        self.headers = {'User-Agent': common.IE_USER_AGENT}
22        url = str(sys.argv[1])
23        host = self.get_host_and_id(url)[0]
24        media_id = self.get_host_and_id(url)[1]
25
26        return self.get_media_url(host, media_id)
27
28    def get_host_and_id(self, url):
29        r = re.search(self.pattern, url, re.I)
30        if r:
31            return r.groups()
32        else:
33            return False
34
35    def get_media_url(self, host, media_id):
36        web_url = self.get_url(host, media_id)
37        headers = {
38            'Referer': web_url
39        }
40        headers.update(self.headers)
41        headers = {'User-Agent': common.IE_USER_AGENT, 'Referer': web_url}
42
43        html = self.net.http_GET(web_url, headers=headers).content
44#        print "111111111111", html.encode('utf-8').strip()
45        old = 0
46        if old:
47            vhash = re.search('\'_vhash\', value: \'(.*?)\'', html).group(1)
48            gfk = re.search('\'gfk\', value: \'(.*?)\'', html).group(1)
49
50            fname = re.search('name="fname" value="(.*?)"', html).group(1)
51            op = re.search('name="op" value="(.*?)"', html).group(1)
52            inhu = re.search('name="inhu" value="(.*?)"', html).group(1)
53            usr_login = re.search('name="usr_login" value="(.*?)"', html).group(1)
54
55            hash = re.search('name="hash" value="(.*?)"', html).group(1)
56            fdata = {'_vhash': vhash,
57                     'gfk': gfk,
58                     'op': op,
59                     'usr_login': usr_login,
60                     'id': media_id,                 
61                     'fname': fname,
62                     'referer': '',
63                     'hash': hash,
64                     'imhuman': 'Proceed to video',
65                     'inhu': inhu}
66
67            html = self.net.http_POST(url=web_url, form_data=fdata, headers=headers).content
68#            print "2222222222", html.encode('utf-8').strip()
69
70#http://thevideo.me/jwv/LDonSU04MylZO1ZNSThGPUEK
71        r = re.search('sources:\s*(\[.*?\])', html, re.DOTALL)
72
73        if r:
74            sources = json.loads(r.group(1))
75            max_label = 0
76            stream_url = ''
77            for source in sources:
78                if 'label' in source and int(re.sub('[^0-9]', '', source['label'])) > max_label:
79                    stream_url = source['file']
80                    max_label = int(re.sub('[^0-9]', '', source['label']))
81
82        for match in re.finditer('(eval\(function.*?)</script>', html, re.DOTALL):
83            js_data = jsunpack.unpack(match.group(1))
84            path = re.search('\'rc=".*(/.*?)\\\'.concat', js_data).group(1)
85            path = path.replace('\\', '')
86            if path:
87                break
88
89        mpri_Key = re.search('var mpri_Key=\'(.*?)\'', html).group(1)
90        web_url = self.get_aturl(host, path, mpri_Key)
91        html = self.net.http_GET(web_url, headers=headers).content
92#        print "3333333333", html.encode('utf-8').strip()
93
94        js_data = jsunpack.unpack(html)
95        for match in re.finditer('(eval\(function.*?)\{\}\)\)', html, re.DOTALL):
96            js_data = jsunpack.unpack(match.group(1))
97            vt = re.search('"vt=(.*?)"', js_data).group(1)
98            print '%s?direct=false&ua=1&vt=%s' % (stream_url, vt)
99       
100    def get_url(self, host, media_id):
101        return 'http://%s/%s' % (host, media_id)
102
103    def get_aturl(self, host, path, key):
104        return 'http://%s%s/%s' % (host, path, key)
105
106sys.stdout = TheVideoResolver()
Note: See TracBrowser for help on using the repository browser.