How to open a link use a web browser?
#16
Taifxx,
Thanks a lot. Yes indeed. I tried the if url == 'Cancel' : break. It did not work. But I used a variable and put everything under
if selected>=0:
url = URLS[selected]
the rest code...

This worked. My addon is indeed a video source I tried the on click but I do not know how to assign it to a list. I will be thankful if you have a sample code. Sample code on internet didn't work.
Thanks in advance.
Reply
#17
PHP Code:
# -*- coding: utf-8 -*-
# ____________________        I M P O R T        ____________________
import xbmc
import xbmcplugin
import xbmcgui
import webbrowser
import sys
import urllib
import ast
from urlparse import parse_qsl

# ____________________     V A R I A B L E S     ____________________

    # ___ Get base_url, add_handle and arguments
__url__ sys.argv[0]
    
# ___ Get the handle integer
__handle__ int(sys.argv[1])    
    
# ___ {<parameter>: <value>} elements
__params__ dict(parse_qsl(sys.argv[2][1:]))


# ____________________     M E T H O D S     ____________________

def openUrl(url):
    
osWin xbmc.getCondVisibility('system.platform.windows')
    
osOsx xbmc.getCondVisibility('system.platform.osx')
    
osLinux xbmc.getCondVisibility('system.platform.linux')
    
