source: titan/mediathek/localhoster/vidto.py @ 42882

Last change on this file since 42882 was 39358, checked in by obi, 7 years ago

add vidto.py

File size: 1.5 KB
Line 
1
2import re
3import sys
4from lib.net import Net
5from lib import helpers
6import lib.common as common
7
8class 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
50sys.stdout = VidtoResolver()
Note: See TracBrowser for help on using the repository browser.