Example #1
0
    def play(self):
        # find a working mirror
        try:
            res = StreamcloudResolver()
            file_url = None

            mirror_count = 1
            switch = False
            x = 1

            while x <= mirror_count:
                url = res.get_mirror_url(self.get('title'), x,
                                         self.get('season'),
                                         self.get('episode'))
                obj = http.get(url)

                if obj is not None and 'Stream' in obj:
                    m = re.search('<a href="(.+?)"', str(obj['Stream']))
                    file_url = res.get_media_url(m.group(1))

                    if res.canceled is True:
                        raise Exception('CANCELED')

                    if file_url is None and switch is False:
                        c = re.search('<b>Mirror</b>: \d+/(\d+)',
                                      str(obj['Replacement']))

                        if c:
                            mirror_count = int(c.group(1))
                        switch = True

                if file_url:
                    self.play_video(file_url)
                    break

                x += 1

            if not file_url:
                raise Exception('FILE_NOT_FOUND')

        except Exception, e:
            print 'StreamCloud Error occurred: %s' % e

            if str(e) == 'FILE_NOT_FOUND':
                http.post(
                    "%s/report.php" % const.SERVICE_URL, {
                        'type': 'unknown',
                        'title': self.get('title'),
                        'message': '404'
                    })
                dialog = xbmcgui.Dialog()
                dialog.ok("StreamCloud", "File Not Found or removed")
    def get_media_url(self, params):
        try:
            res = StreamcloudResolver()
            file_url = None

            mirror_count = 1
            switch = False
            x = 1

            while x <= mirror_count:
                url = res.get_mirror_url(params('title'), x, params('season'),  params('episode'))
                obj = http.get(url)

                if obj is not None and 'Stream' in obj:
                    m = re.search('<a href="(.+?)"', str(obj['Stream']))
                    file_url = res.get_media_url(m.group(1))

                    if res.canceled is True:
                        raise Exception('CANCELED')

                    if file_url is None and switch is False:
                        c = re.search('<b>Mirror</b>: \d+/(\d+)', str(obj['Replacement']))

                        if c:
                            mirror_count = int(c.group(1))
                        switch = True

                if file_url:
                    return file_url

                x += 1

            if not file_url:
                raise Exception('FILE_NOT_FOUND')

        except Exception, e:
            print 'StreamCloud Error occurred: %s' % e

            if str(e) == 'FILE_NOT_FOUND':
                dialog = xbmcgui.Dialog()
                dialog.ok("StreamCloud", "File Not Found or removed")