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

Last change on this file since 40880 was 40880, checked in by obi, 4 years ago

test fix thevideo

File size: 2.6 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.ANDROID_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        html = self.net.http_GET(web_url, headers=headers).content
42
43        r = re.search('sources:\s*(\[.*?\])', html, re.DOTALL)
44
45        if r:
46            sources = json.loads(r.group(1))
47            max_label = 0
48            stream_url = ''
49            for source in sources:
50                if 'label' in source and int(re.sub('[^0-9]', '', source['label'])) > max_label:
51                    stream_url = source['file']
52                    max_label = int(re.sub('[^0-9]', '', source['label']))
53
54        varname = re.search('''concat\(\s*['"]/["']\s*\+([^\+]+?)\+''', html).group(1)
55
56#        authkey = re.search('''var lets_play_a_game=\'(.*)\'''', html).group(1)
57#        print "authkey2", authkey
58
59        authkey = re.search(r"=\'(.*)\'", html).group(1)
60
61#        my_regex = r"var " + re.escape(varname) + r"""\s*=\s*['"]([^'^"]+?)['"]"""
62#        my_regex = re.escape(varname) + r"""\s*=\s*['"]([^'^"]+?)['"]"""
63#
64#        test = re.search(my_regex, html, re.IGNORECASE)
65#        print "test", test
66
67        web_url = "https://thevideo.me/vsign/player/" + authkey
68        html = self.net.http_GET(web_url, headers=headers).content
69
70        js_data = jsunpack.unpack(html)
71        for match in re.finditer('(eval\(function.*?)\{\}\)\)', html, re.DOTALL):
72            js_data = jsunpack.unpack(match.group(1))
73            ua = re.search('"ua=(.*?)"', js_data).group(1)
74            vt = re.search('"vt=(.*?)"', js_data).group(1)
75            print '%s?direct=false&ua=%s&vt=%s' % (stream_url, ua, vt)
76
77       
78    def get_url(self, host, media_id):
79        return 'http://%s/embed-%s-640x360.html' % (host, media_id)
80
81sys.stdout = TheVideoResolver()
Note: See TracBrowser for help on using the repository browser.