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
Exemple #2
0
def Clear_Providers():
    counter = 1
    while counter != 11:
        try:
            koding.Addon_Setting(setting='offset%s' % counter,
                                 value='0',
                                 addon_id='script.trtv')
            koding.Addon_Setting(setting='xmlpath%s.url' % counter,
                                 value='',
                                 addon_id='script.trtv')
            koding.Addon_Setting(setting='xmlpath%s.type' % counter,
                                 value='None',
                                 addon_id='script.trtv')
            koding.Addon_Setting(setting='country%s' % counter,
                                 value='United Kingdom',
                                 addon_id='script.trtv')
            koding.Addon_Setting(setting='usecountry%s' % counter,
                                 value='false',
                                 addon_id='script.trtv')
            counter += 1
        except:
            break
    our functions later on. Please bare in mind though that if you change the value
    of a global variable from inside a function the value will revert back to the
    value set here once that function has completed.
"""
addon_id = xbmcaddon.Addon().getAddonInfo('id')  # Grab our add-on id
dialog = xbmcgui.Dialog()  # A basic dialog message command
home_folder = xbmc.translatePath(
    'special://home/'
)  # Convert the special path of Kodi home folder to the physical path
addon_folder = os.path.join(
    home_folder, 'addons'
)  # Join our folder above with 'addons' so we have a link to our addons folder
art_path = os.path.join(
    addon_folder, addon_id
)  # Join addons folder with the addon_id, we'll use this as a basic art folder
debug = koding.Addon_Setting(
    'debug')  # Grab the setting of our debug mode in add-on settings
#----------------------------------------------------------------
"""
    SECTION 5:
    This is optional, if you want to have your add-on hosted at noobsandnerds.com and
    would like to hook into their special framework then you need to add the following
    line. It has been commented out in this template, just uncomment if you want to use it
    but you will need to have your add-on approved by the noobsandnerds team for this functionality.
"""

# koding.User_Info()

#----------------------------------------------------------------
"""
    SECTION 6:
    Add our custom functions in here, it's VERY important these go in this section
Exemple #4
0
addon_id = xbmcaddon.Addon().getAddonInfo('id')
dialog = xbmcgui.Dialog()
home_folder = xbmc.translatePath('special://home/')
addon_folder = os.path.join(home_folder, 'addons')
art_path = os.path.join(addon_folder, addon_id)
#xml_path     = os.path.join(art_path, 'xmls')
userdata_folder = os.path.join(home_folder, 'userdata')
addon_data_folder = os.path.join(userdata_folder, 'addon_data')
xmlerator_data = os.path.join(addon_data_folder, addon_id)
xml_path = os.path.join(xmlerator_data, 'xmls')
if os.path.exists(xml_path):
    pass
else:
    os.mkdir(xml_path, 0755)
debug = koding.Addon_Setting('debug')
tmdb_api_key = koding.Addon_Setting(setting='TMDB_api', addon_id=addon_id)
trakt_client_id = koding.Addon_Setting(setting='Trakt_api', addon_id=addon_id)
trakt_user_name = koding.Addon_Setting(setting='Trakt_user', addon_id=addon_id)
Text_color = koding.Addon_Setting(setting='Text_color', addon_id=addon_id)
bold_value = koding.Addon_Setting(setting='bold_type', addon_id=addon_id)
get_trailer = xbmcaddon.Addon().getSetting("include_trailer")
User_Agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'


