Ejemplo n.º 1
0
def connect_openvpn(config, sudopassword=None):
    Script.log('OpenVPN: Connecting OpenVPN configuration: [%s]' % config)

    if Script.setting.get_boolean('vpn.sudo') and \
            Script.setting.get_boolean('vpn.sudopsw') and sudopassword is None:

        keyboard = xbmc.Keyboard()
        keyboard.setHeading(Script.localize(30353))
        keyboard.setHiddenInput(True)
        keyboard.doModal()
        if keyboard.isConfirmed():
            sudopassword = keyboard.getText()
        else:
            return

    openvpn = vpnlib.OpenVPN(
        Script.setting.get_string('vpn.openvpnfilepath'),
        config,
        ip=IP,
        port=PORT,
        args=Script.setting.get_string('vpn.args'),
        sudo=Script.setting.get_boolean('vpn.sudo'),
        sudopwd=sudopassword)

    try:
        openvpn.connect()
        Script.notify(
            "OpenVPN",
            Script.localize(30354),
            display_time=3000)
    except Exception as e:
        xbmcgui.Dialog().ok(
            'OpenVPN',
            Script.localize(30358))
        Script.log('OpenVPN: OpenVPN error: ' + str(e))
def getKeyboardText(heading, default='', hidden=False):
    kb = xbmc.Keyboard(default, heading)
    kb.setHiddenInput(hidden)
    kb.doModal()
    if (kb.isConfirmed()):
        return kb.getText()
    return False
Ejemplo n.º 3
0
def search_type(field):
    last_field = settings.getSetting('last_search_field')
    search_text = settings.getSetting('last_search_text')
    if last_field != field or not search_text:
        settings.setSetting('last_search_field', field)
        keyboard = xbmc.Keyboard('', _T(Msg.i30206))
        keyboard.doModal()
        if keyboard.isConfirmed():
            search_text = keyboard.getText()
        else:
            search_text = ''
    settings.setSetting('last_search_text', search_text)
    if search_text:
        searchresults = session.search(field, search_text)
        add_items(searchresults.artists,
                  content=CONTENT_FOR_TYPE.get('files'),
                  end=False)
        add_items(searchresults.albums, end=False)
        add_items(searchresults.playlists, end=False)
        add_items(searchresults.tracks, end=False)
        add_items(searchresults.videos, end=True)
    else:
        #xbmcplugin.setContent(plugin.handle, content='files')
        xbmcplugin.endOfDirectory(plugin.handle,
                                  succeeded=False,
                                  updateListing=False)
Ejemplo n.º 4
0
def import_ovpn(*args, **kwargs):
    path = xbmcgui.Dialog().browse(1,
                                   Script.localize(30342),
                                   'files',
                                   mask='.ovpn|.conf',
                                   enableMultiple=False)

    if path and os.path.exists(path) and os.path.isfile(path):
        Script.log('OpenVPN: Import: [%s]' % path)

        keyboard = xbmc.Keyboard(default='',
                                 heading=Script.localize(30348),
                                 hidden=False)
        keyboard.doModal()
        if keyboard.isConfirmed() and len(keyboard.getText()) > 0:
            name = keyboard.getText()

            ovpnfiles = {}
            with storage.PersistentDict('vpn') as db:
                ovpnfiles = db['ovpnfiles']
                db.flush()

            if name in ovpnfiles and not xbmcgui.Dialog().yesno(
                    'OpenVPN', Script.localize(30349)):
                xbmcgui.Dialog().ok('OpenVPN', Script.localize(30350))

            else:
                ovpnfiles[name] = path
                with storage.PersistentDict('vpn') as db:
                    db['ovpnfiles'] = ovpnfiles
                    db.flush()
        else:
            xbmcgui.Dialog().ok('OpenVPN', Script.localize(30351))
Ejemplo n.º 5
0
def _get_keyboard(default="", heading="", hidden=False):
    """ shows a keyboard and returns a value """
    keyboard = xbmc.Keyboard(default, heading, hidden)
    keyboard.doModal()
    if keyboard.isConfirmed():
        return keyboard.getText().encode("utf8") if PY2 else keyboard.getText()
    return default
