def resolve(self, ident, download_type=None):
        params = {'ident': ident, 'wst': self.token}

        if None is not download_type:
            params.update({
                'download_type': download_type,
                'device_uuid': getSetting('uid'),
                'device_res_x': infoLabel('System.ScreenWidth'),
                'device_res_y': infoLabel('System.ScreenHeight'),
            })

        headers, req = self._create_request('/', params)
        util.info(headers)
        util.info(req)
        try:
            data = post(self._url('api/file_link/'),
                        req,
                        headers=headers,
                        output="content")
            xml = ET.fromstring(data)
            if not xml.find('status').text == 'OK':
                self.clearToken()
                util.error('[SC] Server returned error status, response: %s' %
                           data)
                raise ResolveException(xml.find('message').text)
            return xml.find('link').text
        except Exception as e:
            self.clearToken()
            raise ResolveException(e)
Ejemplo n.º 2
0
 def resolve(self, item, captcha_cb=None, select_cb=None):
     #util.debug("[SC] ITEM RESOLVE: " + str(item))
     #util.debug("[SC] RESOLVE argv: [%s] " % str(sys.argv))
     sctop.win.setProperty('sc.resume', 'true')
     addparams = sys.argv[3] if 3 in sys.argv else None
     if addparams is not None and re.search('resume:false',
                                            sys.argv.get(3)):
         sctop.win.setProperty('sc.resume', 'false')
     if 'https://' not in item['url'] and 'http://' not in item['url']:
         item['url'] = self._url(item['url'])
     if sctop.BASE_URL in item['url']:
         try:
             data = self._json(item['url'])
         except:
             raise ResolveException('Video is not available.')
         if data is None or data is False:
             raise ResolveException('Video is not available.')
         if 'strms' in data:
             util.debug("[SC] data info: %s" % str(data['info']))
             out = [
                 sctop.merge_dicts(data['info'], i) for i in data['strms']
             ]
             data = out
         #util.debug("[SC] data: %s" % str(data))
         if len(data) < 1:
             raise ResolveException('Video is not available.')
         return self._resolve(select_cb(data))
     else:
         return self._resolve(item)
Ejemplo n.º 3
0
 def resolve(self, item, captcha_cb=None, select_cb=None):
     page = util.request(self._url(item['url']))
     data = util.substr(page, '<div id=\"video', '<div id=\"controller')
     data = re.sub('youtube-nocookie.com', 'youtube.com', data)
     resolved = resolver.findstreams(data, [
         '<embed( )src=\"(?P<url>[^\"]+)',
         '<object(.+?)data=\"(?P<url>[^\"]+)',
         '<iframe(.+?)src=\"(?P<url>[^\"]+)'
     ])
     result = []
     if not resolved:
         raise ResolveException('Video nenalezeno')
     for i in resolved:
         item = self.video_item()
         item['title'] = i['title']
         item['url'] = i['url']
         item['quality'] = i['quality']
         item['surl'] = i['surl']
         item['headers'] = i['headers']
         result.append(item)
     result = sorted(result, key=lambda x: x['title'])
     if len(result) == 1:
         return result[0]
     elif len(result) > 1 and select_cb:
         return select_cb(result)
