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

Last change on this file since 39359 was 39219, checked in by obi, 7 years ago

mediathek add thevideo py hoster

File size: 3.4 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
45        vhash = re.search('\'_vhash\', value: \'(.*?)\'', html).group(1)
46        gfk = re.search('\'gfk\', value: \'(.*?)\'', html).group(1)
47
48        fname = re.search('name="fname" value="(.*?)"', html).group(1)
49        op = re.search('name="op" value="(.*?)"', html).group(1)
50        inhu = re.search('name="inhu" value="(.*?)"', html).group(1)
51        usr_login = re.search('name="usr_login" value="(.*?)"', html).group(1)
52
53        hash = re.search('name="hash" value="(.*?)"', html).group(1)
54        fdata = {'_vhash': vhash,
55                 'gfk': gfk,
56                 'op': op,
57                 'usr_login': usr_login,
58                 'id': media_id,                 
59                 'fname': fname,
60                 'referer': '',
61                 'hash': hash,
62                 'imhuman': 'Proceed to video',
63                 'inhu': inhu}
64
65        html = self.net.http_POST(url=web_url, form_data=fdata, headers=headers).content
66
67        r = re.search('sources:\s*(\[.*?\])', html, re.DOTALL)
68
69        if r:
70            sources = json.loads(r.group(1))
71            max_label = 0
72            stream_url = ''
73            for source in sources:
74                if 'label' in source and int(re.sub('[^0-9]', '', source['label'])) > max_label:
75                    stream_url = source['file']
76                    max_label = int(re.sub('[^0-9]', '', source['label']))
77
78        for match in re.finditer('(eval\(function.*?)</script>', html, re.DOTALL):
79            js_data = jsunpack.unpack(match.group(1))
80            path = re.search('\'rc=".*(/.*?)\\\'.concat', js_data).group(1)
81            path = path.replace('\\', '')
82            if path:
83                break
84
85        mpri_Key = re.search('var mpri_Key=\'(.*?)\'', html).group(1)
86        web_url = self.get_aturl(host, path, mpri_Key)
87        html = self.net.http_GET(web_url, headers=headers).content
88        js_data = jsunpack.unpack(html)
89        for match in re.finditer('(eval\(function.*?)\{\}\)\)', html, re.DOTALL):
90            js_data = jsunpack.unpack(match.group(1))
91            vt = re.search('"vt=(.*?)"', js_data).group(1)
92            print '%s?direct=false&ua=1&vt=%s' % (stream_url, vt)
93       
94    def get_url(self, host, media_id):
95        return 'http://%s/%s' % (host, media_id)
96
97    def get_aturl(self, host, path, key):
98        return 'http://%s%s/%s' % (host, path, key)
99
100sys.stdout = TheVideoResolver()
Note: See TracBrowser for help on using the repository browser.