def doLogin(login_url): ''' to call login,source_data = weblogin.dologin(login_url) login_url = site to login into e.g login_url = 'http://p.xxe.press/login.php' ''' source_data = '' Addon_Name = koding.Addon_Info(id='name') Addon_Version = koding.Addon_Info(id='version') Addon_Profile = koding.Addon_Info(id='profile') Cookie_Folder = os.path.join(Addon_Profile,'cookies') cookie_name = web.cookie_name_create(login_url) cookiepath = os.path.join(Cookie_Folder,str(cookie_name)+'.lwp') cookiepath = koding.Physical_Path(cookiepath) username = koding.Addon_Setting('username') password = koding.Addon_Setting('password') #delete any old version of the cookie file try: os.remove(cookiepath) except: pass koding.dolog('UserName = %s %s Password = %s %s'%(username,len(username),password,len(password)),line_info=True) koding.dolog('cookiepath = %s'%cookiepath,line_info=True) if len(username) == 0 or len(password) == 0: yesno = koding.YesNo_Dialog(title=str(Addon_Name)+' Login for'+str(login_url),message='There is no UserName or Password set, would you like to set it now?') if yesno == True: koding.Open_Settings() else: return False if username and password: #the header used to pretend you are a browser header_string = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3' #build the form data necessary for the login login_data = urllib.urlencode({'username':username, 'password':password}) #build the request we will make req = urllib2.Request(login_url, login_data) req.add_header('User-Agent',header_string) #initiate the cookielib class cj = cookielib.LWPCookieJar() #install cookielib into the url opener, so that cookies are handled opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) #do the login and get the response response = opener.open(req) source = response.read() source_data += str(source) response.close() #check the received html for a string that will tell us if the user is logged in #pass the username, which can be used to do this. login = check_login(source,username) #if login suceeded, save the cookiejar to disk if login == True: cj.save(cookiepath) #return whether we are logged in or not return login,source_data else: return False
def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False, PATH=''): #used on resloveURR if not thumb: try: thumb = os.path.join(PATH, 'icon.png') except: thumb = koding.Addon_Info('icon') list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) Add_Item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu, PATH)
def Add_Item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False, PATH=''): #used on resolveURL if not fanart: try: fanart = os.path.join(PATH, 'fanart.jpg') except: fanart = koding.Addon_Info('fanart') if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = queries if isinstance( queries, basestring) else xbmc_common.get_plugin_url(queries) if not list_item.getProperty('fanart_image'): list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items)
# -*- coding: utf-8 -*- import koding import xbmc Addon_Name = koding.Addon_Info(id='name') Addon_Icon = koding.Addon_Info(id='icon') def Notify(title='', message='', times='', icon=''): if title == '': title = Addon_Name if times == '': times = '10000' if icon == '': icon = Addon_Icon Notification = 'XBMC.Notification({},{},{},{})'.format( title, message, times, icon) xbmc.executebuiltin(str(Notification)) def set_sort_method(sortid=0): xbmc.executebuiltin('Container.SetSortMethod({})'.format(sortid)) def set_sort_method_rev(sortid=0): xbmc.executebuiltin('Container.SetSortMethod({})'.format(sortid)) xbmc.executebuiltin('Container.SetSortDirection(Descending)') def sort_date_reverse(): xbmc.executebuiltin('Container.SetSortMethod(2)')