@route(mode="main")
def Main_Menu():
    Add_Dir(name='Directions',
            mode='directions',
            folder=False,
            icon=os.path.join(art_path, 'icon.png'),
def epgtools():
    from koding import String
    dialog_array = []
    exec_array = []
    enable_selector = koding.Addon_Setting(setting='usecustom',
                                           addon_id='script.trtv')
    custom_config = koding.Addon_Setting(setting='custom.config.links',
                                         addon_id='script.trtv')
    custom_reset = koding.Addon_Setting(setting='custom.reset',
                                        addon_id='script.trtv')
    custom_settings = koding.Addon_Setting(setting='custom.settings',
                                           addon_id='script.trtv')
    custom_update = koding.Addon_Setting(setting='custom.update.links',
                                         addon_id='script.trtv')
    custom_url = koding.Addon_Setting(setting='custom.url',
                                      addon_id='script.trtv')
    custom_vpn = koding.Addon_Setting(setting='custom.vpn',
                                      addon_id='script.trtv')
    if enable_selector == 'true':
        if custom_vpn == 'true' and xbmc.getCondVisibility(
                'System.HasAddon(service.vpn.manager)'):
            exec_array.append(
                'xbmc.executebuiltin(\'ActivateWindow(10025,"plugin://service.vpn.manager/?toplevel",return)\')'
            )
            dialog_array.append(String(code=30842, source='script.trtv'))
        if 'http' in custom_url:
            dialog_array.append(String(code=30829, source='script.trtv'))
            exec_array.append(
                'xbmc.executebuiltin("RunScript(special://home/addons/plugin.program.tbs/epg.py,listings,silent)")'
            )
        if custom_update == 'true':
            dialog_array.append(String(code=30825, source='script.trtv'))
            exec_array.append(
                'xbmc.executebuiltin("RunScript(special://home/addons/script.trtv/updateini.py)")'
            )
        if custom_config == 'true':
            dialog_array.append(String(code=30826, source='script.trtv'))
            exec_array.append(
                'xbmc.executebuiltin(\'ActivateWindow(10025,"plugin://plugin.video.addons.ini.creator",return)\')'
            )
        if custom_reset == 'true':
            dialog_array.append(String(code=30827, source='script.trtv'))
            if sys.argv[-1] == 'epg':
                exec_array.append(
                    'xbmc.executebuiltin("RunScript(special://home/addons/script.trtv/deleteDB.py,wipeEPG)");xbmc.executebuiltin("ActivateWindow(home)");xbmc.executebuiltin("StopScript(script.trtv)")'
                )
            else:
                exec_array.append(
                    'xbmc.executebuiltin("RunScript(special://home/addons/script.trtv/deleteDB.py,wipeEPG)")'
                )
        if custom_settings == 'true':
            dialog_array.append(String(code=30828, source='script.trtv'))
            exec_array.append(
                'xbmc.executebuiltin("RunScript(special://home/addons/script.trtv/openSettings.py,std)")'
            )
        if len(dialog_array) > 0:
            choice = dialog.select(String(code=30805, source='script.trtv'),
                                   dialog_array)
            if choice >= 0:
                exec(exec_array[choice])
    else:
        dialog.ok(String(code=30830, source='script.trtv'),
                  String(code=30831, source='script.trtv'))
        koding.Open_Settings(addon_id='script.trtv', focus='3.11', click=True)
Exemple #6
0
def Main_Menu_Check():
    # Standard social sharing style menus
    if mode == 'std':
        folders = Folder_Check()
        if sys.argv[1] == "live_tv" and folders == 0 and not tvgskip:
            choice = dialog.select(
                sys.argv[1].replace('_', ' ').upper() + ' Menu', [
                    '[COLOR=gold]Add[/COLOR] to Live TV',
                    '[COLOR=gold]Add / Remove[/COLOR] Sub-menus'
                ])
            if choice == 0:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=live_tv",return)'
                )
            if choice == 1:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=live_tv_submenu",return)'
                )

        elif sys.argv[1] == "live_tv" and folders > 0 and not tvgskip:
            choice = dialog.select(
                sys.argv[1].replace('_', ' ').upper() + ' Menu', [
                    '[COLOR=gold]Add[/COLOR] to Live TV',
                    '[COLOR=gold]Remove[/COLOR] from Live TV',
                    '[COLOR=gold]Add / Remove[/COLOR] Sub-menus',
                    '[COLOR=gold]Share[/COLOR] Live TV Item'
                ])
            if choice == 0:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=live_tv",return)'
                )
            if choice == 1:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=from_the_live_tv_menu",return)'
                )
            if choice == 2:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=live_tv_submenu",return)'
                )
            if choice == 3:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.super.favourites/?folder=HOME_LIVE_TV",return)'
                )

    # EDIT Menu
        elif sys.argv[1] == "mainmenu":
            choice = dialog.select(String(30280), [
                String(30281),
                String(30282),
                String(30292),
                String(30300),
                String(30506)
            ])
            if choice >= 0:
                if choice == 0:
                    xbmc.executebuiltin(
                        'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=main_menu_install&url=add",return)'
                    )
                    xbmc.executebuiltin('Container.Refresh')

                if choice == 1:
                    xbmc.executebuiltin(
                        'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=main_menu_install&url=remove",return)'
                    )
                    xbmc.executebuiltin('Container.Refresh')

                if choice == 2:
                    Configure_Menus()

                if choice == 3:
                    Configure_Menus('SUBMENU_')

                if choice == 4:
                    Reset_Factory('ALL')

    # SOCIAL SHARES - If content exists add menu for adding, removing and sharing
        elif (sys.argv[1] != "mainmenu") and (folders > 0) and (
                not sys.argv[1].endswith('_SF')):
            cleanname = sys.argv[1].replace('_', ' ')
            choice = dialog.select(String(30283), [
                String(30284) % sys.argv[1].replace('_', ' '),
                String(30285) % sys.argv[1].replace('_', ' '),
                String(30286),
                String(30287) % cleanname
            ])
            if choice == 0:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url='
                    + sys.argv[1] + '",return)')
            if choice == 1:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=from_the_'
                    + sys.argv[1] + '_menu",return)')
            if choice == 2:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url='
                    + sys.argv[1] + '_submenu",return)')
            if choice == 3:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.super.favourites/?folder=HOME_'
                    + sys.argv[1].replace(' ', '_').upper() + '",return)')

    # SOCIAL SHARES - If no content exists add menu for adding and sharing only
        elif (sys.argv[1] != "mainmenu") and (folders == 0) and (
                not sys.argv[1].endswith('_SF')):
            cleanname = sys.argv[1].replace('_', ' ')
            choice = dialog.select(
                String(30283),
                [String(30284) % sys.argv[1].replace('_', ' '),
                 String(30291)])
            if choice == 0:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url='
                    + sys.argv[1] + '",return)')
            if choice == 1:
                xbmc.executebuiltin(
                    'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url='
                    + sys.argv[1] + '_submenu",return)')
        else:
            xbmc.executebuiltin(
                'ActivateWindow(programs,"plugin://plugin.program.super.favourites/?folder=HOME_'
                + sys.argv[1].replace(' ', '_').upper() + '",return)')

