|
1 | 1 | import xbmcaddon
|
2 | 2 | import xbmcgui
|
3 |
| - |
| 3 | + |
4 | 4 | addon = xbmcaddon.Addon()
|
5 | 5 | addonname = addon.getAddonInfo('name')
|
6 |
| - |
| 6 | + |
7 | 7 | osWin = xbmc.getCondVisibility('system.platform.windows')
|
8 | 8 | osOsx = xbmc.getCondVisibility('system.platform.osx')
|
9 | 9 | osLinux = xbmc.getCondVisibility('system.platform.linux')
|
10 | 10 | osAndroid = xbmc.getCondVisibility('System.Platform.Android')
|
11 |
| -url = addon.getSetting("url") |
12 |
| - |
13 |
| -if osOsx: |
14 |
| - # ___ Open the url with the default web browser |
15 |
| - xbmc.executebuiltin("System.Exec(open "+url+")") |
16 |
| -elif osWin: |
17 |
| - # ___ Open the url with the default web browser |
18 |
| - xbmc.executebuiltin("System.Exec(cmd.exe /c start "+url+")") |
19 |
| -elif osLinux and not osAndroid: |
20 |
| - # ___ Need the xdk-utils package |
21 |
| - xbmc.executebuiltin("System.Exec(xdg-open "+url+")") |
22 |
| -elif osAndroid: |
23 |
| - # ___ Open media with standard android web browser |
24 |
| - xbmc.executebuiltin("StartAndroidActivity(com.android.browser,android.intent.action.VIEW,,"+url+")") |
25 |
| - |
26 |
| - # ___ Open media with Mozilla Firefox |
27 |
| - xbmc.executebuiltin("StartAndroidActivity(org.mozilla.firefox,android.intent.action.VIEW,,"+url+")") |
28 |
| - |
29 |
| - # ___ Open media with Chrome |
30 |
| - xbmc.executebuiltin("StartAndroidActivity(com.android.chrome,,,"+url+")") |
| 11 | + |
| 12 | + |
| 13 | +def openbrowser(url): |
| 14 | + if osOsx: |
| 15 | + # ___ Open the url with the default web browser |
| 16 | + xbmc.executebuiltin("System.Exec(open "+urlConfig+")") |
| 17 | + elif osWin: |
| 18 | + # ___ Open the url with the default web browser |
| 19 | + xbmc.executebuiltin("System.Exec(cmd.exe /c start "+urlConfig+")") |
| 20 | + elif osLinux and not osAndroid: |
| 21 | + # ___ Need the xdk-utils package |
| 22 | + xbmc.executebuiltin("System.Exec(xdg-open "+urlConfig+")") |
| 23 | + elif osAndroid: |
| 24 | + # ___ Open media with configured web browser in addon settings |
| 25 | + xbmc.executebuiltin("StartAndroidActivity("+browserApp+",android.intent.action.VIEW,,"+urlConfig+")") |
| 26 | + |
| 27 | + |
| 28 | +#Config Variables |
| 29 | +urlConfig = addon.getSetting("url") |
| 30 | +browserApp = addon.getSetting("app") |
| 31 | + |
| 32 | +#Check if urlConfig is set |
| 33 | +if urlConfig == "https://": |
| 34 | + xbmcaddon.Addon().openSettings() |
| 35 | + |
| 36 | +#Start processing |
| 37 | +#Check if configured url returns a redirect |
| 38 | +import requests |
| 39 | +response_text = requests.get(urlConfig).text |
| 40 | +import re |
| 41 | +urls = re.findall(r"URL=(.*)'>", response_text) |
| 42 | +if not urls: |
| 43 | + openbrowser(urlConfig) |
| 44 | +else: |
| 45 | + #In case returns a redirect |
| 46 | + url = urls[0] |
| 47 | + #Search for Youtube ID |
| 48 | + regex = re.compile(r'(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?(?P<id>[A-Za-z0-9\-=_]{11})') |
| 49 | + match_youtube_id = regex.match(url) |
| 50 | + if not match_youtube_id: |
| 51 | + openbrowser(url) |
| 52 | + else: |
| 53 | + youtube_id = match_youtube_id.group('id') |
| 54 | + xbmc.Player().play("plugin://plugin.video.youtube/play/?video_id="+youtube_id) |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
0 commit comments