Example #1
0
def setup_addon(addon_id, **kwargs):
    addon, data = merge_info(addon_id)

    if METHOD_PLAYLIST in data:
        playlist, created = Playlist.get_or_create(path=addon_id,
                                                   defaults={
                                                       'source_type':
                                                       Playlist.TYPE_ADDON,
                                                       'enabled': True
                                                   })
        if not playlist.enabled:
            playlist.enabled = True
            playlist.save()

    if METHOD_EPG in data:
        epg, created = EPG.get_or_create(path=addon_id,
                                         defaults={
                                             'source_type': EPG.TYPE_ADDON,
                                             'enabled': True
                                         })
        if not epg.enabled:
            epg.enabled = True
            epg.save()

    if 'configure' in data:
        path = data['configure'].replace('$ID', addon_id)
        run_plugin(path, wait=True)

    _setup(reinstall=False, run_merge=True)
Example #2
0
    def _manifest_middleware(self, data):
        url = self._session.get('manifest_middleware')
        if not url:
            return data

        data_path = xbmc.translatePath('special://temp/proxy.manifest')
        with open(data_path, 'wb') as f:
            f.write(data.encode('utf8'))

        url = add_url_args(url,
                           _data_path=data_path,
                           _headers=json.dumps(self._headers))

        log.debug('PLUGIN MANIFEST MIDDLEWARE REQUEST: {}'.format(url))
        dirs, files = run_plugin(url, wait=True)
        if not files:
            raise Exception('No data returned from plugin')

        path = unquote_plus(files[0])
        split = path.split('|')
        data_path = split[0]

        if len(split) > 1:
            self._plugin_headers = dict(
                parse_qsl(u'{}'.format(split[1]), keep_blank_values=True))

        with open(data_path, 'rb') as f:
            data = f.read().decode('utf8')

        if not ADDON_DEV:
            remove_file(data_path)

        return data
Example #3
0
    def _plugin_request(self, url):
        log.debug('PLUGIN REQUEST: {}'.format(url))
        dirs, files = run_plugin(url, wait=True)
        if not files:
            raise Exception('No data returned from plugin')

        data = json.loads(unquote_plus(files[0]))
        self._headers.update(data.get('headers', {}))
        return data['url']
    def _call_addon_method(self, plugin_url):
        dirs, files = run_plugin(plugin_url, wait=True)

        if not files:
            raise AddonError('Plugin method failed')

        result, msg = int(files[0][0]), unquote_plus(files[0][1:])
        if not result:
            raise AddonError(msg)
Example #5
0
def setup_addon(addon_id, **kwargs):
    if not iptv_is_setup() and not _setup():
        return

    addon, data = merge_info(addon_id)

    if METHOD_PLAYLIST in data:
        playlist, created = Playlist.get_or_create(path=addon_id, defaults={'source_type': Playlist.TYPE_ADDON, 'enabled': True})
        if not playlist.enabled:
            playlist.enabled = True
            playlist.save()

    if METHOD_EPG in data:
        epg, created = EPG.get_or_create(path=addon_id, defaults={'source_type': EPG.TYPE_ADDON, 'enabled': True})
        if not epg.enabled:
            epg.enabled = True
            epg.save()

    if 'configure' in data:
        path = data['configure'].replace('$ID', addon_id)
        run_plugin(path, wait=True)

    set_kodi_string('_iptv_merge_force_run', '1')
Example #6
0
def middleware_plugin(response, url, **kwargs):
    path = 'special://temp/proxy.middleware'
    real_path = xbmc.translatePath(path)
    with open(real_path, 'wb') as f:
        f.write(response.stream.content)

    if ADDON_DEV:
        shutil.copy(real_path, real_path + '.in')

    url = add_url_args(url, _path=path)
    dirs, files = run_plugin(url, wait=True)
    if not files:
        raise Exception('No data returned from plugin')

    data = json.loads(unquote_plus(files[0]))
    with open(real_path, 'rb') as f:
        response.stream.content = f.read()

    response.headers.update(data.get('headers', {}))
    if ADDON_DEV:
        shutil.copy(real_path, real_path + '.out')

    remove_file(real_path)
