1 | |
---|
2 | import re |
---|
3 | import json |
---|
4 | import urllib2 |
---|
5 | import time |
---|
6 | from lib import helpers |
---|
7 | import sys |
---|
8 | from lib.net import Net |
---|
9 | import lib.common as common |
---|
10 | from lib import jsunpack |
---|
11 | import re, urllib, json |
---|
12 | |
---|
13 | INTERVALS = 5 |
---|
14 | |
---|
15 | class TheVideoResolver(object): |
---|
16 | name = "thevideo" |
---|
17 | domains = ["thevideo.me"] |
---|
18 | pattern = '(?://|\.)(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 | host = self.get_host_and_id(url)[0] |
---|
26 | media_id = self.get_host_and_id(url)[1] |
---|
27 | |
---|
28 | return self.get_media_url(host, media_id) |
---|
29 | |
---|
30 | def get_host_and_id(self, url): |
---|
31 | r = re.search(self.pattern, url, re.I) |
---|
32 | if r: |
---|
33 | return r.groups() |
---|
34 | else: |
---|
35 | return False |
---|
36 | |
---|
37 | def get_media_url(self, host, media_id): |
---|
38 | web_url = self.get_url(host, media_id) |
---|
39 | |
---|
40 | headers = { |
---|
41 | 'Referer': web_url |
---|
42 | } |
---|
43 | headers.update(self.headers) |
---|
44 | |
---|
45 | response = self.net.http_GET(web_url, headers=headers).content |
---|
46 | ret = self.net.save_cookies('/mnt/network/cookies') |
---|
47 | videoCode = self.getSearchGroups(response, r'''['"]video_code['"]\s*:\s*['"]([^'^"]+?)['"]''')[0] |
---|
48 | print videoCode |
---|
49 | |
---|
50 | def getSearchGroups(self, data, pattern, grupsNum=1, ignoreCase=False): |
---|
51 | tab = [] |
---|
52 | if ignoreCase: |
---|
53 | match = re.search(pattern, data, re.IGNORECASE) |
---|
54 | else: |
---|
55 | match = re.search(pattern, data) |
---|
56 | |
---|
57 | for idx in range(grupsNum): |
---|
58 | try: value = match.group(idx + 1) |
---|
59 | except Exception: value = '' |
---|
60 | tab.append(value) |
---|
61 | return tab |
---|
62 | |
---|
63 | def getPage(self, url, addParams = {}, post_data = None): |
---|
64 | ''' wraps getURLRequestData ''' |
---|
65 | try: |
---|
66 | addParams['url'] = url |
---|
67 | if 'return_data' not in addParams: |
---|
68 | addParams['return_data'] = True |
---|
69 | response = self.getURLRequestData(addParams, post_data) |
---|
70 | status = True |
---|
71 | except urllib2.HTTPError, e: |
---|
72 | # printExc() |
---|
73 | response = e |
---|
74 | status = False |
---|
75 | except Exception: |
---|
76 | # printExc() |
---|
77 | response = None |
---|
78 | status = False |
---|
79 | |
---|
80 | if addParams['return_data'] and status and not isinstance(response, basestring): |
---|
81 | status = False |
---|
82 | |
---|
83 | return (status, response) |
---|
84 | |
---|
85 | def get_url(self, host, media_id): |
---|
86 | return 'http://%s/embed-%s-640x360.html' % (host, media_id) |
---|
87 | |
---|
88 | sys.stdout = TheVideoResolver() |
---|