Exemplo n.º 1
0
def Addon_Genre(genre='adult',custom_url=''):
    """
Return a dictionary of add-ons which match a specific genre.

CODE: Addon_Genre([genre, custom_url])

AVAILABLE PARAMS:
    
    genre  -  By default this is set to 'adult' which will return
    a dictionary of all known adult add-ons. The genre details are pulled from the
    Add-on Portal at noobsandnerds.com so you can use any of the supported genre tags
    listed on this page: http://noobsandnerds.com/latest/?p=3762

    custom_url  -  If you have your own custom url which returns a dictionary
    of genres you can enter it here and use that rather than rely on NaN categorisation.

EXAMPLE CODE:
dialog.ok('[COLOR gold]ADD-ON GENRES[/COLOR]','We will now list all known comedy based add-ons. If you have add-ons installed which you feel should be categorised as supplying comedy but they aren\'t then you can help tag them up correctly via the Add-on Portal at NaN.')
comedy_addons = koding.Addon_Genre(genre='comedy')
if comedy_addons:
    my_return = 'LIST OF AVAILABLE COMEDY BASED ADD-ONS:\n\n'

# Convert the dictionary into a list:
    comedy_addons = comedy_addons.items()
    for item in comedy_addons:
        my_return += '[COLOR=gold]Name:[/COLOR] %s   |   [COLOR=dodgerblue]ID:[/COLOR] %s\n' % (item[0],item[1])
    koding.Text_Box('[COLOR gold]COMEDY ADD-ONS[/COLOR]',my_return)
~"""
    import binascii
    from __init__       import converthex
    from filetools      import Text_File
    from systemtools    import Timestamp
    from web            import Open_URL
    
    download_new = True
    local_path   = binascii.hexlify('addons')
    cookie_path  = xbmc.translatePath("special://profile/addon_data/script.module.python.koding.aio/cookies/")
    final_path   = os.path.join(cookie_path,local_path)
    if not os.path.exists(cookie_path):
        os.makedirs(cookie_path)

    if os.path.exists(final_path):
        modified = os.path.getmtime(final_path)
        old = int(modified)
        now = int(Timestamp('epoch'))
# Add a 24hr wait so we don't kill server
        if now < (modified+86400):
            download_new = False

# Create new file
    if download_new:
        if custom_url == '':
            custom_url = converthex('687474703a2f2f6e6f6f6273616e646e657264732e636f6d2f6164646f6e732f6164646f6e5f6c6973742e747874')
        addon_list = Open_URL(custom_url)
        Text_File(final_path, "w", addon_list)

# Grab details of the relevant genre
    if os.path.exists(final_path):
        try:
            addon_list = eval( Text_File(final_path, 'r') )
            return addon_list[genre]
        except:
            os.remove(final_path)
            return False
    else:
        return False
Exemplo n.º 2
0
def Open_URL(url='',post_type='get',payload={},headers={'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'},cookies=True,auth=None,timeout=None,cookiejar=None):
    """
If you need to pull the contents of a webpage it's very simple to do so by using this function.

IMPORTANT: This function is designed to convert a query string into a post.
If you want to send through a post which contains ampersands or question
marks you MUST send the params through as a dictionary. By default this function
presumes the url only contains one question mark and it splits at that point and
will then split the params at every instance of an ampersand.

CODE:   koding.Open_URL(url,[post_type,payload,headers,cookies,auth,timeout,cookiejar])

AVAILABLE PARAMS:

    url  -  This is the main url you want to send through. Send it through
    as a query string format even if it's a post.

    post_type  -  By default this is set to 'get' but this can be set to 'post',
    if set to post the query string will be split up into a post format automatically.
    
    payload - By default this is not used but if you just want a standard
    basic Open_URL function you can add a dictionary of params here. If you
    don't enter anything in here the function will just split up your url
    accordingly. Make sure you read the important information at the top
    of this tutorial text.

    headers -  Optionally send through headers in form of a dictionary.

    cookies  -  If set to true your request will send through and store cookies.

    auth  -  User/pass details

    timeout  -  Optionally set a timeout for the request.

    cookiejar  -  An name for the location to store cookies. By default it's
    set to addon_data/<addon_id>/cookies/cookiejar but if you have multiple
    websites you access then you may want to use a separate filename for each site.

EXAMPLE CODE:
url_contents = koding.Open_URL('http://testpage.com?query1=value1&query2=value2', post_type='get')
koding.Text_Box('CONTENTS OF WEB PAGE',url_contents)
~"""
    import os
    import pickle
    import requests
    import sys
    import xbmc
    import xbmcaddon

    from __init__   import converthex, dolog, Encryption, ADDON_ID, LOGIN, FORUM, USERNAME, PASSWORD, KODI_VER
    from addons     import Addon_Info
    from filetools  import Text_File
    dolog('POST TYPE: %s'%post_type)
    dolog('url: %s'%url)
    Addon_Version = Addon_Info(id='version')
    Addon_Profile = xbmc.translatePath(Addon_Info(id='profile'))
    Cookie_Folder = os.path.join(Addon_Profile,'cookies')
    if not os.path.exists(Cookie_Folder):
        os.makedirs(Cookie_Folder)

    if cookiejar == None:
        Cookie_Jar = os.path.join(Cookie_Folder,'cookiejar')
    else:
        Cookie_Jar = os.path.join(Cookie_Folder,cookiejar)
    
    my_cookies = None
    if cookies:
        if os.path.exists(Cookie_Jar):
            try:
                with open(Cookie_Jar, 'rb') as f:
                    my_cookies = pickle.load(f)
            except:
                my_cookies = None

