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

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

fix nowvideo

File size: 2.3 KB
Line 
1
2import sys
3import re
4from lib.net import Net
5import lib.common as common
6from lib import helpers
7
8class NowvideoResolver(object):
9    name = "nowvideo"
10    domains = ['nowvideo.eu', 'nowvideo.ch', 'nowvideo.sx', 'nowvideo.co', 'nowvideo.li', 'nowvideo.fo', 'nowvideo.at', 'nowvideo.ec']
11    pattern = '(?://|\.)(nowvideo\.(?:eu|ch|sx|co|li|fo|at|ec))/(?:video/|embed\.php\?\S*v=|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://embed.nowvideo.sx/embed/?v=%s' % media_id
68
69sys.stdout = NowvideoResolver()
Note: See TracBrowser for help on using the repository browser.