Ejemplo n.º 6
0
def search_fuzzy_edit():
    try:
        params = eval(settings.getSetting('search_parameters'))
        params.update({'search': ''})
    except:
        log.error('Search Parameters not set !')
        return
    cmds = [
        ('search', _S(Msg.i30400)),
        ('artist', _T('artist') + ': '),
        ('title', _T('track') + ': '),
        ('album', _T('album') + ': '),
        ('albumartist', _S(Msg.i30402) + ': '),
        ('year', _S(Msg.i30403) + ': '),
    ]
    answer = 1
    while answer > 0:
        menue = [
            '%s%s' % (FOLDER_MASK % s_head, params.get(s_key))
            for s_key, s_head in cmds
        ]
        answer = xbmcgui.Dialog().select(_S(Msg.i30400), menue)
        if answer > 0:
            keyboard = xbmc.Keyboard(params.get(cmds[answer][0]),
                                     cmds[answer][1])
            keyboard.doModal()
            if keyboard.isConfirmed():
                value = keyboard.getText()
                params.update({cmds[answer][0]: value})
    if answer == 0:
        settings.setSetting('search_parameters', repr(params))
        xbmc.executebuiltin('Container.Refresh()')
    pass
Ejemplo n.º 7
0
def get_keyboard_input():
    kb = xbmc.Keyboard('', L('Bitte Suchwort(e) eingeben'))
    kb.doModal()  # Onscreen keyboard
    if kb.isConfirmed() == False:
        return ""
    inp = kb.getText()  # User Eingabe
    return inp
Ejemplo n.º 8
0
def connect_openvpn(config, restart=False, sudopassword=None):
    with storage.PersistentDict('vpn') as db:
        Script.log('OpenVPN: Connecting OpenVPN configuration: [%s]' % config)

        if Script.setting.get_boolean('vpn.sudo') and \
                Script.setting.get_boolean('vpn.sudopsw') and sudopassword is None:

            keyboard = xbmc.Keyboard(default='',
                                     heading=Script.localize(
                                         LABELS['Enter your sudo password']),
                                     hidden=True)
            keyboard.doModal()
            if keyboard.isConfirmed():
                sudopassword = keyboard.getText()

        openvpn = vpnlib.OpenVPN(
            Script.setting.get_string('vpn.openvpnfilepath'),
            config,
            ip=ip,
            port=port,
            args=Script.setting.get_string('vpn.args'),
            sudo=Script.setting.get_boolean('vpn.sudo'),
            sudopwd=sudopassword,
            debug=True)

        try:
            if restart:
                openvpn.disconnect()
                db['status'] = "disconnected"
            openvpn.connect()
            Script.notify("OpenVPN",
                          Script.localize(LABELS['Started VPN connection']),
                          display_time=3000)

            db['status'] = "connected"
        except vpnlib.OpenVPNError as exception:
            if exception.errno == 1:
                db['status'] = "connected"

                if xbmcgui.Dialog().yesno(
                        'OpenVPN',
                        Script.localize(LABELS[
                            'An existing OpenVPN instance appears to be running.']
                                        ),
                        Script.localize(LABELS['Disconnect it?'])):

                    Script.log('OpenVPN: User has decided to restart OpenVPN')
                    connect_openvpn(config, True, sudopassword)
                else:
                    Script.log(
                        'OpenVPN: User has decided not to restart OpenVPN')
            else:
                xbmcgui.Dialog().ok(
                    'OpenVPN',
                    Script.localize(LABELS[
                        'An error has occurred while trying to connect OpenVPN']
                                    ))
                db['status'] = "failed"
        db.flush()
Ejemplo n.º 9
0
 def buildSearch(self, tunerkey='All'):
     log('buildSearch')
     self.setDevice(tunerkey)
     kb = xbmc.Keyboard('', LANGUAGE(30109)%ADDON_NAME)
     xbmc.sleep(500)
     kb.doModal()
     if kb.isConfirmed():
         self.browseSearch(kb.getText(),tunerkey)