osAndroid xbmc.getCondVisibility('System.Platform.Android'
    
    if 
osOsx:    
        
# ___ Open the url with the default web browser
        
xbmc.executebuiltin("System.Exec(open "+url+")")
    
elif osWin:
        
# ___ Open the url with the default web browser
        
xbmc.executebuiltin("System.Exec(cmd.exe /c start "+url+")")
    
elif osLinux and not osAndroid:
        
# ___ Need the xdk-utils package
        
xbmc.executebuiltin("System.Exec(xdg-open "+url+")"
    
elif osAndroid:
        
# ___ Open media with standard android web browser
        
xbmc.executebuiltin("StartAndroidActivity(com.android.browser,android.intent.action.VIEW,,"+url+")")
        
        
# ___ Open media with Mozilla Firefox
        
xbmc.executebuiltin("StartAndroidActivity(org.mozilla.firefox,android.intent.action.VIEW,,"+url+")")                    
        
        
# ___ Open media with Chrome
        
xbmc.executebuiltin("StartAndroidActivity(com.android.chrome,,,"+url+")"

def directOpenURL(url):
    
""""
        
Method to open url
        
@param urlthe url to open
    
"""
    webbrowser.open(url)
    
def openFromDialog(urls):
    """
        
Method to choose a link with a dialog
    
"""
    dialog = xbmcgui.Dialog()
    selected = dialog.select('Choose an url', urls)   
    url = urls[selected]
    directOpenURL(url)
    # or
    # openUrl(url)
    

# ____________________    UI   M E T H O D S    ____________________
def initMenu():
    """
        
Method to initialize the menu
    
"""
    xbmcplugin.setContent(__handle__, 'folder')
    
    element1 = {'action': 'dialogList',
               'label': 'Display list with dialog'}
    url1 = __url__ + '?' + urllib.urlencode(element1)
    li1 = xbmcgui.ListItem(element1['label'])
    xbmcplugin.addDirectoryItem(handle=__handle__, 
                                url=url1,
                                listitem=li1, 
                                isFolder=True)
    
    element2 = {'action': 'directList',
               'label': 'Display direct link list'}
    url2 = __url__ + '?' + urllib.urlencode(element2)
    li2 = xbmcgui.ListItem(element2['label'])
    xbmcplugin.addDirectoryItem(handle=__handle__, 
                                url=url2,
                                listitem=li2, 
                                isFolder=True)
    
    xbmcplugin.endOfDirectory(__handle__) 
    

def initDialogList():
    """
        
Method to initialize a list of item which open a dialog with our list of url
    
"""
    xbmcplugin.setContent(__handle__, 'folder')
    
    element1 = {'action': 'dialog',
               'label': 'Element which open a dialog',
               'urls':['http://www.google.fr/', 'http://www.google.com/', 'http://www.google.de/']
               }
    url1 = __url__ + '?' + urllib.urlencode(element1)
    li1 = xbmcgui.ListItem(element1['label'])
    xbmcplugin.addDirectoryItem(handle=__handle__, 
                                url=url1,
                                listitem=li1, 
                                isFolder=True) 
    xbmcplugin.endOfDirectory(__handle__) 
    
    
def initDirectList():
    """
        
Method to initialize a list of item which open a directly the url
    
"""
    xbmcplugin.setContent(__handle__, 'folder')
    
    element1 = {'action': 'direct',
               'label': 'Direct link',
               'url':'http://www.google.com/'}
    url1 = __url__ + '?' + urllib.urlencode(element1)
    li1 = xbmcgui.ListItem(element1['label'])
    xbmcplugin.addDirectoryItem(handle=__handle__, 
                                url=url1,
                                listitem=li1, 
                                isFolder=False) 
    xbmcplugin.endOfDirectory(__handle__) 
    
    
# ____________________   R O U T E R    ____________________    
def router(params):
    ""
    if 'action' in params and params['action'] == 'dialogList':
        initDialogList()
    elif 'action' in params and params['action'] == 'directList':
        initDirectList()
    elif 'action' in params and params['action'] == 'dialog':
        urls = ast.literal_eval(params['urls'])
        openFromDialog(urls)
    elif 'action' in params and params['action'] == 'direct':
        directOpenURL(params['url'])
        # or
        # openUrl(url)    
    else:
        initMenu()


# ___ Route by url
router(__params__) 
Reply
#18
(2017-01-09, 22:30)sinanozgur Wrote: Ronie,

Thank you for your reply. It is great to have help. But the code is not working. For simplicity.
import sys
import os
import urllib
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
import logging
from operator import itemgetter

# import webbrowser


#URLS = ['http://www.google.fr/', 'http://www.google.com/', 'http://www.google.de/']
# dialog = xbmcgui.Dialog()
# selected = dialog.select('Choose an url', URLS)
# url = URLS[selected]
url='http://www.google.com/'
# Open URL in new browser window
# webbrowser.open_new(url) # opens in default browser

osWin = xbmc.getCondVisibility('system.platform.windows')
osOsx = xbmc.getCondVisibility('system.platform.osx')
osLinux = xbmc.getCondVisibility('system.platform.linux')
osAndroid = xbmc.getCondVisibility('System.Platform.Android')

if osOsx:
# ___ Open the url with the default web browser
xbmc.executebuiltin("System.Exec(open "+url+")")
elif osWin:
# ___ Open the url with the default web browser
xbmc.executebuiltin("System.Exec(cmd.exe /c start "+url+")")
elif osLinux and not osAndroid:
# ___ Need the xdk-utils package
xbmc.executebuiltin("System.Exec(xdg-open "+url+")")
elif osAndroid:
# ___ Open media with standard android web browser
xbmc.executebuiltin("StartAndroidActivity(com.android.browser,android.intent.action.VIEW,,"+url+")")

# ___ Open media with Mozilla Firefox
xbmc.executebuiltin("StartAndroidActivity(org.mozilla.firefox,android.intent.action.VIEW,,"+url+")")

# ___ Open media with Chrome
xbmc.executebuiltin("StartAndroidActivity(com.android.chrome,,,"+url+")")

This above code is working.
If I replace the url='http://www.google.com/' with your code above (see that I commented it) it is not working. The portion of the log file is as follows:

21:24:35 T:6028 NOTICE: Checking resolution 16
21:24:35 T:6028 NOTICE: Running database version Addons20
21:24:37 T:6028 WARNING: CSkinInfo: failed to load skin settings
21:24:37 T:6028 WARNING: Previous line repeats 1 times.
21:24:37 T:6028 WARNING: JSONRPC: Could not parse type "Setting.Details.SettingList"
21:24:37 T:6028 NOTICE: ActiveAE DSP - starting
21:24:37 T:6028 NOTICE: initialize done
21:24:37 T:6028 NOTICE: Running the application...
21:24:37 T:6028 NOTICE: starting upnp client
21:24:37 T:5240 NOTICE: ES: Starting UDP Event server on 127.0.0.1:9777
21:24:37 T:5240 NOTICE: UDP: Listening on port 9777
21:27:13 T:2036 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.IndentationError'>
Error Contents: ('unexpected indent', ('C:\\Users\\tygtr\\AppData\\Roaming\\Kodi\\addons\\plugin.video.simplekodi\\addon.py', 15, 1, ' dialog = xbmcgui.Dialog()\n'))
IndentationError: ('unexpected indent', ('C:\\Users\\tygtr\\AppData\\Roaming\\Kodi\\addons\\plugin.video.simplekodi\\addon.py', 15, 1, ' dialog = xbmcgui.Dialog()\n'))
-->End of Python script error report<--
21:27:13 T:6028 ERROR: XFILE::CDirectory::GetDirectory - Error getting plugin://plugin.video.simplekodi/
21:27:13 T:6028 ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.simplekodi/) failed

Anyway I appreciate your help also that one of Taifxx. Thanks again in advance....
Hi there could i borrow a copy of your plugin for this if you finished it so i can edit it with my own URL, thanks in advance
Reply
#19
(2015-08-18, 21:28)Seko Wrote: Hi,

You can also use "System.Exec" or "StartAndroidActivity" built-in functions to do that.

For instance :

PHP Code:
osWin xbmc.getCondVisibility('system.platform.windows')
osOsx xbmc.getCondVisibility('system.platform.osx')
osLinux xbmc.getCondVisibility('system.platform.linux')
osAndroid xbmc.getCondVisibility('System.Platform.Android')
url 'http://www.google.fr/'

if osOsx:    
    
# ___ Open the url with the default web browser
    
xbmc.executebuiltin("System.Exec(open "+url+")")
elif osWin:
    
# ___ Open the url with the default web browser
    
xbmc.executebuiltin("System.Exec(cmd.exe /c start "+url+")")
elif osLinux and not osAndroid:
    
# ___ Need the xdk-utils package
    
xbmc.executebuiltin("System.Exec(xdg-open "+url+")"
elif osAndroid:
    
# ___ Open media with standard android web browser
    
xbmc.executebuiltin("StartAndroidActivity(com.android.browser,android.intent.action.VIEW,,"+url+")")
    
    
# ___ Open media with Mozilla Firefox
    
xbmc.executebuiltin("StartAndroidActivity(org.mozilla.firefox,android.intent.action.VIEW,,"+url+")")                    
    
    
# ___ Open media with Chrome
    
xbmc.executebuiltin("StartAndroidActivity(com.android.chrome,,,"+url+")"
Hi Seko, how would i go about making the above code into a plugin i could use, sorry im a real newbie, cheers
Reply

Logout Mark Read Team Forum Stats Members Help
How to open a link use a web browser?0