Ejemplo n.º 4
0
    def resolve(self, item, captcha_cb=None, select_cb=None):

        def probeHTML5(result):

            class NoRedirectHandler(urllib2.HTTPRedirectHandler):

                def http_error_302(self, req, fp, code, msg, headers):
                    infourl = urllib.addinfourl(fp, headers, req.get_full_url())
                    infourl.status = code
                    infourl.code = code
                    return infourl
                http_error_300 = http_error_302
                http_error_301 = http_error_302
                http_error_303 = http_error_302
                http_error_307 = http_error_302

            opener = urllib2.build_opener(NoRedirectHandler())
            urllib2.install_opener(opener)

            r = urllib2.urlopen(urllib2.Request(result['url'], headers=result['headers']))
            if r.code == 200:
                result['url'] = r.read()
            return result

        data = item['url']
        if not data:
            raise ResolveException('Video is not available.')
        result = self.findstreams([STREAMUJ_URL + data])
        if len(result) == 1:
            return probeHTML5(self.set_streamujtv_info(result[0]))
        elif len(result) > 1 and select_cb:
            return probeHTML5(self.set_streamujtv_info(select_cb(result)))
    def resolve(self, item, captcha_cb=None, select_cb=None):
        result = []
        resolved = []
        item = item.copy()
        url = self._url(item['url'])
        data = util.substr(util.request(url), 'async type', '</script>')
        print 'data start ----'
        print data
        print 'data end ----'
        playlist = re.search(
            '''new mfJWPlayer.+?(?P<jsondata>playlist:.+?)events:''', data,
            re.MULTILINE | re.DOTALL)
        print 'playlist start ----'
        print playlist
        print 'playlist end ----'
        jsondata = re.sub(
            ' +', ' ', '{%s' %
            playlist.group('jsondata').replace('file:', '"file":').replace(
                'label:', '"label":').replace('kind:', '"kind":').replace(
                    'default:', '"default":').replace(
                        'true', '"true"').replace('],', ']')) + '}'
        print 'jsondata start ----'
        print jsondata
        print 'jsondata end ----'
        jsondata = demjson.decode(jsondata)

        for playlist_item in jsondata['playlist']:
            video_url = resolver.findstreams([playlist_item['file']])
            subs = playlist_item['tracks']
            if video_url and subs:
                for i in video_url:
                    i['subs'] = self.base_url[:-1] + subs[0]['file']
            resolved += video_url[:]

            if not resolved:
                raise ResolveException('Video nenalezeno')

            for i in resolved:
                item = self.video_item()
                try:
                    item['title'] = i['title']
                except KeyError:
                    pass
                item['url'] = i['url']
                item['quality'] = i['quality']
                item['surl'] = i['surl']
                item['subs'] = i['subs']
                item['headers'] = i['headers']
                try:
                    item['fmt'] = i['fmt']
                except KeyError:
                    pass
                result.append(item)

        if len(result) > 0 and select_cb:
            return select_cb(result)

        return result
Ejemplo n.º 6
0
 def resolve(self, item, captcha_cb=None, select_cb=None):
     data = item['url']
     if not data:
         raise ResolveException('Video is not available.')
     result = self.findstreams([STREAMUJ_URL + data])
     if len(result) == 1:
         return result[0]
     elif len(result) > 1 and select_cb:
         return select_cb(result)
Ejemplo n.º 7
0
 def resolve(self, item, captcha_cb=None, select_cb=None):
     page = util.request(item['url'])
     data = util.substr(page, '<div class=\"bottom-player\"', 'div>')
     if data.find('<iframe') < 0:
         raise ResolveException('Video is not available.')
     result = self.findstreams(data, ['<iframe src=\"(?P<url>[^\"]+)'])
     if len(result) == 1:
         return result[0]
     elif len(result) > 1 and select_cb:
         return select_cb(result)
Ejemplo n.º 8
0
 def resolve(self, ident):
     headers, req = self._create_request('/', {
         'ident': ident,
         'wst': self.token
     })
     util.info(headers)
     util.info(req)
     try:
         data = post(self._url('api/file_link/'), req, headers=headers)
         xml = ET.fromstring(data)
         if not xml.find('status').text == 'OK':
             self.clearToken()
             util.error('[SC] Server returned error status, response: %s' %
                        data)
             raise ResolveException(xml.find('message').text)
         return xml.find('link').text
     except Exception as e:
         self.clearToken()
         raise ResolveException(e)
