source: titan/mediathek/localhoster/thevideo.py

Last change on this file was 45654, checked in by obi, 7 weeks ago

tithek fix thevideo hoster

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
11import re, urllib, json
12
13INTERVALS = 5
14
15class TheVideoResolver(object):
16    name = "thevideo"
17    domains = ["thevideo.me"]
18    pattern = '(?://|\.)(streamcrypt\.net|thevideo\.me|thevideo\.cc|vev\.io|tvad./me)/(?:embed-|download/)?([0-9a-zA-Z]+)'
19
20    def __init__(self):
21#        self.net = Net()
22        self.net = Net(cookie_file='/mnt/network/cookies', http_debug = False)
23        self.headers = {'User-Agent': common.ANDROID_USER_AGENT}
24        url = str(sys.argv[1])
25#        print "url", url
26        host = self.get_host_and_id(url)[0]
27        media_id = self.get_host_and_id(url)[1]
28        return self.get_media_url(url)
29#        return self.get_media_url(host, media_id)
30
31    def get_host_and_id(self, url):
32        r = re.search(self.pattern, url, re.I)
33        if r:
34            return r.groups()
35        else:
36            return False
37
38    def get_media_url(self, url):
39#        web_url = self.get_url(host, media_id)
40        web_url = url
41
42        headers = {
43            'Referer': web_url
44        }
45        headers.update(self.headers)
46
47        response = self.net.http_GET(web_url, headers=headers).content
48        js_data = re.findall('(eval\(function.*?)</script>', response.replace('\n', ''))
49#        print "js_data1", js_data
50        for i in js_data:
51            response += jsunpack.unpack(i)
52#        print "js_data2", js_data
53
54#        print "response", response
55        ret = self.net.save_cookies('/mnt/network/cookies')
56#        videoCode = self.getSearchGroups(response, r'''['"]video_code['"]\s*:\s*['"]([^'^"]+?)['"]''')[0]
57        videoCode = re.findall("video/mp4.*'(.*?)\\\\'.*;", response)
58#        print videoCode[0]
59
60        sStreamUrl = 'https://thevideome.com/%s' % (videoCode[0])
61        sUrl = self.redirectHoster(sStreamUrl)
62        print sUrl
63
64    def getSearchGroups(self, data, pattern, grupsNum=1, ignoreCase=False):
65        tab = []
66        if ignoreCase:
67            match = re.search(pattern, data, re.IGNORECASE)
68        else:
69            match = re.search(pattern, data)
70       
71        for idx in range(grupsNum):
72            try:    value = match.group(idx + 1)
73            except Exception: value = ''
74            tab.append(value)
75        return tab
76
77    def getPage(self, url, addParams = {}, post_data = None):
78        ''' wraps getURLRequestData '''
79        try:
80            addParams['url'] = url
81            if 'return_data' not in addParams:
82                addParams['return_data'] = True
83            response = self.getURLRequestData(addParams, post_data)
84            status = True
85        except urllib2.HTTPError, e:
86#            printExc()
87            response = e
88            status = False
89        except Exception:
90#            printExc()
91            response = None
92            status = False
93       
94        if addParams['return_data'] and status and not isinstance(response, basestring):
95            status = False
96           
97        return (status, response)
98 
99    def get_url(self, host, media_id):
100        return 'http://%s/embed-%s-640x360.html' % (host, media_id)
101
102    def redirectHoster(self, url):
103        try:
104            from urllib2 import build_opener, HTTPError
105        except ImportError:
106            from urllib.error import HTTPError
107            from urllib.request import build_opener
108        opener = build_opener()
109        opener.addheaders = [('Referer', url)]
110        try:
111            resp = opener.open(url)
112            if url != resp.geturl():
113                return resp.geturl()
114            else:
115                return url
116        except HTTPError as e:
117            if e.code == 403:
118                if url != e.geturl():
119                    return e.geturl()
120            raise
121
122sys.stdout = TheVideoResolver()
Note: See TracBrowser for help on using the repository browser.