1 | |
---|
2 | import re |
---|
3 | import sys |
---|
4 | from lib.net import Net |
---|
5 | from lib import helpers |
---|
6 | import lib.common as common |
---|
7 | |
---|
8 | class VidtoResolver(object): |
---|
9 | name = "vidto" |
---|
10 | domains = ["vidto.me"] |
---|
11 | pattern = '(?://|\.)(vidto\.me)/(?:embed-)?([0-9a-zA-Z]+)' |
---|
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 | html = self.net.http_GET(web_url, headers=headers).content |
---|
32 | html = helpers.add_packed_data(html) |
---|
33 | sources = [] |
---|
34 | for match in re.finditer('label:\s*"([^"]+)"\s*,\s*file:\s*"([^"]+)', html): |
---|
35 | label, stream_url = match.groups() |
---|
36 | sources.append((label, stream_url)) |
---|
37 | |
---|
38 | sources = sorted(sources, key=lambda x: x[0])[::-1] |
---|
39 | print helpers.pick_source(sources) + helpers.append_headers(headers) |
---|
40 | # print helpers.pick_source(sources) |
---|
41 | |
---|
42 | # raise ResolverError("File Link Not Found") |
---|
43 | |
---|
44 | # def get_url(self, host, media_id): |
---|
45 | # return self._default_get_url(host, media_id) |
---|
46 | |
---|
47 | def get_url(self, host, media_id): |
---|
48 | return 'http://%s/embed-%s.html' % (host, media_id) |
---|
49 | |
---|
50 | sys.stdout = VidtoResolver() |
---|