Ejemplo n.º 9
0
 def resolve(self, item, captcha_cb=None, select_cb=None):
     #util.debug("ITEM RESOLVE: " + str(item))
     item['url'] = self._url(item['url'])
     if sctop.BASE_URL in item['url']:
         try:
             data = self._json(item['url']) #json.loads(self.get_data_cached(item['url']))
         except:
             raise ResolveException('Video is not available.')
         if data is None or data is False:
             raise ResolveException('Video is not available.')
         if 'strms' in data:
             util.debug("[SC] data info: %s" % str(data['info']))
             out = [sctop.merge_dicts(data['info'], i) for i in data['strms']]
             data = out
         #util.debug("[SC] data: %s" % str(data))
         if len(data) < 1:
             raise ResolveException('Video is not available.')
         return self._resolve(select_cb(data))
     else:
         return self._resolve(item)
Ejemplo n.º 10
0
    def _resolve(self, itm):
        if itm is None:
            return None
        if itm.get('provider') == 'plugin.video.online-files' and itm.get(
                'params').get('cp') == 'webshare.cz':
            if self.parent.getSetting('wsuser') != "":
                try:
                    from myprovider.webshare import Webshare as wx
                    self.ws = wx(self.parent.getSetting('wsuser'),
                                 self.parent.getSetting('wspass'))
                    if not self.ws.login():
                        res = sctop.yesnoDialog(sctop.getString(30945),
                                                sctop.getString(30946), "")
                        if res == True:
                            sctop.openSettings('201.101')
                        return None
                    else:
                        udata = self.ws.userData()
                        util.debug("[SC] udata: %s" % str(udata))
                        if udata == False:
                            util.debug("[SC] NIEJE VIP ucet")
                            sctop.infoDialog(sctop.getString(30947),
                                             icon="WARNING")
                            sctop.sleep(5000)
                        elif int(udata) <= 14:
                            sctop.infoDialog(sctop.getString(30948) %
                                             str(udata),
                                             icon="WARNING")
                            util.debug("[SC] VIP ucet konci")

                    itm['url'] = self.ws.resolve(
                        itm.get('params').get('play').get('ident'))
                except:
                    buggalo.onExceptionRaised()
                    pass
            else:
                sctop.infoDialog(sctop.getString(30945), icon="WARNING")
                #sctop.openSettings('0.1')

        else:
            try:
                raise ResolveException('zatial nic...')
                hmf = urlresolver.HostedMediaFile(url=itm['url'],
                                                  include_disabled=False,
                                                  include_universal=False)
                if hmf.valid_url() is True:
                    try:
                        itm['url'] = hmf.resolve()
                    except:
                        pass
            except:
                pass
        itm['title'] = self.parent.encode(itm['title'])
        return itm
Ejemplo n.º 11
0
 def resolve(self,item,captcha_cb=None,select_cb=None):
     item = item.copy()        
     util.init_urllib()
     headers,req = self._create_request(item['url'],{'ident':'','wst':self.token})
     data = util.post(self._url('api/file_link/'),req,headers=headers)
     xml = ET.fromstring(data)
     if not xml.find('status').text == 'OK':
         self.error('Server returned error status, response: %s' % data)
         raise ResolveException(xml.find('message').text)
     item['url'] = xml.find('link').text
     return item
Ejemplo n.º 12
0
 def checkResponse(self, jsonResp):
     if 'statusCode' in jsonResp:
         emsg = 'ERROR MSG'
         smsg = 'STATUS MSG'
         scode = '-1'
         if 'statusMessage' in jsonResp: smsg = jsonResp['statusMessage']
         if 'errorMessage' in jsonResp: emsg = jsonResp['errorMessage']
         if 'statusCode' in jsonResp:
             scode = toString(jsonResp['statusCode'])
         if scode == '401':  # invalid AT
             raise ResolveException("%s: %s (%s)" % (scode, smsg, emsg))
         else:
             raise Exception("%s: %s (%s)" % (scode, smsg, emsg))
Ejemplo n.º 13
0
 def resolve(self, item, captcha_cb=None, select_cb=None):
     data = item['url']
     if not data:
         raise ResolveException('Video is not available.')
     result = self.findstreams([STREAMUJ_URL + data])
     stream = None
     if len(result) == 1:
         stream = result[0]
     elif len(result) > 1 and select_cb:
         stream = select_cb(result)
         if not stream:
             return None
     return self.probe_html5(self.set_streamujtv_info(stream))
