diff --git a/streaming/core.py b/streaming/core.py
index 13697a5..e69e23a 100644
--- a/streaming/core.py
+++ b/streaming/core.py
@@ -634,7 +634,7 @@ class Core(CorePluginBase):
port = self.config['port']
ip = self.config['ip']
- elif self.config['serve_method'] == 'webui': # this webserver is fubar
+ elif self.config['serve_method'] == 'webui' and self.check_webui(): # this webserver is fubar
plugin_manager = component.get("CorePluginManager")
webui_plugin = plugin_manager['WebUi'].plugin
@@ -658,13 +658,14 @@ class Core(CorePluginBase):
self.site.stopFactory()
self.torrent_handler.shutdown()
- plugin_manager = component.get("CorePluginManager")
- webui_plugin = plugin_manager['WebUi'].plugin
+ if self.check_webui():
+ plugin_manager = component.get("CorePluginManager")
+ webui_plugin = plugin_manager['WebUi'].plugin
- try:
- webui_plugin.server.top_level.delEntity('streaming')
- except KeyError:
- pass
+ try:
+ webui_plugin.server.top_level.delEntity('streaming')
+ except KeyError:
+ pass
if self.listening:
yield self.listening.stopListening()
diff --git a/streaming/data/config.glade b/streaming/data/config.glade
index 6bd46b8..eb51b9e 100644
--- a/streaming/data/config.glade
+++ b/streaming/data/config.glade
@@ -579,7 +579,7 @@
- Use stream urls
+ Use stream protocol urls
True
True
False
@@ -594,7 +594,7 @@
- Auto-open stream urls
+ Auto-open stream protocol urls
True
True
False
diff --git a/streaming/data/streaming.js b/streaming/data/streaming.js
index ca50034..5546602 100644
--- a/streaming/data/streaming.js
+++ b/streaming/data/streaming.js
@@ -240,14 +240,14 @@ PreferencePage = Ext.extend(Ext.Panel, {
om.bind('use_stream_urls', fieldset.add({
xtype: 'checkbox',
name: 'use_stream_urls',
- boxLabel: 'Use stream urls',
+ boxLabel: 'Use stream protocol urls',
style: 'margin-left: 12px;'
}));
om.bind('auto_open_stream_urls', fieldset.add({
xtype: 'checkbox',
name: 'auto_open_stream_urls',
- boxLabel: 'Auto-open stream urls',
+ boxLabel: 'Auto-open stream protocol urls',
style: 'margin-left: 12px;'
}));
},
diff --git a/streaming/gtkui.py b/streaming/gtkui.py
index 6e5b930..7daa6ce 100644
--- a/streaming/gtkui.py
+++ b/streaming/gtkui.py
@@ -39,7 +39,9 @@
import json
import gtk
-import webbrowser
+import os
+import subprocess
+import sys
from deluge.log import LOG as log
from deluge.ui.client import client
@@ -53,35 +55,18 @@ from twisted.web import server, resource
from common import get_resource
-class LocalAddResource(resource.Resource):
- gtkui = None
- isLeaf = True
- def __init__(self, gtkui):
- self.gtkui = gtkui
- resource.Resource.__init__(self)
+def execute_url(url):
+ if sys.platform == 'win32':
+ os.startfile(url)
+ elif sys.platform == 'darwin':
+ subprocess.Popen(['open', url])
+ else:
+ try:
+ subprocess.Popen(['xdg-open', url])
+ except OSError:
+ print 'Unable to open URL %s' % (url, )
- def render_GET(self, request):
- useragent = request.getHeader('User-Agent')
- if 'Deluge-Streamer' not in useragent:
- request.setResponseCode(401)
- return 'Unauthorized'
-
- torrent_url = request.args.get('url', None)
- if not torrent_url:
- return json.dumps({'status': 'error', 'message': 'missing url in request'})
-
- torrent_file = request.args.get('file', None)
- if torrent_file:
- torrent_file = torrent_file[0]
-
- infohash = request.args.get('infohash', None)
- if infohash:
- infohash = infohash[0]
-
- client.streaming.stream_torrent(url=torrent_url[0], infohash=infohash, filepath_or_index=torrent_file).addCallback(self.gtkui.stream_ready)
-
- return json.dumps({'status': 'ok', 'message': 'queued'})
class GtkUI(GtkPluginBase):
def enable(self):
@@ -115,11 +100,6 @@ class GtkUI(GtkPluginBase):
self.sep_torrentmenu.show()
self.item_torrentmenu.show()
- self.resource = LocalAddResource(self)
- self.site = server.Site(self.resource)
- self.listening = reactor.listenTCP(40747, self.site, interface='127.0.0.1')
-
- @defer.inlineCallbacks
def disable(self):
component.get("Preferences").remove_page("Streaming")
component.get("PluginManager").deregister_hook("on_apply_prefs", self.on_apply_prefs)
@@ -135,9 +115,6 @@ class GtkUI(GtkPluginBase):
torrentmenu.remove(self.item_torrentmenu)
torrentmenu.remove(self.sep_torrentmenu)
- self.site.stopFactory()
- yield self.listening.stopListening()
-
@defer.inlineCallbacks
def on_apply_prefs(self):
log.debug("applying prefs for Streaming")
@@ -210,9 +187,13 @@ class GtkUI(GtkPluginBase):
if result.get('use_stream_urls', False):
url = "stream+%s" % result['url']
if result.get('auto_open_stream_urls', False):
- threads.deferToThread(webbrowser.open, url)
+ threads.deferToThread(execute_url, url)
else:
- dialogs.InformationDialog('Stream ready', 'Click here to open it' % url).run()
+ def on_dialog_callback(response):
+ if response == gtk.RESPONSE_YES:
+ threads.deferToThread(execute_url, url)
+
+ dialogs.YesNoDialog('Stream ready', 'Do you want to play the video?').run().addCallback(on_dialog_callback)
else:
dialogs.ErrorDialog('Stream ready', 'Copy the link into a media player', details=result['url']).run()
else: