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

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

tithek thevideo add deleted error msg

File size: 2.7 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        if re.search('File was deleted.', html):
55            print 'errormsg=File was deleted.'
56
57        varname = re.search('''concat\(\s*['"]/["']\s*\+([^\+]+?)\+''', html).group(1)
58
59#        authkey = re.search('''var lets_play_a_game=\'(.*)\'''', html).group(1)
60#        print "authkey2", authkey
61
62        authkey = re.search(r"=\'(.*)\'", html).group(1)
63
64#        my_regex = r"var " + re.escape(varname) + r"""\s*=\s*['"]([^'^"]+?)['"]"""
65#        my_regex = re.escape(varname) + r"""\s*=\s*['"]([^'^"]+?)['"]"""
66#
67#        test = re.search(my_regex, html, re.IGNORECASE)
68#        print "test", test
69
70        web_url = "https://thevideo.me/vsign/player/" + authkey
71        html = self.net.http_GET(web_url, headers=headers).content
72
73        js_data = jsunpack.unpack(html)
74        for match in re.finditer('(eval\(function.*?)\{\}\)\)', html, re.DOTALL):
75            js_data = jsunpack.unpack(match.group(1))
76            ua = re.search('"ua=(.*?)"', js_data).group(1)
77            vt = re.search('"vt=(.*?)"', js_data).group(1)
78            print '%s?direct=false&ua=%s&vt=%s' % (stream_url, ua, vt)
79
80       
81    def get_url(self, host, media_id):
82        return 'http://%s/embed-%s-640x360.html' % (host, media_id)
83
84sys.stdout = TheVideoResolver()
Note: See TracBrowser for help on using the repository browser.