[39219] | 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 |
---|
[42919] | 11 | import re, urllib, json |
---|
[39219] | 12 | |
---|
| 13 | INTERVALS = 5 |
---|
| 14 | |
---|
| 15 | class TheVideoResolver(object): |
---|
| 16 | name = "thevideo" |
---|
| 17 | domains = ["thevideo.me"] |
---|
[44486] | 18 | pattern = '(?://|\.)(streamcrypt\.net|thevideo\.me|thevideo\.cc|vev\.io|tvad./me)/(?:embed-|download/)?([0-9a-zA-Z]+)' |
---|
[39219] | 19 | |
---|
| 20 | def __init__(self): |
---|
[42919] | 21 | # self.net = Net() |
---|
| 22 | self.net = Net(cookie_file='/mnt/network/cookies', http_debug = False) |
---|
[40880] | 23 | self.headers = {'User-Agent': common.ANDROID_USER_AGENT} |
---|
[39219] | 24 | url = str(sys.argv[1]) |
---|
[44486] | 25 | # print "url", url |
---|
[39219] | 26 | host = self.get_host_and_id(url)[0] |
---|
| 27 | media_id = self.get_host_and_id(url)[1] |
---|
[44486] | 28 | return self.get_media_url(url) |
---|
| 29 | # return self.get_media_url(host, media_id) |
---|
[39219] | 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 | |
---|
[44486] | 38 | def get_media_url(self, url): |
---|
| 39 | # web_url = self.get_url(host, media_id) |
---|
| 40 | web_url = url |
---|
[42919] | 41 | |
---|
[39219] | 42 | headers = { |
---|
| 43 | 'Referer': web_url |
---|
| 44 | } |
---|
| 45 | headers.update(self.headers) |
---|
| 46 | |
---|
[42919] | 47 | response = self.net.http_GET(web_url, headers=headers).content |
---|
[44486] | 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 |
---|
[42919] | 55 | ret = self.net.save_cookies('/mnt/network/cookies') |
---|
[44486] | 56 | # videoCode = self.getSearchGroups(response, r'''['"]video_code['"]\s*:\s*['"]([^'^"]+?)['"]''')[0] |
---|
| 57 | videoCode = re.findall("video/mp4.*'(.*?)\\\\'.*;", response) |
---|
[45654] | 58 | # print videoCode[0] |
---|
[39219] | 59 | |
---|
[45654] | 60 | sStreamUrl = 'https://thevideome.com/%s' % (videoCode[0]) |
---|
| 61 | sUrl = self.redirectHoster(sStreamUrl) |
---|
| 62 | print sUrl |
---|
| 63 | |
---|
[42919] | 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 |
---|
[39219] | 76 | |
---|
[42919] | 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 |
---|
[39219] | 93 | |
---|
[42919] | 94 | if addParams['return_data'] and status and not isinstance(response, basestring): |
---|
| 95 | status = False |
---|
| 96 | |
---|
| 97 | return (status, response) |
---|
| 98 | |
---|
[39219] | 99 | def get_url(self, host, media_id): |
---|
[40880] | 100 | return 'http://%s/embed-%s-640x360.html' % (host, media_id) |
---|
[39219] | 101 | |
---|
[45654] | 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 | |
---|
[40880] | 122 | sys.stdout = TheVideoResolver() |
---|