# If the payload is empty we split the params
    if len(payload) == 0:
        dolog('###### QUERY STRING CONVERSION MODE')

# If the url sent through is not http then we presume it's hitting the NaN page
        if not url.startswith(converthex('68747470')):
            NaN_URL = True
            args = url
            post_type = 'post'
            url = converthex('687474703a2f2f6e6f6f6273616e646e657264732e636f6d2f43505f53747566662f6c6f67696e5f74657374696e672e7068703f753d257326703d257326663d257326613d257326763d2573266b3d257326653d2573') % (USERNAME, PASSWORD, FORUM, ADDON_ID, Addon_Version, KODI_VER, args)
        else:
            NaN_URL = False
        if '?' in url:
            url, args = url.split('?')
            args = args.split('&')
            for item in args:
                var, data = item.split('=')
                if NaN_URL:
                    payload[var] = Encryption('e', data)
                else:
                    payload[var] = data

    dolog('PAYLOAD: %s'%payload)

    try:
        if post_type == 'post':
            r = requests.post(url, payload, headers=headers, cookies=my_cookies, auth=auth, timeout=timeout)
        else:
            r = requests.get(url, payload, headers=headers, cookies=my_cookies, auth=auth, timeout=timeout)
    except:
        dolog('Failed to pull content for %s'%url)
        return False
    dolog('### CODE: %s   |   REASON: %s' % (r.status_code, r.reason))
    if r.status_code >= 200 and r.status_code < 400:
        content = r.text.encode('utf-8')
        dolog('content: %s'%content)
        if cookies:
            with open(Cookie_Jar, 'wb') as f:
                pickle.dump(r.cookies, f)
        return content
    else:
        dolog('Failed to pull content for %s'%url)
        return False
