def search(params): """ Search on ex.ua params: original_id (optional) """ listing = [] keyboard = xbmc.Keyboard('', _('Search query')) keyboard.doModal() search_text = keyboard.getText() if keyboard.isConfirmed() and search_text: search_path = '/search?s={0}'.format(urllib.quote_plus(search_text)) if params.get('original_id'): search_path += '&original_id={0}'.format(params['original_id']) if plugin.cache_pages: results = _get_media_list(search_path, 0, plugin.itemcount) else: results = exua.get_media_list(search_path, 0, plugin.itemcount) plugin.log_debug('Search results: {0}'.format(results)) if results.media: listing = _media_list(search_path, results, is_search_result=True) if plugin.savesearch: with plugin.get_storage('__history__.pcl') as storage: history = storage.get('history', []) history.insert(0, SearchQuery(search_text, search_path)) if len(history) > plugin.historylength: history.pop(-1) storage['history'] = history else: dialog.ok(_('No results found'), _('Refine your search and try again')) return plugin.create_listing(listing, cache_to_disk=True)
def media_list(params): """ Display the list of videos params: path, page """ page = int(params['page']) if plugin.cache_pages: media_listing = _get_media_list(params['path'], page, plugin.itemcount) else: media_listing = exua.get_media_list(params['path'], page, plugin.itemcount) plugin.log_debug('Media list: {0}'.format(media_listing)) return plugin.create_listing(_media_list(params['path'], media_listing, page, params.get('is_search_result')), update_listing=page > 0)
def bookmarks(params): """ Login to display ex.ua bookmarks """ if not webclient.is_logged_in(): plugin.log_debug('Trying to login to ex.ua') username = plugin.get_setting('username', False) password = webclient.decode(plugin.get_setting('password', False)) captcha = webclient.check_captcha() login_dialog = login_window.LoginWindow(username, password, captcha.image) login_dialog.doModal() if not login_dialog.login_cancelled: try: webclient.login(login_dialog.username, login_dialog.password, captcha.captcha_id, login_dialog.captcha_text) except webclient.LoginError: plugin.log_debug('ex.ua login error') dialog.ok(_('Login error!'), _('Check your login and password, and try again.')) else: plugin.log_debug('Successful login to ex.ua') plugin.set_setting('username', login_dialog.username) if plugin.save_pass: plugin.set_setting('password', webclient.encode(login_dialog.password)) else: plugin.set_setting('password', '') del login_dialog if webclient.is_logged_in(): plugin.log_debug('The user is logged in, getting bookmarks.') media = exua.get_media_list('/buffer') plugin.log_debug('My bookmarks: {0}'.format(media)) listing = _media_list('/buffer', media, from_bookmarks=True) else: listing = [] return listing
def _get_media_list(path, page, items): return exua.get_media_list(path, page, items)