Ejemplo n.º 14
0
 def resolve(self, item, captcha_cb=None, select_cb=None):
     self.write("ITEM RESOLVE: " + str(item))
     data = json.loads(self.get_data_cached(item['url']))
     self.write("\n\n\ndata: " + str(data))
     try:
         if len(data) < 1:
             raise ResolveException('Video is not available.')
         res = []
         for m in data:
             tmp = self._resolve(m)
             self._filter(res, tmp)
         return res
     except:
         self.write(traceback.format_exc())
         pass
Ejemplo n.º 15
0
    def resolve(self, item, captcha_cb=None, select_cb=None):
        result = []
        resolved = []
        item = item.copy()
        url = self._url(item['url'])
        data = util.substr(util.request(url),
                           'jQuery( document ).ready(function()', '</script>')
        print 'data start ----'
        print data
        print 'data end ----'

        urls = re.findall('file:[ ]+\"(?P<url>[^\"].+?)\"', data,
                          re.IGNORECASE | re.DOTALL | re.MULTILINE)
        vid = YDStreamExtractor.getVideoInfo(
            urls[0], quality=self.quality
        )  #quality is 0=SD, 1=720p, 2=1080p, 3=Highest Available
        video_url = [vid.streams()[0]]
        subs = urls[1]

        if video_url and subs:
            for i in video_url:
                i['subs'] = subs
        resolved += video_url[:]

        if not resolved:
            raise ResolveException('Video nenalezeno')

        for i in resolved:
            item = self.video_item()
            try:
                item['title'] = i['title']
            except KeyError:
                pass
            item['url'] = i['xbmc_url']
            item['quality'] = i['ytdl_format']['height']
            item['surl'] = i['ytdl_format']['webpage_url']
            item['subs'] = i['subs']
            item['headers'] = {}
            try:
                item['fmt'] = i['fmt']
            except KeyError:
                pass
            result.append(item)

        return result
Ejemplo n.º 16
0
    def resolve(self, item, captcha_cb=None, select_cb=None):
        result = []
        resolved = []
        item = item.copy()
        url = self._url(item['url'])
        data = util.substr(util.request(url),
                           'jQuery( document ).ready(function()', '</script>')
        print 'data start ----'
        print data
        print 'data end ----'

        urls = re.findall('file:[ ]+\"(?P<url>[^\"].+?)\"', data,
                          re.IGNORECASE | re.DOTALL | re.MULTILINE)
        video_url = resolver.findstreams([
            urls[0].replace('https://youtu.be/',
                            'https://www.youtube.com/watch?v=')
        ])
        print video_url
        subs = urls[1]

        if video_url and subs:
            for i in video_url:
                i['subs'] = subs
        resolved += video_url[:]

        if not resolved:
            raise ResolveException('Video nenalezeno')

        for i in resolved:
            item = self.video_item()
            try:
                item['title'] = i['title']
            except KeyError:
                pass
            item['url'] = i['url']
            item['quality'] = i['quality']
            item['surl'] = i['surl']
            item['subs'] = i['subs']
            item['headers'] = i['headers']
            try:
                item['fmt'] = i['fmt']
            except KeyError:
                pass
            result.append(item)
        return result
Ejemplo n.º 17
0
    def resolve(self, ident, devid, dwnType='video_stream'):
        try:
            headers, req = self._create_request(
                '/', {
                    'ident': ident,
                    'wst': self.token,
                    'download_type': dwnType,
                    'device_uuid': devid
                })
            # @TODO add params, maybe later 'device_res_x': infoLabel('System.ScreenWidth'), 'device_res_y': infoLabel('System.ScreenHeight'),

            #util.info(headers)
            #util.info(req)
            data = util.post(self._url('api/file_link/'), req, headers=headers)
            xml = ET.fromstring(data)
            if not xml.find('status').text == 'OK':
                #util.error('Server returned error status, response: %s' % data)
                raise ResolveException(xml.find('message').text)
            return xml.find('link').text
        except:
            raise
