def wizard(self):
        types = [self.TYPE_REMOTE, self.TYPE_LOCAL, self.TYPE_ADDON]
        options = [_.REMOTE_PATH, _.LOCAL_PATH, _.ADDON_SOURCE]
        default = self.path_type or self.TYPE_REMOTE

        index = gui.select(_.CHOOSE, options, preselect=types.index(default))
        if index < 0:
            return False

        self.path_type = types[index]

        if self.path_type == self.TYPE_ADDON:
            addons = self._get_merge_addons()
            if not addons:
                raise Error(_.NO_ADDONS)

            ids = [x['id'] for x in addons]
            options = [x['name'] for x in addons]

            try:
                default = ids.index(self.path)
            except ValueError:
                default = 0

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

            self.path = ids[index]
            self.file_type = self.FILE_STANDARD

            return True

        elif self.path_type == self.TYPE_REMOTE:
            self.path = gui.input(_.URL, default=self.path)
        elif self.path_type == self.TYPE_LOCAL:
            self.path = xbmcgui.Dialog().browseSingle(1, _.BROWSE_FILE,
                                                      self.path or '', '')

        if not self.path:
            return False

        types = [self.FILE_STANDARD, self.FILE_GZIP]
        options = [_.STANDARD_FILE, _.GZIPPED_FILE]
        default = self.file_type or (self.FILE_GZIP if self.path.endswith(
            '.gz') else self.FILE_STANDARD)

        index = gui.select(_.CHOOSE, options, preselect=types.index(default))
        if index < 0:
            return False

        self.file_type = types[index]

        return True
def get_tvg_id(channel):
    epg_channels = load_epg_channels()

    channel_epgs = []
    for row in Channels().channel_list():
        tvg_id = row.get('tvg-id')
        if tvg_id:
            channel_epgs.append(tvg_id)

    tvg_id = channel.get('tvg-id', '')
    name = channel.get('_name').lower().strip()
    best_match = None
    values = []
    labels = []

    for key in sorted(epg_channels.keys()):
        values.append(key)
        names = ' / '.join(epg_channels[key]).strip()
        label = _(_.EPG_ID_LABEL, epg_id=key, names=names)

        if key == tvg_id:
            label = _(_.CURRENT_EPG, label=label)
        elif key in channel_epgs:
            label = _(_.ASSIGNED_EPG, label=label)

        labels.append(label)

        for value in epg_channels[key]:
            ratio = SequenceMatcher(None, name,
                                    value.lower().strip()).quick_ratio()
            if not best_match or ratio > best_match[0]:
                best_match = [ratio, key]

    labels.append(_.CUSTOM_EPG)
    values.append(None)

    if best_match and best_match[1] != tvg_id:
        index = values.index(best_match[1])
        labels[index] = _(_.BEST_MATCH_EPG, label=labels[index])

    if tvg_id:
        try:
            default = values.index(tvg_id)
        except:
            default = len(values) - 1
    else:
        if best_match:
            default = values.index(best_match[1])
        else:
            default = 0

    index = gui.select(_.SET_CHANNEL_ID, labels, preselect=default)
    if index < 0:
        return None

    value = values[index]
    if value == None:
        value = gui.input(_.CUSTOM_EPG, default=tvg_id)

    return value
Exemplo n.º 3
0
def _select_profile():
    profiles = api.profiles()
    profiles.append({'id': None, 'name': _.NO_PROFILE})

    index = gui.select(_.SELECT_PROFILE, options=[p['name'] for p in profiles])
    if index < 0:
        return

    userdata.set('profile', profiles[index]['id'])