source: titan/mediathek/localhoster/streamcloud.py @ 42600

Last change on this file since 42600 was 42584, checked in by obi, 16 months ago

fix streamcloud

File size: 1.8 KB
Line 
1
2import re
3import sys
4import time
5from lib.net import Net
6import re, urllib, json
7from lib import helpers
8import lib.common as common
9
10class StreamcloudResolver(object):
11    name = "streamcloud"
12    domains = ["streamcloud.eu"]
13    pattern = '(?://|\.)(streamcloud\.eu)/([0-9a-zA-Z]+)'
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)
32        headers = {'User-Agent': common.FF_USER_AGENT}
33        response = self.net.http_GET(web_url, headers=headers)
34        html = response.content
35        if re.search('>(File Not Found)<', html):
36            raise ResolverError('File Not Found or removed')
37
38        cnt = 10
39        match = re.search('count\s*=\s*(\d+);', html)
40        if match:
41            cnt = int(match.group(1))
42        cnt += 1
43
44        data = helpers.get_hidden(html)
45        headers.update({'Referer': web_url})
46#        common.kodi.sleep(cnt * 1000)
47        time.sleep(10)
48        html = self.net.http_POST(response.get_url(), form_data=data, headers=headers).content
49        sources = helpers.scrape_sources(html, patterns=['''file\s*:\s*["'](?P<url>[^"']+)'''])
50#        return helpers.pick_source(sources) + helpers.append_headers(headers)
51        print helpers.pick_source(sources) + helpers.append_headers(headers)
52#        print "%s%s" % (helpers.pick_source(sources), helpers.append_headers(headers))
53
54
55    def get_url(self, host, media_id):
56        return 'http://streamcloud.eu/%s' % (media_id)
57
58sys.stdout = StreamcloudResolver()
Note: See TracBrowser for help on using the repository browser.