Ejemplo n.º 18
0
class FastshareContentProvider(ContentProvider):

    def __init__(self,username=None,password=None,filter=None,tmp_dir='.'):
        ContentProvider.__init__(self,'fastshare.cz','http://www.fastshare.cz/',username,password,filter,tmp_dir)
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.LWPCookieJar()))
        urllib2.install_opener(opener)

    def capabilities(self):
        return ['search','resolve']

    def search(self,keyword):
        return self.list('?term='+urllib.quote(keyword))

    def list(self,url):
        result = []
        page = util.request(self._url(url))
        data = util.substr(page,'<div class=\"search','<footer')
        for m in re.finditer('<div class=\"search-result-box(.+?)</a>',data,re.IGNORECASE | re.DOTALL ):
            it = m.group(1)
            link = re.search('<a href=([^ ]+)',it,re.IGNORECASE | re.DOTALL)
            name = re.search('title=\"([^\"]+)',it,re.IGNORECASE | re.DOTALL)
            img = re.search('<img src=\"([^\"]+)',it,re.IGNORECASE | re.DOTALL)
            size = re.search('<div class=\"fs\">([^<]+)',it,re.IGNORECASE | re.DOTALL)
            time = re.search('<div class=\"vd\">([^<]+)',it,re.IGNORECASE | re.DOTALL)
            if name and link:
                item = self.video_item()
                item['title'] = name.group(1)
                if size:
                    item['size'] = size.group(1).strip()
                if time:
                    item['length'] =  time.group(1).strip()
                item['url'] = self._url(link.group(1))
                item['img'] = self._url(img.group(1))
                self._filter(result,item)
        next = re.search('<a href=\"(?P<url>[^\"]+)[^>]+>dal',data,re.IGNORECASE | re.DOTALL) 
        if next:
            item = self.dir_item()
            item['type'] = 'next'
            item['url'] = next.group('url')
            result.append(item)
        return result


    def resolve(self,item,captcha_cb=None,select_cb=None):
        item = item.copy()        
        util.init_urllib()
        url = self._url(item['url'])
        page = ''
        try:
            opener = urllib2.OpenerDirector()
            opener.add_handler(urllib2.HTTPHandler())
            opener.add_handler(urllib2.UnknownHandler())
            urllib2.install_opener(opener)
            request = urllib2.Request(url)
            request.add_header('User-Agent',util.UA)
            response= urllib2.urlopen(request)
            page = response.read()
            response.close()
        except urllib2.HTTPError, e:
            traceback.print_exc()
            return
        data = util.substr(page,'<form method=post target=\"iframe_dwn\"','</form>')
        action = re.search('action=(?P<url>[^>]+)',data,re.IGNORECASE | re.DOTALL)
        img = re.search('<img src=\"(?P<url>[^\"]+)',data,re.IGNORECASE | re.DOTALL)
        if img and action:
            sessid=[]
            for cookie in re.finditer('(PHPSESSID=[^\;]+)',response.headers.get('Set-Cookie'),re.IGNORECASE | re.DOTALL):
                sessid.append(cookie.group(1))
            # we have to download image ourselves
            image = util.request(self._url(img.group('url')),headers={'Referer':url,'Cookie':sessid[-1]})
            img_file = os.path.join(self.tmp_dir,'captcha.png')
            util.save_data_to_file(image,img_file)
            code = None
            if captcha_cb:
                code = captcha_cb({'id':'0','img':img_file})
            if not code:
                self.info('No captcha received, exit')
                return
            request = urllib.urlencode({'code':code})
            req = urllib2.Request(self._url(action.group('url')),request)
            req.add_header('User-Agent',util.UA)
            req.add_header('Referer',url)
            req.add_header('Cookie',sessid[-1])
            try:
                resp = urllib2.urlopen(req)
                if resp.code == 302:
                    file_url = resp.headers.get('location')
                else:
                    file_url = resp.geturl()
                if file_url.find(action.group('url')) > 0:            
                    msg = resp.read()
                    resp.close()
                    js_msg = re.search('alert\(\'(?P<msg>[^\']+)',msg,re.IGNORECASE | re.DOTALL)
                    if js_msg:
                        raise ResolveException(js_msg.group('msg'))
                    self.error(msg)
                    raise ResolveException('Nelze ziskat soubor, zkuste to znovu')
                resp.close()
                if file_url.find('data') >=0 or file_url.find('download_free') > 0:
                    item['url'] = file_url
                    return item
                self.error('wrong captcha, retrying')
                return self.resolve(item,captcha_cb,select_cb)
            except urllib2.HTTPError:
                traceback.print_exc()
                return
