[39608] | 1 |
|
---|
| 2 | import sys
|
---|
| 3 | import re
|
---|
| 4 | from lib.net import Net
|
---|
| 5 | import lib.common as common
|
---|
| 6 | from lib import helpers
|
---|
| 7 |
|
---|
| 8 | class DivxstageResolver(object):
|
---|
| 9 | name = 'divxstage'
|
---|
| 10 | domains = ['divxstage.eu', 'divxstage.net', 'divxstage.to', 'cloudtime.to']
|
---|
| 11 | pattern = '(?://|\.)(divxstage.eu|divxstage.net|divxstage.to|cloudtime.to)/(?:video/|embed/\?v=)([A-Za-z0-9]+)'
|
---|
| 12 |
|
---|
| 13 | def __init__(self):
|
---|
| 14 | self.net = Net()
|
---|
| 15 | url = str(sys.argv[1])
|
---|
| 16 | host = self.get_host_and_id(url)[0]
|
---|
| 17 | media_id = self.get_host_and_id(url)[1]
|
---|
| 18 |
|
---|
| 19 | return self.get_media_url(host, media_id)
|
---|
| 20 |
|
---|
| 21 | def get_host_and_id(self, url):
|
---|
| 22 | r = re.search(self.pattern, url, re.I)
|
---|
| 23 | if r:
|
---|
| 24 | return r.groups()
|
---|
| 25 | else:
|
---|
| 26 | return False
|
---|
| 27 |
|
---|
| 28 | def get_media_url(self, host, media_id):
|
---|
| 29 | web_url = self.get_url(host, media_id)
|
---|
| 30 | headers = {'User-Agent': common.FF_USER_AGENT}
|
---|
| 31 | stream_url = ''
|
---|
| 32 | html = self.net.http_GET(web_url, headers=headers).content
|
---|
| 33 | try:
|
---|
| 34 | r = re.search('flashvars.filekey=(.+?);', html)
|
---|
| 35 | if r:
|
---|
| 36 | r = r.group(1)
|
---|
| 37 |
|
---|
| 38 | try: filekey = re.compile('\s+%s="(.+?)"' % r).findall(html)[-1]
|
---|
| 39 | except: filekey = r
|
---|
| 40 |
|
---|
| 41 | player_url = 'http://www.nowvideo.sx/api/player.api.php?key=%s&file=%s' % (filekey, media_id)
|
---|
| 42 |
|
---|
| 43 | html = self.net.http_GET(player_url).content
|
---|
| 44 |
|
---|
| 45 | r = re.search('url=(.+?)&', html)
|
---|
| 46 |
|
---|
| 47 | if r:
|
---|
| 48 | stream_url = r.group(1)
|
---|
| 49 | except:
|
---|
| 50 | print "no embedded urls found using first method"
|
---|
| 51 |
|
---|
| 52 | try:
|
---|
| 53 | r = re.search('id="player".*?src="(.*?)"', html, re.DOTALL)
|
---|
| 54 | if r:
|
---|
| 55 | stream_url = r.group(1)
|
---|
| 56 |
|
---|
| 57 | except:
|
---|
| 58 | print "no embedded urls found using second method"
|
---|
| 59 |
|
---|
| 60 | if stream_url:
|
---|
| 61 | headers.update({'Referer': web_url, })
|
---|
| 62 | print stream_url + helpers.append_headers(headers)
|
---|
| 63 | # print stream_url + helpers.append_headers({'Referer': web_url})
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | def get_url(self, host, media_id):
|
---|
| 67 | return 'http://www.cloudtime.to/embed/?v=%s' % media_id
|
---|
| 68 |
|
---|
| 69 | sys.stdout = DivxstageResolver() |
---|