[39232] | 1 |
|
---|
[39352] | 2 | import random
|
---|
[39232] | 3 | import re
|
---|
| 4 | import urllib
|
---|
| 5 | import sys
|
---|
| 6 | from lib.net import Net
|
---|
[39352] | 7 | from lib import helpers
|
---|
[39354] | 8 | import lib.common as common
|
---|
[39232] | 9 |
|
---|
| 10 | class MovshareResolver(object):
|
---|
| 11 | name = "movshare"
|
---|
| 12 | domains = ["movshare.net", 'wholecloud.net', 'vidgg.to']
|
---|
| 13 | pattern = '(?://|\.)(movshare.net|wholecloud.net|vidgg.to)/(?:video/|embed(?:/|\.php)\?(?:v|id)=)([A-Za-z0-9]+)'
|
---|
| 14 |
|
---|
| 15 | def __init__(self):
|
---|
| 16 | self.net = Net()
|
---|
| 17 | url = str(sys.argv[1])
|
---|
| 18 | host = self.get_host_and_id(url)[0]
|
---|
| 19 | media_id = self.get_host_and_id(url)[1]
|
---|
| 20 |
|
---|
| 21 | return self.get_media_url(host, media_id)
|
---|
| 22 |
|
---|
| 23 | def get_host_and_id(self, url):
|
---|
| 24 | r = re.search(self.pattern, url, re.I)
|
---|
| 25 | if r:
|
---|
| 26 | return r.groups()
|
---|
| 27 | else:
|
---|
| 28 | return False
|
---|
| 29 |
|
---|
| 30 | def get_media_url(self, host, media_id):
|
---|
| 31 | web_url = self.get_url(host, media_id)
|
---|
[39352] | 32 | headers = {'User-Agent': common.FF_USER_AGENT}
|
---|
| 33 | html = self.net.http_GET(web_url, headers=headers).content
|
---|
| 34 | stream_url = ''
|
---|
| 35 | match = re.search('<video.*?</video>', html, re.DOTALL)
|
---|
| 36 | if match:
|
---|
| 37 | links = re.findall('<source[^>]+src="([^"]+)', match.group(0), re.DOTALL)
|
---|
| 38 | if links:
|
---|
| 39 | stream_url = random.choice(links)
|
---|
| 40 |
|
---|
| 41 | if not stream_url:
|
---|
| 42 | match = re.search('fkzd="([^"]+)', html)
|
---|
| 43 | if match:
|
---|
| 44 | query = {'pass': 'undefined', 'key': match.group(1), 'cid3': 'undefined', 'cid': 0, 'numOfErrors': 0, 'file': media_id, 'cid2': 'undefined', 'user': 'undefined'}
|
---|
| 45 | api_url = 'http://www.wholecloud.net//api/player.api.php?' + urllib.urlencode(query)
|
---|
| 46 | html = self.net.http_GET(api_url, headers=headers).content
|
---|
| 47 | match = re.search('url=([^&]+)', html)
|
---|
| 48 | if match:
|
---|
| 49 | stream_url = match.group(1)
|
---|
[39232] | 50 |
|
---|
| 51 | if stream_url:
|
---|
[39352] | 52 | headers.update({'Referer': web_url, })
|
---|
| 53 | print stream_url + helpers.append_headers(headers)
|
---|
[39354] | 54 | # else:
|
---|
| 55 | # raise ResolverError('File Not Found or removed')
|
---|
[39232] | 56 |
|
---|
| 57 | def get_url(self, host, media_id):
|
---|
| 58 | if 'vidgg' in host:
|
---|
[39354] | 59 | return 'http://%s/embed/?id=%s' % (host, media_id)
|
---|
| 60 | # template = 'http://{host}/embed/?id={media_id}'
|
---|
[39232] | 61 | else:
|
---|
[39354] | 62 | return 'http://%s/embed/?v=%s' % (host, media_id)
|
---|
| 63 | # template = 'http://{host}/embed/?v={media_id}'
|
---|
[39352] | 64 | print self._default_get_url(host, media_id, template)
|
---|
[39232] | 65 |
|
---|
| 66 | sys.stdout = MovshareResolver()
|
---|