Ejemplo n.º 19
0
 def resolve(self, item, captcha_cb=None, select_cb=None):
     item = item.copy()
     util.init_urllib()
     url = self._url(item['url'])
     page = ''
     try:
         opener = OpenerDirector()
         opener.add_handler(HTTPHandler())
         opener.add_handler(UnknownHandler())
         install_opener(opener)
         request = Request(url)
         request.add_header('User-Agent', util.UA)
         response = urlopen(request)
         page = response.read()
         response.close()
     except HTTPError as e:
         traceback.print_exc()
         return
     data = util.substr(page, '<form method=post target=\"iframe_dwn\"',
                        '</form>')
     action = re.search('action=(?P<url>[^>]+)', data,
                        re.IGNORECASE | re.DOTALL)
     img = re.search('<img src=\"(?P<url>[^\"]+)', data,
                     re.IGNORECASE | re.DOTALL)
     if img and action:
         sessid = []
         for cookie in re.finditer('(PHPSESSID=[^\;]+)',
                                   response.headers.get('Set-Cookie'),
                                   re.IGNORECASE | re.DOTALL):
             sessid.append(cookie.group(1))
         # we have to download image ourselves
         image = util.request(self._url(img.group('url')),
                              headers={
                                  'Referer': url,
                                  'Cookie': sessid[-1]
                              })
         img_file = os.path.join(self.tmp_dir, 'captcha.png')
         util.save_data_to_file(image, img_file)
         code = None
         if captcha_cb:
             code = captcha_cb({'id': '0', 'img': img_file})
         if not code:
             self.info('No captcha received, exit')
             return
         request = urllib.urlencode({'code': code})
         req = Request(self._url(action.group('url')), request)
         req.add_header('User-Agent', util.UA)
         req.add_header('Referer', url)
         req.add_header('Cookie', sessid[-1])
         try:
             resp = urlopen(req)
             if resp.code == 302:
                 file_url = resp.headers.get('location')
             else:
                 file_url = resp.geturl()
             if file_url.find(action.group('url')) > 0:
                 msg = resp.read()
                 resp.close()
                 js_msg = re.search('alert\(\'(?P<msg>[^\']+)', msg,
                                    re.IGNORECASE | re.DOTALL)
                 if js_msg:
                     raise ResolveException(js_msg.group('msg'))
                 self.error(msg)
                 raise ResolveException(
                     'Nelze ziskat soubor, zkuste to znovu')
             resp.close()
             if file_url.find('data') >= 0 or file_url.find(
                     'download_free') > 0:
                 item['url'] = file_url
                 return item
             self.error('wrong captcha, retrying')
             return self.resolve(item, captcha_cb, select_cb)
         except HTTPError:
             traceback.print_exc()
             return
    def _get_file_url_anonymous(self, page, post_url, headers, captcha_cb):

        data = util.request(self._url('reloadXapca.php'))
        capdata = json.loads(data)
        captcha = capdata['image']
        if not captcha.startswith('http'):
            captcha = 'http:' + captcha
        sound = capdata['sound']
        if not sound.startswith('http'):
            sound = 'http:' + sound
        # ask callback to provide captcha code
        self.info('Asking for captcha img %s' % captcha)
        code = captcha_cb({'id': captcha, 'img': captcha, 'snd': sound})
        if not code:
            self.info('Captcha not provided, done')
            return

        ts = re.search(
            '<input type=\"hidden\" name=\"ts\".+?value=\"([^\"]+)"', page,
            re.IGNORECASE | re.DOTALL)
        cid = re.search(
            '<input type=\"hidden\" name=\"cid\".+?value=\"([^\"]+)"', page,
            re.IGNORECASE | re.DOTALL)
        sign = re.search(
            '<input type=\"hidden\" name=\"sign\".+?value=\"([^\"]+)"', page,
            re.IGNORECASE | re.DOTALL)
        sign_a = re.search(
            '<input type=\"hidden\" name=\"sign_a\".+?value=\"([^\"]+)"', page,
            re.IGNORECASE | re.DOTALL)
        has = capdata['hash']
        salt = capdata['salt']
        timestamp = capdata['timestamp']
        token = re.search(
            '<input type=\"hidden\" name=\"_token_\".+?value=\"([^\"]+)"',
            page, re.IGNORECASE | re.DOTALL)
        if not (sign and ts and cid and has and token):
            util.error(
                '[uloz.to] - unable to parse required params from page, plugin needs fix'
            )
            return
        request = {
            'captcha_type': 'xapca',
            'hash': has,
            'salt': salt,
            'timestamp': timestamp,
            'ts': ts.group(1),
            'cid': '',
            'sign': sign.group(1),
            'sign_a': sign_a.group(1),
            'captcha_value': code,
            'do': 'download-freeDownloadTab-freeDownloadForm-submit',
            '_token_': token.group(1),
            'adi': 'f'
        }
        req = urllib2.Request(post_url, urllib.urlencode(request))
        req.add_header('User-Agent', util.UA)
        req.add_header('Referer', post_url)
        req.add_header('Accept', 'application/json')
        req.add_header('X-Requested-With', 'XMLHttpRequest')
        sessid = []
        for cookie in re.finditer('(ULOSESSID=[^\;]+)',
                                  headers.get('Set-Cookie'),
                                  re.IGNORECASE | re.DOTALL):
            sessid.append(cookie.group(1))
        req.add_header(
            'Cookie', 'nomobile=1; uloztoid=' + cid.group(1) + 'uloztoid2=' +
            cid.group(1) + '; ' + sessid[-1])
        util.info(request)
        try:
            resp = urllib2.urlopen(req)
            page = resp.read()
            headers = resp.headers
        except urllib2.HTTPError:
            # this is not OK, something went wrong
            traceback.print_exc()
            util.error(
                '[uloz.to] cannot resolve stream url, server did not redirected us'
            )
            util.info('[uloz.to] POST url:' + post_url)
            return
        try:
            result = json.loads(page)
        except:
            raise ResolveException('Unexpected error, addon needs fix')
        if not 'status' in result.keys():
            raise ResolveException('Unexpected error, addon needs fix')
        if result['status'] == 'ok':
            return self._fix_stream_url(result['url'])
        elif result['status'] == 'error':
            # the only known state is wrong captcha for now
            util.error(
                'Captcha validation failed, please try playing/downloading again'
            )
            util.error(result)
            raise ResolveException('Captcha failed, try again')
Ejemplo n.º 21
0
                        itm['subs'] = self.parent.saveSubtitle(
                            content, 'cs', False)
                        util.debug("[SC] posielam URL na titulky: %s" %
                                   itm['subs'])
                except Exception, e:
                    util.debug("[SC] chyba WS titlkov... %s | %s" %
                               (str(e), str(traceback.format_exc())))
                    pass
                itm['headers'] = {'User-Agent': util.UA}
            except:
                bug.onExceptionRaised()
                pass

        else:
            try:
                raise ResolveException('zatial nic...')
                hmf = urlresolver.HostedMediaFile(url=itm['url'],
                                                  include_disabled=False,
                                                  include_universal=False)
                if hmf.valid_url() is True:
                    try:
                        itm['url'] = hmf.resolve()
                    except:
                        pass
            except:
                pass
        itm['title'] = self.parent.encode(itm['title'])

        return itm

    def resolve(self, item, captcha_cb=None, select_cb=None):