Ejemplo n.º 10
0
def get_playlist_title(line):
    keyboard = xbmc.Keyboard(line, i18n('Enter a playlist title'))
    keyboard.doModal()
    if keyboard.isConfirmed():
        playlist_title = keyboard.getText()
        playlist_title = playlist_title.strip()
        return playlist_title
    return ''
Ejemplo n.º 11
0
def searchUser():
    keyboard = xbmc.Keyboard('', translation(30002) + ' ' + translation(30007))
    keyboard.doModal()
    if keyboard.isConfirmed() and keyboard.getText():
        searchl_string = urllib_parse.quote_plus(keyboard.getText())
        listUsers(
            "{0}/users?fields=username,avatar_large_url,videos_total,views_total&search={1}&limit={2}&family_filter={3}&localization={4}&page=1"
            .format(urlMain, searchl_string, itemsPerPage, familyFilter,
                    language))
Ejemplo n.º 12
0
    def get_user_input():
        kb = xbmc.Keyboard(
            '', 'Search for Movies/TV Shows/Trailers/Videos in all languages')
        kb.doModal()  # Onscreen keyboard appears
        if not kb.isConfirmed():
            return

        # User input
        return kb.getText()
Ejemplo n.º 13
0
def search():  #8
    keyb = xbmc.Keyboard('', 'Search')
    keyb.doModal()
    if keyb.isConfirmed():
        search = urllib.quote_plus(keyb.getText())
        url = BASEURL + "search/{}" + search
        get_content(url)
    else:
        return
def authorize_addon():
    # type: () -> None
    """
    Authorize the addon on TVmaze

    The function sends authorization request to TVmaze and saves TVmaze
    username and API token for scrobbling requests authorization
    """
    if tvmaze.is_authorized() and not gui.DIALOG.yesno(
            kodi.ADDON_NAME,
            _('The addon is already authorized.[CR]Authorize again?')):
        return
    keyboard = xbmc.Keyboard()
    keyboard.setHeading(_('Your TVmaze account email'))
    keyboard.doModal()
    if keyboard.isConfirmed():
        email = keyboard.getText()
        if re.search(r'^[\w.\-+]+@[\w.-]+\.[\w]+$', email) is None:
            logger.error('Invalid email: {}'.format(email))
            gui.DIALOG.notification(kodi.ADDON_NAME,
                                    _('Invalid email'),
                                    icon='error',
                                    time=3000)
            return
        try:
            token, confirm_url = tvmaze.start_authorization(email)
        except tvmaze.AuthorizationError as exc:
            message = _('Authorization error: {}').format(exc)
            logger.error(message)
            gui.DIALOG.notification(kodi.ADDON_NAME, message, icon='error')
            return
        qrcode_path = _create_and_save_qrcode(confirm_url)
        confirmation_dialog = gui.ConfirmationDialog(email, token, confirm_url,
                                                     qrcode_path)
        confirmation_dialog.doModal()
        if confirmation_dialog.is_confirmed:
            kodi.ADDON.setSettingString('username',
                                        confirmation_dialog.username)
            kodi.ADDON.setSettingString('apikey', confirmation_dialog.apikey)
            gui.DIALOG.notification(
                kodi.ADDON_NAME,
                _('Addon has been authorized successfully'),
                icon=kodi.ADDON_ICON,
                sound=False,
                time=3000)
            if gui.DIALOG.yesno(
                    kodi.ADDON_NAME,
                    _('Do you want to sync your TV shows with TVmaze now?')):
                sync_all_episodes()
        elif confirmation_dialog.error_message is not None:
            logger.error('Confirmation error: {}'.format(
                confirmation_dialog.error_message))
            message = _('Confirmation error: {}').format(
                confirmation_dialog.error_message)
            gui.DIALOG.notification(kodi.ADDON_NAME, message, icon='error')
        del confirmation_dialog
Ejemplo n.º 15
0
def searchLive():
    keyboard = xbmc.Keyboard(
        '', '{0} {1}'.format(translation(30002), translation(30003)))
    keyboard.doModal()
    if keyboard.isConfirmed() and keyboard.getText():
        searchl_string = urllib_parse.quote_plus(keyboard.getText())
        listLive(
            "{0}/videos?fields=id,thumbnail_large_url,title,views_last_hour&live_onair=1&search={1}&limit={2}&family_filter={3}&localization={4}&page=1"
            .format(urlMain, searchl_string, itemsPerPage, familyFilter,
                    language))
