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

Last change on this file since 44486 was 44486, checked in by obi, 2 years ago

test thevideo

File size: 3.0 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    def getSearchGroups(self, data, pattern, grupsNum=1, ignoreCase=False):
61        tab = []
62        if ignoreCase:
63            match = re.search(pattern, data, re.IGNORECASE)
64        else:
65            match = re.search(pattern, data)
66       
67        for idx in range(grupsNum):
68            try:    value = match.group(idx + 1)
69            except Exception: value = ''
70            tab.append(value)
71        return tab
72
73    def getPage(self, url, addParams = {}, post_data = None):
74        ''' wraps getURLRequestData '''
75        try:
76            addParams['url'] = url
77            if 'return_data' not in addParams:
78                addParams['return_data'] = True
79            response = self.getURLRequestData(addParams, post_data)
80            status = True
81        except urllib2.HTTPError, e:
82#            printExc()
83            response = e
84            status = False
85        except Exception:
86#            printExc()
87            response = None
88            status = False
89       
90        if addParams['return_data'] and status and not isinstance(response, basestring):
91            status = False
92           
93        return (status, response)
94 
95    def get_url(self, host, media_id):
96        return 'http://%s/embed-%s-640x360.html' % (host, media_id)
97
98sys.stdout = TheVideoResolver()
Note: See TracBrowser for help on using the repository browser.