Re: [Rhythmbox-devel] yet another rb plugin: Rhythmweb
- From: "Jonathan Matthew" <notverysmart gmail com>
- To: rhythmbox-devel gnome org
- Subject: Re: [Rhythmbox-devel] yet another rb plugin: Rhythmweb
- Date: Tue, 2 Oct 2007 00:17:09 +1000
On 9/30/07, Michael Gratton <mike vee net> wrote:
>
> On Sun, 2007-09-30 at 22:23 +1000, Jonathan Matthew wrote:
> > This is really nice. I've been vaguely intending to make something
> > like this for a while, but I never quite got around to it. Now I guess
> > I don't have to.
>
> Cheers. Let me know how well it works if you try it out.
I've been using it a bit, and it's working pretty nicely. I've
attached some patches that fix a few more things I noticed:
- the redirect URL works better (at least in my broken network) using
the HTTP Host header in preference to the server's idea of its
hostname
- include streaming song titles if available
- stop the HTTP server from logging to stderr
- set charset=UTF-8 on html responses (otherwise iso8859-1 is assumed,
apparently)
- display the hostname
> > - I'm pretty sure I fixed the crash that occurred when calling
> > plugin.find_file() a week or so ago
>
> Oh yeah, I was meaning to track that down but couldn't find the debug
> packages for Ubuntu gutsy straight away, so kinda forgot about it.
>
> Has the fix made it into a release yet? I wonder if it's possible to
> determine the version number from Python?
It hasn't been in a release yet. I'm not sure if there's a way for
plugins to get the version number.
diff --git a/rhythmweb/__init__.py b/rhythmweb/__init__.py
index 4cfe0e9..dd9ba91 100644
--- a/rhythmweb/__init__.py
+++ b/rhythmweb/__init__.py
@@ -218,7 +218,10 @@ def return_redirect(path, environ, response):
else:
path = path_prefix.rsplit('/', 1)[0] + path
scheme = environ['wsgi.url_scheme']
- authority = environ['SERVER_NAME']
+ if 'HTTP_HOST' in environ:
+ authority = environ['HTTP_HOST']
+ else:
+ authority = environ['SERVER_NAME']
port = environ['SERVER_PORT']
if ((scheme == 'http' and port != '80') or
(scheme == 'https' and port != '443')):
diff --git a/rhythmweb/__init__.py b/rhythmweb/__init__.py
index dd9ba91..f6d5f68 100644
--- a/rhythmweb/__init__.py
+++ b/rhythmweb/__init__.py
@@ -42,15 +42,21 @@ class RhythmwebPlugin(rb.Plugin):
self.player.connect ('playing-changed',
self._playing_changed_cb)
)
+ self.db_cb_ids = (
+ self.db.connect ('entry-extra-metadata-notify',
+ self._extra_metadata_changed_cb)
+ )
self.server = RhythmwebServer('', 8000, self)
def deactivate(self, shell):
self.server.shutdown()
self.server = None
- player = shell.get_player()
for id in self.shell_cb_ids:
- player.disconnect(id)
+ self.player.disconnect(id)
+
+ for id in self.db_cb_ids:
+ self.db.disconnect(id)
self.db = None
self.player = None
@@ -61,11 +67,18 @@ class RhythmwebPlugin(rb.Plugin):
def _playing_entry_changed_cb(self, player, entry):
self._update_entry(entry)
+ def _extra_metadata_changed_cb(self, db, entry, field, metadata):
+ if entry == self.player.get_playing_entry():
+ self._update_entry(entry)
+
def _update_entry(self, entry):
if entry:
artist = self.db.entry_get(entry, rhythmdb.PROP_ARTIST) or None
album = self.db.entry_get(entry, rhythmdb.PROP_ALBUM) or None
- title = self.db.entry_get(entry, rhythmdb.PROP_TITLE) or None
+ title = self.db.entry_get(entry, rhythmdb.PROP_TITLE) or ""
+ stream_title = self.db.entry_request_extra_metadata(entry, 'rb:stream-song-title')
+ if stream_title != None and stream_title != "":
+ title = "%s (%s)" % (stream_title, title)
self.server.set_playing(artist, album, title)
else:
self.server.set_playing(None, None, None)
diff --git a/rhythmweb/__init__.py b/rhythmweb/__init__.py
index 3a8e252..a45df6c 100644
--- a/rhythmweb/__init__.py
+++ b/rhythmweb/__init__.py
@@ -19,7 +19,7 @@
import cgi
import os
-from wsgiref.simple_server import make_server
+from wsgiref.simple_server import make_server, WSGIRequestHandler
import gtk
import gobject
@@ -83,6 +83,10 @@ class RhythmwebPlugin(rb.Plugin):
else:
self.server.set_playing(None, None, None)
+class QuietWSGIRequestHandler(WSGIRequestHandler):
+
+ def log_message(self, format, *args):
+ return
class RhythmwebServer(object):
@@ -92,7 +96,7 @@ class RhythmwebServer(object):
self.artist = None
self.album = None
self.title = None
- self._httpd = make_server(hostname, port, self._wsgi)
+ self._httpd = make_server(hostname, port, self._wsgi, handler_class=QuietWSGIRequestHandler)
self._watch_cb_id = gobject.io_add_watch(self._httpd.socket,
gobject.IO_IN,
self._idle_cb)
diff --git a/rhythmweb/__init__.py b/rhythmweb/__init__.py
index a45df6c..2a8549a 100644
--- a/rhythmweb/__init__.py
+++ b/rhythmweb/__init__.py
@@ -164,7 +164,7 @@ class RhythmwebServer(object):
player = open(resolve_path('player.html'))
- response_headers = [('Content-type','text/html')]
+ response_headers = [('Content-type','text/html; charset=UTF-8')]
response('200 OK', response_headers)
return player.read() % { 'playing': playing,
'title': playing,
diff --git a/rhythmweb/__init__.py b/rhythmweb/__init__.py
index f6d5f68..3a8e252 100644
--- a/rhythmweb/__init__.py
+++ b/rhythmweb/__init__.py
@@ -163,7 +163,8 @@ class RhythmwebServer(object):
response_headers = [('Content-type','text/html')]
response('200 OK', response_headers)
return player.read() % { 'playing': playing,
- 'title': playing }
+ 'title': playing,
+ 'host': environ['SERVER_NAME'] }
def _handle_stock(self, environ, response):
path = environ['PATH_INFO']
diff --git a/rhythmweb/player.html b/rhythmweb/player.html
index 952b722..0ed2ac9 100644
--- a/rhythmweb/player.html
+++ b/rhythmweb/player.html
@@ -24,12 +24,12 @@
<html>
<head>
-<title>Rhythmweb %(title)s</title>
+<title>%(title)s - Rhythmweb on %(host)s</title>
<link rel="stylesheet" href="site.css" type="text/css"></head>
<body>
<div id="player">
-<h1>Rhythmweb</h1>
+<h1>Rhythmweb (%(host)s)</h1>
<form method="post" action="/">
<p id="toolbar">
@@ -39,7 +39,7 @@
<button name="action" value="prev"><img alt="Previous" title="Play the previous track" width="24" height="24" src="stock/gtk-media-previous-ltr"/></button>
<button name="action" value="next"><img alt="Next Track" title="Play the next track" width="24" height="24" src="stock/gtk-media-next-ltr"/></button>
<button name="action" value="vol-up"><img alt="Volume Up" title="Turn the volume up" width="24" height="24" src="stock/gtk-go-up"/></button>
-<button name="action" value="vol-down"><img alt="Volume Down" title="Turn the volumen down" width="24" height="24" src="stock/gtk-go-down"/></button>
+<button name="action" value="vol-down"><img alt="Volume Down" title="Turn the volume down" width="24" height="24" src="stock/gtk-go-down"/></button>
</p>
<p id="playing">%(playing)s</p>
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]