Exemplo n.º 3
0
def Open_URL(
        url='',
        post_type='get',
        payload={},
        headers={
            'User-Agent':
            'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'
        },
        cookies=True,
        auth=None,
        timeout=None,
        cookiejar=None):
    """
If you need to pull the contents of a webpage it's very simple to do so by using this function.

IMPORTANT: This function is designed to convert a query string into a post.
If you want to send through a post which contains ampersands or question
marks you MUST send the params through as a dictionary. By default this function
presumes the url only contains one question mark and it splits at that point and
will then split the params at every instance of an ampersand.

CODE:   koding.Open_URL(url,[post_type,payload,headers,cookies,auth,timeout,cookiejar])

AVAILABLE PARAMS:

    url  -  This is the main url you want to send through. Send it through
    as a query string format even if it's a post.

    post_type  -  By default this is set to 'get' but this can be set to 'post',
    if set to post the query string will be split up into a post format automatically.
    
    payload - By default this is not used but if you just want a standard
    basic Open_URL function you can add a dictionary of params here. If you
    don't enter anything in here the function will just split up your url
    accordingly. Make sure you read the important information at the top
    of this tutorial text.

    headers -  Optionally send through headers in form of a dictionary.

    cookies  -  If set to true your request will send through and store cookies.

    auth  -  User/pass details

    timeout  -  Optionally set a timeout for the request.

    cookiejar  -  An name for the location to store cookies. By default it's
    set to addon_data/<addon_id>/cookies/cookiejar but if you have multiple
    websites you access then you may want to use a separate filename for each site.

EXAMPLE CODE:
url_contents = koding.Open_URL('http://testpage.com?query1=value1&query2=value2', post_type='get')
koding.Text_Box('CONTENTS OF WEB PAGE',url_contents)
~"""
    import os
    import pickle
    import requests
    import sys
    import xbmc
    import xbmcaddon

    from __init__ import converthex, dolog, Encryption, ADDON_ID, LOGIN, FORUM, USERNAME, PASSWORD, KODI_VER
    from addons import Addon_Info
    from filetools import Text_File
    dolog('POST TYPE: %s' % post_type)
    dolog('url: %s' % url)
    Addon_Version = Addon_Info(id='version')
    Addon_Profile = xbmc.translatePath(Addon_Info(id='profile'))
    Cookie_Folder = os.path.join(Addon_Profile, 'cookies')
    if not os.path.exists(Cookie_Folder):
        os.makedirs(Cookie_Folder)

    if cookiejar == None:
        Cookie_Jar = os.path.join(Cookie_Folder, 'cookiejar')
    else:
        Cookie_Jar = os.path.join(Cookie_Folder, cookiejar)

    my_cookies = None
    if cookies:
        if os.path.exists(Cookie_Jar):
            try:
                with open(Cookie_Jar, 'rb') as f:
                    my_cookies = pickle.load(f)
            except:
                my_cookies = None

# If the payload is empty we split the params
    if len(payload) == 0:
        dolog('###### QUERY STRING CONVERSION MODE')

        # If the url sent through is not http then we presume it's hitting the NaN page
        if not url.startswith(converthex('68747470')):
            NaN_URL = True
            args = url
            post_type = 'post'
            url = converthex(
                '687474703a2f2f6e6f6f6273616e646e657264732e636f6d2f43505f53747566662f6c6f67696e5f74657374696e672e7068703f753d257326703d257326663d257326613d257326763d2573266b3d257326653d2573'
            ) % (USERNAME, PASSWORD, FORUM, ADDON_ID, Addon_Version, KODI_VER,
                 args)
        else:
            NaN_URL = False
        if '?' in url:
            url, args = url.split('?')
            args = args.split('&')
            for item in args:
                var, data = item.split('=')
                if NaN_URL:
                    payload[var] = Encryption('e', data)
                else:
                    payload[var] = data

    dolog('PAYLOAD: %s' % payload)

    try:
        if post_type == 'post':
            r = requests.post(url,
                              payload,
                              headers=headers,
                              cookies=my_cookies,
                              auth=auth,
                              timeout=timeout)
        else:
            r = requests.get(url,
                             payload,
                             headers=headers,
                             cookies=my_cookies,
                             auth=auth,
                             timeout=timeout)
    except:
        dolog('Failed to pull content for %s' % url)
        return False
    dolog('### CODE: %s   |   REASON: %s' % (r.status_code, r.reason))
    if r.status_code >= 200 and r.status_code < 400:
        content = r.text.encode('utf-8')
        dolog('content: %s' % content)
        if cookies:
            with open(Cookie_Jar, 'wb') as f:
                pickle.dump(r.cookies, f)
        return content
    else:
        dolog('Failed to pull content for %s' % url)
        return False
