[telepathy-ashes/master] Added !playsong to make wjt happy.
David Laban
david.laban at collabora.co.uk
Thu Oct 15 05:42:22 PDT 2009
!playsong actually plays ${HOME}/data/song.mp3 but is documented
to play http://www.thesixtyone.com/nuskiffle/song/Go+Murder+a+Fish/19572/
---
ashes/tools/commands.py | 60 ++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 54 insertions(+), 6 deletions(-)
diff --git a/ashes/tools/commands.py b/ashes/tools/commands.py
index 1b2f8fe..ed95f07 100644
--- a/ashes/tools/commands.py
+++ b/ashes/tools/commands.py
@@ -3,15 +3,19 @@ import time
import traceback
import inspect
import types
+import os
import gobject
import telepathy
+import farsight
+import gst
from bases import ChannelListener
from helper_functions import (get_connections, get_property,
green, red, printer, rpartial)
from text import TextChannelEchoer
+from media_echoer import MediaChannelEchoer
class CommandExecutor(TextChannelEchoer):
"""
@@ -112,7 +116,7 @@ class CommandExecutor(TextChannelEchoer):
Opens a voice call to whoever sent this command.
"""
- self.make_call(target, True, False)
+ self.make_call(sender, True, False)
return "Please wait."
def do_videome(self, id, timestamp, sender, type, flags, text):
@@ -121,12 +125,24 @@ class CommandExecutor(TextChannelEchoer):
Opens a video call to whoever sent this command.
"""
- self.make_call(target, True, True)
+ self.make_call(sender, True, True)
return "Please wait."
-
+ def do_playsong(self, id, timestamp, sender, type, flags, text):
+ """
+ !playsong
+
+ Plays "Go Murder A Fish", by Nu Skiffle Brigade. This song is available
+ for download at:
+ http://www.thesixtyone.com/nuskiffle/song/Go+Murder+a+Fish/19572/
+ """
+ if os.path.exists(SongPlayer.song_path):
+ self.make_call(sender, True, False, SongPlayer)
+ return "Please wait."
+ else:
+ return "Sorry. I couldn't locate the song I wanted to play you."
- def make_call(self, target, want_audio, want_video):
+ def make_call(self, target, want_audio, want_video, handler_class=None):
"""
Makes a call to target with audio and video if wanted.
"""
@@ -142,7 +158,39 @@ class CommandExecutor(TextChannelEchoer):
'org.freedesktop.Telepathy.Channel.Type.StreamedMedia.FUTURE.InitialVideo':
want_video,
}
- self.connection[telepathy.interfaces.CONNECTION_INTERFACE_REQUESTS
- ].CreateChannel(request)
+ self.connection.create_channel(request, handler_class)
+
+
+class SongPlayer(MediaChannelEchoer):
+ """
+ Plays the song pointed to by self.song_path over the media channel.
+ """
+ song_path = os.path.expandvars("${HOME}/data/song.mp3")
+
+ def stream_created(self, channel, stream):
+ """
+ Overrides MediaChannelEchoer.stream_created() to play media down it.
+ Doesn't connect src_pad_added because we don't care about incoming
+ media.
+ """
+
+ srcpad = stream.get_property ("sink-pad")
+
+ type = stream.get_property ("media-type")
+ if type == farsight.MEDIA_TYPE_AUDIO:
+ # NOTE: identity sync=true stops the song finishing before we
+ # actually connect, but the remote end still only connects halfway
+ # through the song. We could delay it until src-pad-added, because
+ # that's closer to when the other side is connected, but that's
+ # a massive hack. I'd rather wait until the media spec is less
+ # funky and do it properly if possible.
+ description = "filesrc location=%s ! mad ! audioconvert ! audioresample ! identity sync=true" % self.song_path
+ src = gst.parse_bin_from_description(description, True)
+ elif type == farsight.MEDIA_TYPE_VIDEO:
+ src = gst.element_factory_make ("videotestsrc")
+ src.set_property("is-live", True)
+ self.pipeline.add(src)
+ src.get_pad("src").link(srcpad)
+ src.set_state(gst.STATE_PLAYING)
--
1.5.6.5
More information about the telepathy-commits
mailing list