Example #7
0
    def _plugin_request(self, url):
        data_path = xbmc.translatePath('special://temp/proxy.post')
        with open(data_path, 'wb') as f:
            f.write(self._post_data or b'')

        url = add_url_args(url,
                           _data_path=data_path,
                           _headers=json.dumps(self._headers))

        log.debug('PLUGIN REQUEST: {}'.format(url))
        dirs, files = run_plugin(url, wait=True)
        if not files:
            raise Exception('No data returned from plugin')

        path = unquote_plus(files[0])
        split = path.split('|')
        url = split[0]

        if len(split) > 1:
            self._plugin_headers = dict(
                parse_qsl(u'{}'.format(split[1]), keep_blank_values=True))

        return url
Example #8
0
def configure_addon(addon_id, **kwargs):
    addon, data = merge_info(addon_id)
    if 'configure' in data:
        path = data['configure'].replace('$ID', addon_id)
        run_plugin(path, wait=True)
    def select_path(self, creating=False):
        try:
            default = self.TYPES.index(self.source_type)
        except:
            default = -1

        index = gui.select(_.SELECT_SOURCE_TYPE,
                           [self.TYPE_LABELS[x] for x in self.TYPES],
                           preselect=default)
        if index < 0:
            return False

        orig_source_type = self.source_type
        self.source_type = self.TYPES[index]

        if self.source_type == self.TYPE_ADDON:
            addons = self.get_addon_sources()
            if not addons:
                raise Error(_.NO_SOURCE_ADDONS)

            options = []
            default = -1
            addons.sort(key=lambda x: x[0].getAddonInfo('name').lower())

            for idx, row in enumerate(addons):
                options.append(
                    plugin.Item(label=row[0].getAddonInfo('name'),
                                art={'thumb': row[0].getAddonInfo('icon')}))
                if orig_source_type == self.TYPE_ADDON and row[0].getAddonInfo(
                        'id') == self.path:
                    default = idx

            index = gui.select(_.SELECT_SOURCE_ADDON,
                               options,
                               preselect=default,
                               useDetails=True)
            if index < 0:
                return False

            addon, data = addons[index]
            self.path = addon.getAddonInfo('id')
        elif self.source_type == self.TYPE_URL:
            self.path = gui.input(_.ENTER_SOURCE_URL,
                                  default=self.path if orig_source_type
                                  == self.TYPE_URL else '').strip()
        elif self.source_type == self.TYPE_FILE:
            self.path = xbmcgui.Dialog().browseSingle(
                1,
                _.SELECT_SOURCE_FILE,
                '',
                '',
                defaultt=self.path
                if orig_source_type == self.TYPE_FILE else '')
        elif self.source_type == self.TYPE_CUSTOM:
            self.path = gui.input('Custom Name',
                                  default=self.path if orig_source_type
                                  == self.TYPE_CUSTOM else '').strip()

        if not self.path:
            return False

        self.save()

        if self.source_type == self.TYPE_ADDON:
            if creating:
                if self.__class__ == Playlist and METHOD_EPG in data:
                    epg = EPG(source_type=EPG.TYPE_ADDON, path=self.path)
                    try:
                        epg.save()
                    except:
                        pass

                elif self.__class__ == EPG and METHOD_PLAYLIST in data:
                    playlist = Playlist(source_type=Playlist.TYPE_ADDON,
                                        path=self.path)
                    try:
                        playlist.save()
                    except:
                        pass

            for key in data.get('settings', {}):
                value = data['settings'][key].replace('$ID', self.path)
                log.debug('Set setting {}={} for addon {}'.format(
                    key, value, self.path))
                addon.setSetting(key, value)

            if 'configure' in data:
                path = data['configure'].replace('$ID', self.path)
                run_plugin(path, wait=True)

        return True