Skip to content

Commit d851b86

Browse files
author
marcalv
committed
add support for url short service (buscatorrent), add youtube plugin support
1 parent dab7fc8 commit d851b86

File tree

3 files changed

+55
-23
lines changed

3 files changed

+55
-23
lines changed

addon.py

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,59 @@
11
import xbmcaddon
22
import xbmcgui
3-
3+
44
addon = xbmcaddon.Addon()
55
addonname = addon.getAddonInfo('name')
6-
6+
77
osWin = xbmc.getCondVisibility('system.platform.windows')
88
osOsx = xbmc.getCondVisibility('system.platform.osx')
99
osLinux = xbmc.getCondVisibility('system.platform.linux')
1010
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+

addon.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<addon id="script.url.launcher" name="Url Launcher" version="1.0.0" provider-name="marcalv">
33
<requires>
44
<import addon="xbmc.python" version="2.14.0"/>
5+
<import addon="script.module.requests"/>
56
</requires>
67
<extension point="xbmc.python.script" library="addon.py">
78
<provides>executable</provides>

resources/settings.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
22
<settings>
3-
<category label="32310">
3+
<category label="32011">
44
<setting type="lsep" label="URL to be opened" />
55
<setting label="32011" type="text" id="url" default="https://"/>
6+
<setting type="lsep" label="Android Browser to be used" />
7+
<setting label="32011" type="text" id="app" default="com.android.browser"/>
68
</category>
79
</settings>

0 commit comments

Comments
 (0)