def search(url):
    keyboard = xbmc.Keyboard('', i18n('Search...'))
    keyboard.setHeading(i18n('Enter search term'))
    keyboard.doModal()
    if keyboard.isConfirmed():
        text = keyboard.getText()
        LOG.debug('Search term input: %s' % text)
        return url + '&query=' + quote(text)

    return None
Ejemplo n.º 17
0
def get_keyboard(heading, default='', hidden=False):
    keyboard = xbmc.Keyboard()
    if hidden: keyboard.setHiddenInput(True)
    keyboard.setHeading(heading)
    if default: keyboard.setDefault(default)
    keyboard.doModal()
    if keyboard.isConfirmed():
        return keyboard.getText()
    else:
        return None
Ejemplo n.º 18
0
def youtube():
    query = plugin.args['q'][0]
    kb = xbmc.Keyboard(query, 'Search')
    kb.doModal()
    if kb.isConfirmed():
        edited_query = kb.getText()
        if edited_query:
            url = "plugin://plugin.video.youtube/kodion/search/query/?q=" + \
                  quote_plus(edited_query)
            xbmc.executebuiltin('Container.Update(\"%s\")' % url)
Ejemplo n.º 19
0
    def search(self, query=None):
        if not self.chk_login():
            self.login()

        search_text = ""
        if query is None:
            keyb = xbmc.Keyboard("", self.LB_SEARCH_DESC)
            keyb.doModal()
            if keyb.isConfirmed():
                search_text = py2_encode(keyb.getText())
        else:
            self.force_original_names = False
            search_text = py2_encode(query)

        if search_text == "":
            xbmcgui.Dialog().notification(
                self.LB_SEARCH_NORES, self.LB_ERROR,
                self.get_media_resource('search.png'))
        else:
            if query is None:
                self.add_to_search_history(search_text)
            self.log("Performing search: " + self.API_URL_SEARCH +
                     quote(search_text))
            response = self.get_from_hbogo(
                self.API_URL_SEARCH + quote(search_text) + "&max=30&offset=0",
                'xml')
            if response is False:
                return
            count = 0

            for item in response.findall('.//item'):
                count += 1
                item_link = item.find('link').text

                if item_link:
                    if self.lograwdata:
                        self.log(ET.tostring(item, encoding='utf8'))
                    item_type = py2_encode(
                        item.find('clearleap:itemType',
                                  namespaces=self.NAMESPACES).text)
                    if item_type != 'media':
                        self.addDir(item)
                    elif item_type == 'media':
                        self.addLink(item, HbogoConstants.ACTION_PLAY)
                    else:
                        self.log('Unknown item type: ' + item_type)

            if count == 0:
                # No result
                xbmcgui.Dialog().notification(
                    self.LB_SEARCH_NORES, self.LB_ERROR,
                    self.get_media_resource('search.png'))

        KodiUtil.endDir(self.handle, self.decide_media_type())
Ejemplo n.º 20
0
def _get_search_query():
    text = ''
    keyboard = xbmc.Keyboard('', i18n('Search...'))
    keyboard.setHeading(i18n('Enter search term'))
    keyboard.doModal()
    if keyboard.isConfirmed():
        text = keyboard.getText()
        if not text.strip():
            return ''
    LOG.debug('Search term input: %s' % text)
    return text.strip()
Ejemplo n.º 21
0
def search(url):
    keyboard = xbmc.Keyboard('', translation(30002))
    keyboard.doModal()
    if keyboard.isConfirmed() and keyboard.getText():
        search_string = urllib_parse.quote_plus(keyboard.getText())
        url2 = url.replace("&search=", "&search=" + str(search_string))
        listVideos(url2)
        addtoHistory({
            'name': keyboard.getText(),
            'url': urllib_parse.quote_plus(url2),
            'mode': 'listVideos'
        })