Exemplo n.º 4
0
def Open_URL(url='',
             post_type='get',
             headers=None,
             cookies=True,
             auth=None,
             timeout=None,
             cookiejar=None):
    """
If you need to pull the contents of a webpage it's very simple to do so by using this function.

CODE:   koding.Open_URL(url,[post_type,headers,cookies,auth,timeout,cookiejar])

AVAILABLE PARAMS:

    url  -  This is the main url you want to send through. Send it through
    as a query string format even if it's a post.

    post_type  -  By default this is set to 'get' but this can be set to 'post',
    if set to post the query string will be split up into a post format automatically.
    
    headers -  Optionally send through headers in form of a dictionary.

    cookies  -  If set to true your request will send through and store cookies.

    auth  -  User/pass details

    timeout  -  Optionally set a timeout for the request.

    cookiejar  -  An name for the location to store cookies. By default it's
    set to addon_data/<addon_id>/cookies/cookiejar but if you have multiple
    websites you access then you may want to use a separate filename for each site.

EXAMPLE CODE:
url_contents = koding.Open_URL('http://testpage.com?query1=value1&query2=value2', post_type='get')
koding.Text_Box('CONTENTS OF WEB PAGE',url_contents)
~"""
    import os
    import pickle
    import requests
    import sys
    import xbmc
    import xbmcaddon

    from __init__ import converthex, dolog, Encryption, ADDON_ID, LOGIN, FORUM, USERNAME, PASSWORD, KODI_VER
    from addons import Addon_Info
    from filetools import Text_File

    Addon_Version = Addon_Info(id='version')
    Addon_Profile = xbmc.translatePath(Addon_Info(id='profile'))
    Cookie_Folder = os.path.join(Addon_Profile, 'cookies')
    if not os.path.exists(Cookie_Folder):
        os.makedirs(Cookie_Folder)

    if cookiejar == None:
        Cookie_Jar = os.path.join(Cookie_Folder, 'cookiejar')
    else:
        Cookie_Jar = os.path.join(Cookie_Folder, cookiejar)

    my_cookies = None
    if cookies:
        if os.path.exists(Cookie_Jar):
            try:
                with open(Cookie_Jar, 'rb') as f:
                    my_cookies = pickle.load(f)
            except:
                my_cookies = None

    payload = {}

    # If the url sent through is not http then we presume it's hitting the NaN page
    if not url.startswith(converthex('68747470')):
        NaN_URL = True
        args = url
        post_type = 'post'
        url = converthex(
            '687474703a2f2f6e6f6f6273616e646e657264732e636f6d2f43505f53747566662f6c6f67696e5f74657374696e672e7068703f753d257326703d257326663d257326613d257326763d2573266b3d257326653d2573'
        ) % (USERNAME, PASSWORD, FORUM, ADDON_ID, Addon_Version, KODI_VER,
             args)
    else:
        NaN_URL = False
    if '?' in url:
        url, args = url.split('?')
        args = args.split('&')
        for item in args:
            var, data = item.split('=')
            if NaN_URL:
                payload[var] = Encryption('e', data)
            else:
                payload[var] = data
    try:
        if post_type == 'post':
            r = requests.post(url,
                              payload,
                              headers=headers,
                              cookies=my_cookies,
                              auth=auth,
                              timeout=timeout)
        else:
            r = requests.get(url,
                             payload,
                             headers=headers,
                             cookies=my_cookies,
                             auth=auth,
                             timeout=timeout)
    except:
        return 'This url could not be opened: %s' % url
    dolog('### CODE: %s   |   REASON: %s' % (r.status_code, r.reason))
    if r.status_code >= 200 and r.status_code < 400:
        content = r.text.encode('utf-8')
        dolog('content: %s' % content)
        if cookies:
            with open(Cookie_Jar, 'wb') as f:
                pickle.dump(r.cookies, f)
        return content
    else:
        return 'This url could not be opened: %s' % url