# If we're opening the EPG Tools menu
    elif mode == 'listings':

        custom_url = koding.Addon_Setting(setting='custom.url',
                                          addon_id='script.trtv')
        if 'http' in custom_url:
            countries = [
                'Afghanistan', 'Albania', 'Algeria', 'Angola', 'Argentina',
                'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas',
                'Belarus', 'Belgium', 'Bolivia', 'Bosnia', 'Brazil',
                'Bulgaria', 'Cambodia', 'Cameroon', 'Canada', 'Chile', 'China',
                'Colombia', 'Costa Rica', 'Croatia', 'Cuba', 'Cyprus',
                'Czech Republic', 'Denmark', 'Dominican Republic', 'Ecuador',
                'Egypt', 'El Salvador', 'Estonia', 'Ethiopia', 'Finland',
                'France', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana',
                'Greece', 'Guatemala', 'Guinea', 'Haiti', 'Honduras',
                'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia',
                'Iran', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Ivory Coast',
                'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kosovo',
                'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Liberia',
                'Libya', 'Liechstenstein', 'Lithuania', 'Luxembourg',
                'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Mali',
                'Malta', 'Mauritius', 'Mexico', 'Moldova', 'Mongolia',
                'Montenegro', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia',
                'Nepal', 'Netherlands', 'New Zealand', 'Nicaragua', 'Niger',
                'Nigeria', 'Norway', 'Oman', 'Pakistan', 'Palestine', 'Panama',
                'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal',
                'Puerto Rico', 'Qatar', 'Romania', 'Russia', 'Rwanda',
                'Saudi Arabia', 'Senegal', 'Serbia', 'Sierra Leone',
                'Singapore', 'Slovakia', 'Slovenia', 'Somalia', 'South Africa',
                'South Korea', 'South Sudan', 'Spain', 'Sri Lanka', 'Sudan',
                'Suriname', 'Sweden', 'Switzerland', 'Syria', 'Taiwan',
                'Tajikistan', 'Tanzania', 'Thailand', 'Togo',
                'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan',
                'Uganda', 'Ukraine', 'United Arab Emireates', 'United Kingdom',
                'United States', 'Uruguay', 'Uzbekistan', 'Venezuela',
                'Vietnam', 'Yemen', 'Zambia', 'Zimbabwe'
            ]

            # content    = koding.Open_URL('https://friendpaste.com/5Xu6ETfd0vjj8lvpvQ390b/raw')
            content = koding.Open_URL(custom_url)
            raw_list = koding.Find_In_Text(content, 'name="', '\n\n')
            final_list = []
            my_list = []
            Clear_Providers()
            xbmc.executebuiltin(
                'RunScript(special://home/addons/script.trtv/deleteDB.py,wipeEPG)'
            )
            for item in raw_list:
                name, url, country, offset = item.split('\n')
                name = name.replace('"', '').strip()
                url = url.replace('url="', '').replace('"', '').strip()
                country = country.replace('country="', '').replace('"',
                                                                   '').strip()
                offset = offset.replace('offset="', '').replace('"',
                                                                '').strip()
                final_list.append('[COLOR=dodgerblue]%s:[/COLOR] %s' %
                                  (country, name))
                my_list.append([name, url, country, offset])

        # Select main provider
            dialog.ok(String(30264).upper(), String(30265))
            choice = dialog.select(String(30264), final_list)
            counter = 1
            if choice >= 0:
                koding.Addon_Setting(setting='offset%s' % counter,
                                     value=my_list[choice][3],
                                     addon_id='script.trtv')
                koding.Addon_Setting(setting='xmlpath%s.url' % counter,
                                     value=my_list[choice][1],
                                     addon_id='script.trtv')
                koding.Addon_Setting(setting='xmlpath%s.type' % counter,
                                     value='URL',
                                     addon_id='script.trtv')
                if my_list[choice][2] in countries:
                    koding.Addon_Setting(setting='country%s' % counter,
                                         value=my_list[choice][2],
                                         addon_id='script.trtv')
                    koding.Addon_Setting(setting='usecountry%s' % counter,
                                         value='true',
                                         addon_id='script.trtv')
                else:
                    koding.Addon_Setting(setting='usecountry%s' % counter,
                                         value='false',
                                         addon_id='script.trtv')
                del final_list[choice]
                del my_list[choice]
                counter += 1

                # If still items in list offer to add more providers
                my_choice = 1
                while my_choice:
                    if len(final_list) > 1:
                        my_choice = dialog.yesno(
                            String(30264).upper(), String(30266))
                        if not my_choice:
                            break
                        choice = dialog.select(String(30264), final_list)
                        koding.Addon_Setting(setting='offset%s' % counter,
                                             value=my_list[choice][3],
                                             addon_id='script.trtv')
                        koding.Addon_Setting(setting='xmlpath%s.url' % counter,
                                             value=my_list[choice][1],
                                             addon_id='script.trtv')
                        koding.Addon_Setting(setting='xmlpath%s.type' %
                                             counter,
                                             value='URL',
                                             addon_id='script.trtv')
                        if my_list[choice][2] in countries:
                            koding.Addon_Setting(setting='country%s' % counter,
                                                 value=my_list[choice][2],
                                                 addon_id='script.trtv')
                            koding.Addon_Setting(setting='usecountry%s' %
                                                 counter,
                                                 value='true',
                                                 addon_id='script.trtv')
                        else:
                            koding.Addon_Setting(setting='usecountry%s' %
                                                 counter,
                                                 value='false',
                                                 addon_id='script.trtv')
                        del final_list[choice]
                        del my_list[choice]
                        counter += 1