Ejemplo n.º 22
0
def renameUser():
    cur_user = loadUser()['name']
    users, sel = selectUser()
    if sel > -1:
        keyboard = xbmc.Keyboard(users[sel]['name'], getString(30135))
        keyboard.doModal()
        if keyboard.isConfirmed() and keyboard.getText():
            usr = keyboard.getText()
            if users[sel]['name'] == cur_user:
                var.addon.setSetting('login_acc', usr)
                xbmc.executebuiltin('Container.Refresh')
            users[sel]['name'] = usr
            writeConfig('accounts.lst', json.dumps(users))
Ejemplo n.º 23
0
def get_keyboard_legacy(heading, default='', hide_input=False):

    keyboard = xbmc.Keyboard(hidden=hide_input)
    keyboard.setHeading(heading)

    if default:
        keyboard.setDefault(default)

    keyboard.doModal()

    if keyboard.isConfirmed():
        return keyboard.getText()
    else:
        return None
Ejemplo n.º 24
0
def search_field_edit():
    try:
        params = eval(settings.getSetting('search_parameters_field'))
        params.update({'search': ''})
    except:
        log.error('Search Parameters not set !')
        return
    s_text = params.get('text')
    keyboard = xbmc.Keyboard(s_text, _S(Msg.i30401))
    keyboard.doModal()
    if keyboard.isConfirmed():
        value = py2_decode(keyboard.getText())
        params.update({'text': value})
        settings.setSetting('search_parameters_field', repr(params))
        xbmc.executebuiltin('Container.Refresh()')
Ejemplo n.º 25
0
def search_page():
    """Display a search dialog, then the results"""

    kb = xbmc.Keyboard()
    kb.doModal()
    if kb.isConfirmed():
        # Enable more viewtypes
        xbmcplugin.setContent(addon_handle, 'videos')

        search_string = kb.getText()
        url = 'https://data.jw-api.org/search/query?'
        query = urlencode({
            'q': search_string,
            'lang': global_lang,
            'limit': 24
        })

        try:
            token = addon.getSetting(SettingID.TOKEN)
            if not token:
                raise RuntimeError

            headers = {'Authorization': 'Bearer ' + token}
            data = get_json(Request(url + query, headers=headers),
                            catch_401=False)

        except (HTTPError, RuntimeError):
            # Get and save new token
            log('requesting new authentication token from jw.org',
                xbmc.LOGINFO)
            token_url = 'https://tv.jw.org/tokens/web.jwt'
            token = urlopen(token_url).read().decode('utf-8')
            if not token:
                raise RuntimeError('failed to get search authentication token')

            addon.setSetting(SettingID.TOKEN, token)

            headers = {'Authorization': 'Bearer ' + token}
            data = get_json(Request(url + query, headers=headers))

        for hd in data['hits']:
            media = Media()
            media.parse_hits(hd)
            if media.url:
                media.add_item_in_kodi()

        xbmcplugin.endOfDirectory(addon_handle)
Ejemplo n.º 26
0
def addFav():
    keyboard = xbmc.Keyboard('', translation(30033))
    keyboard.doModal()
    if keyboard.isConfirmed() and keyboard.getText():
        user = keyboard.getText()
        channelEntry = "###USER###={0}###THUMB###=###END###".format(user)
        if xbmcvfs.exists(channelFavsFile):
            with open(channelFavsFile, 'r') as fh:
                content = fh.read()
            if content.find(channelEntry) == -1:
                with open(channelFavsFile, 'a') as fh:
                    fh.write(channelEntry + "\n")
        else:
            with open(channelFavsFile, 'a') as fh:
                fh.write(channelEntry + "\n")
        xbmcgui.Dialog().notification('Info:', translation(30030), _icon, 5000,
                                      False)