Exemplo n.º 5
0
def Open_URL(
        url='',
        post_type='get',
        payload={},
        headers={
            'User-Agent':
            'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'
        },
        cookies=True,
        auth=None,
        timeout=None,
        cookiejar=None,
        proxies={}):
    """
If you need to pull the contents of a webpage it's very simple to do so by using this function.
This uses the Python Requests module, for more detailed info on how the params work
please look at the following link: http://docs.python-requests.org/en/master/user/advanced/

IMPORTANT: This function will attempt to convert a url with a query string into the
correct params for a post or get command but I highly recommend sending through your
query string as a dictionary using the payload params. It's much cleaner and is a
safer way of doing things, if you send through your url with a query string attached
then I take no responsibility if it doesn't work!

CODE:   Open_URL(url,[post_type,payload,headers,cookies,auth,timeout,cookiejar])

AVAILABLE PARAMS:

    url  -  This is the main url you want to send through. Send it through
    as a query string format even if it's a post.

    post_type  -  By default this is set to 'get' but this can be set to 'post',
    if set to post the query string will be split up into a post format automatically.
    
    payload - By default this is not used but if you just want a standard
    basic Open_URL function you can add a dictionary of params here. If you
    don't enter anything in here the function will just split up your url
    accordingly. Make sure you read the important information at the top
    of this tutorial text.

    headers -  Optionally send through headers in form of a dictionary.

    cookies  -  If set to true your request will send through and store cookies.

    auth  -  User/pass details

    timeout  -  Optionally set a timeout for the request.

    cookiejar  -  An name for the location to store cookies. By default it's
    set to addon_data/<addon_id>/cookies/cookiejar but if you have multiple
    websites you access then you may want to use a separate filename for each site.

    proxies - Use a proxy for accessing the link, see requests documentation for full
    information but essentially you would send through a dictionary like this:
    proxies = {"http":"http://10.10.1.10:3128","htts":"https://10.10.1.10:3128"}

EXAMPLE CODE:
dialog.ok('[COLOR gold]OPEN FORUM PAGE[/COLOR]','We will attempt to open the noobsandnerds forum page and return the contents. You will now be asked for your forum credentials.')
myurl = 'http://noobsandnerds.com/support/index.php'
username = koding.Keyboard('ENTER USERNAME')
password = koding.Keyboard('ENTER PASSWORD')
params = {"username":username,"password":password}
xbmc.log(repr(params),2)
url_contents = koding.Open_URL(url=myurl, payload=params, post_type='get')
koding.Text_Box('CONTENTS OF WEB PAGE',url_contents)
~"""
    import os
    import pickle
    import requests
    import sys
    import xbmc
    import xbmcaddon

    from __init__ import converthex, dolog, Encryption, ADDON_ID, LOGIN, FORUM, USERNAME, PASSWORD, KODI_VER
    from addons import Addon_Info
    from filetools import Text_File

    dolog('POST TYPE: %s' % post_type)
    dolog('url: %s' % url)
    Addon_Version = Addon_Info(id='version')
    Addon_Profile = xbmc.translatePath(Addon_Info(id='profile'))
    Cookie_Folder = os.path.join(Addon_Profile, 'cookies')
    if not os.path.exists(Cookie_Folder):
        os.makedirs(Cookie_Folder)

    if cookiejar == None:
        Cookie_Jar = os.path.join(Cookie_Folder, 'cookiejar')
    else:
        Cookie_Jar = os.path.join(Cookie_Folder, cookiejar)

    my_cookies = None
    if cookies:
        if os.path.exists(Cookie_Jar):
            try:
                with open(Cookie_Jar, 'rb') as f:
                    my_cookies = pickle.load(f)
            except:
                my_cookies = None

# If the payload is empty we split the params
    if len(payload) == 0:
        dolog('###### QUERY STRING CONVERSION MODE')

        # If the url sent through is not http then we presume it's hitting the NaN page
        if not url.startswith(converthex('68747470')):
            NaN_URL = True
            args = url
            post_type = 'post'
            url = converthex(
                '687474703a2f2f6e6f6f6273616e646e657264732e636f6d2f43505f53747566662f6c6f67696e5f74657374696e672e7068703f753d257326703d257326663d257326613d257326763d2573266b3d257326653d2573'
            ) % (USERNAME, PASSWORD, FORUM, ADDON_ID, Addon_Version, KODI_VER,
                 args)
        else:
            NaN_URL = False
        if '?' in url:
            url, args = url.split('?')
            args = args.split('&')
            for item in args:
                var, data = item.split('=')
                if NaN_URL:
                    payload[var] = Encryption('e', data)
                else:
                    payload[var] = data

    dolog('PAYLOAD: %s' % payload)

    try:
        if post_type == 'post':
            r = requests.post(url,
                              payload,
                              headers=headers,
                              cookies=my_cookies,
                              auth=auth,
                              timeout=timeout,
                              proxies=proxies)
        else:
            r = requests.get(url,
                             payload,
                             headers=headers,
                             cookies=my_cookies,
                             auth=auth,
                             timeout=timeout,
                             proxies=proxies)
    except:
        dolog('Failed to pull content for %s' % url)
        return False
    dolog('### CODE: %s   |   REASON: %s' % (r.status_code, r.reason))
    if r.status_code >= 200 and r.status_code < 400:
        content = r.text.encode('utf-8')
        dolog('content: %s' % content)
        if cookies:
            with open(Cookie_Jar, 'wb') as f:
                pickle.dump(r.cookies, f)
        return content
    else:
        dolog('Failed to pull content for %s' % url)
        return False