source: titan/mediathek/localhoster/allmyvideos.py @ 38989

Last change on this file since 38989 was 38989, checked in by obi, 5 years ago

fox

File size: 2.4 KB
Line 
1
2import re
3import json
4import urllib
5import urlparse
6from lib import helpers
7import sys
8from lib.net import Net
9import lib.common as common
10
11class AllmyvideosResolver(object):
12    name = "allmyvideos"
13    domains = ["allmyvideos.net"]
14    pattern = '(?://|\.)(allmyvideos\.net)/(?:embed-)?([0-9a-zA-Z]+)'
15
16    def __init__(self):
17        self.net = Net()
18        url = str(sys.argv[1])
19        host = self.get_host_and_id(url)[0]
20        media_id = self.get_host_and_id(url)[1]
21
22        return self.get_media_url(host, media_id)
23
24    def get_host_and_id(self, url):
25        r = re.search(self.pattern, url, re.I)
26        if r:
27            return r.groups()
28        else:
29            return False
30
31    def get_media_url(self, host, media_id):
32        url = self.get_url1st(host, media_id)
33        headers = {'User-Agent': common.IE_USER_AGENT, 'Referer': url}
34        html = self.net.http_GET(url, headers=headers).content
35        stream_url = self.__get_best_source(html)
36        if stream_url:
37#            xbmc.sleep(2000)
38            print stream_url
39
40        url = self.get_url(host, media_id)
41        headers = {'User-Agent': common.IE_USER_AGENT, 'Referer': url}
42        html = self.net.http_GET(url, headers=headers).content
43
44        data = helpers.get_hidden(html)
45        html = self.net.http_POST(url, data, headers=headers).content
46        stream_url = self.__get_best_source(html)
47        if stream_url:
48#           xbmc.sleep(2000)
49            print stream_url
50
51    def __get_best_source(self, html):
52        r = re.search('"sources"\s*:\s*(\[.*?\])', html, re.DOTALL)
53        if r:
54            sources = json.loads(r.group(1))
55            max_label = 0
56            stream_url = ''
57            for source in sources:
58                if 'label' in source and int(re.sub('[^0-9]', '', source['label'])) > max_label:
59                    stream_url = source['file']
60                    max_label = int(re.sub('[^0-9]', '', source['label']))
61            if stream_url:
62                stream_url = '%s?%s&direct=false&ua=false' % (stream_url.split('?')[0], urlparse.urlparse(stream_url).query)
63                return stream_url + '|' + urllib.urlencode({'User-Agent': common.IE_USER_AGENT})
64
65    def get_url(self, host, media_id):
66        return 'http://allmyvideos.net/%s' % media_id
67
68    def get_url1st(self, host, media_id):
69        return 'http://allmyvideos.net/embed-%s.html' % media_id
70
71sys.stdout = AllmyvideosResolver()
72
Note: See TracBrowser for help on using the repository browser.