Ejemplo n.º 27
0
    def search(self):
        if not self.chk_login():
            self.login()
        keyb = xbmc.Keyboard(self.search_string, self.LB_SEARCH_DESC)
        keyb.doModal()
        if keyb.isConfirmed():
            search_text = quote(keyb.getText())
            if search_text == "":
                self.addCat(self.LB_SEARCH_NORES, self.LB_SEARCH_NORES,
                            self.get_media_resource('DefaultFolderBack.png'),
                            '')
            else:
                self.addon.setSetting('lastsearch', search_text)
                self.log("Performing search: " +
                         str(self.API_URL_SEARCH + py2_encode(search_text)))
                response = self.get_from_hbogo(
                    str(self.API_URL_SEARCH + py2_encode(search_text)) +
                    "&max=30&offset=0", 'xml')

                count = 0

                for item in response.findall('.//item'):
                    count += 1
                    item_link = item.find('link').text

                    if item_link:
                        if self.lograwdata:
                            self.log(ET.tostring(item, encoding='utf8'))
                        item_type = py2_encode(
                            item.find('clearleap:itemType',
                                      namespaces=self.NAMESPACES).text)
                        if item_type != 'media':
                            self.addDir(item)
                        elif item_type == 'media':
                            self.addLink(item, HbogoConstants.ACTION_PLAY)
                        else:
                            self.log('Unknown item type: ' + item_type)

                if count == 0:
                    # No result
                    self.addCat(
                        self.LB_SEARCH_NORES, self.LB_SEARCH_NORES,
                        self.get_media_resource('DefaultFolderBack.png'), '')

        KodiUtil.endDir(self.handle, self.use_content_type)
Ejemplo n.º 28
0
def rename_system(system_key):
    system = util.get_system(system_key)
    if not system:
        return

    kb = xbmc.Keyboard()
    kb.setHeading('Rename system')
    kb.setDefault(system.get('name', ''))
    kb.doModal()
    if not kb.isConfirmed():
        return

    new_name = kb.getText()
    name = system.get('name', '')
    icon = system.get('icon', xbmcgui.NOTIFICATION_INFO)

    util.update_system(system_key, {'name': new_name})
    xbmc.executebuiltin('Container.Refresh')
Ejemplo n.º 29
0
def import_ovpn(*args, **kwargs):
    path = xbmcgui.Dialog().browse(
        1,
        Script.localize(LABELS['Import OpenVPN configuration file']),
        'files',
        mask='.ovpn|.conf',
        enableMultiple=False)

    if path and os.path.exists(path) and os.path.isfile(path):
        Script.log('OpenVPN: Import: [%s]' % path)

        keyboard = xbmc.Keyboard(
            default='',
            heading=Script.localize(
                LABELS['Choose a name for OpenVPN configuration']),
            hidden=False)
        keyboard.doModal()
        if keyboard.isConfirmed() and len(keyboard.getText()) > 0:
            name = keyboard.getText()

            ovpnfiles = {}
            with storage.PersistentDict('vpn') as db:
                ovpnfiles = db['ovpnfiles']
                db.flush()

            if name in ovpnfiles and not xbmcgui.Dialog().yesno(
                    'OpenVPN',
                    Script.localize(LABELS[
                        'This OpenVPN configuration name already exists. Overwrite?']
                                    )):
                xbmcgui.Dialog().ok(
                    'OpenVPN', Script.localize(LABELS['Import cancelled']))

            else:
                ovpnfiles[name] = path
                with storage.PersistentDict('vpn') as db:
                    db['ovpnfiles'] = ovpnfiles
                    db.flush()
        else:
            xbmcgui.Dialog().ok(
                'OpenVPN',
                Script.localize(LABELS[
                    'Import failed. You must specify a name for the OpenVPN configuration']
                                ))
def run(context, url, prompt):
    """
        When we encounter a search request, branch off to this function to generate the keyboard
        and accept the terms.  This URL is then fed back into the correct function for
        onward processing.
    """
    context.plex_network = plex.Plex(context.settings, load=True)

    if prompt:
        prompt = unquote(prompt)
    else:
        prompt = i18n('Enter search term')

    keyboard = xbmc.Keyboard('', i18n('Search...'))
    keyboard.setHeading(prompt)
    keyboard.doModal()
    if keyboard.isConfirmed():
        text = keyboard.getText()
        LOG.debug('Search term input: %s' % text)
        url = url + '&query=' + quote(text)
        process_plex_plugins(context, url)