<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Muffin Research Labs &#187; Music</title>
	<atom:link href="http://muffinresearch.co.uk/archives/category/music/feed/" rel="self" type="application/rss+xml" />
	<link>http://muffinresearch.co.uk</link>
	<description>the personal blog of Stuart Colville covering modern web development techniques and best practices</description>
	<lastBuildDate>Thu, 15 Mar 2012 10:10:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Spotify ScreenSaver Toggle with D-bus</title>
		<link>http://muffinresearch.co.uk/archives/2010/11/03/spotify-screensaver-toggle-with-dbus/</link>
		<comments>http://muffinresearch.co.uk/archives/2010/11/03/spotify-screensaver-toggle-with-dbus/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 00:10:39 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=1027</guid>
		<description><![CDATA[UPDATE! &#8211; see This post for the latest version of the spotify screensaver toggle The latest version of the spotify client for linux (0.4.8) has added partial mpris support. This is great as it means controlling spotify via D-bus is far easier than the previous hacks using wmctrl and xvkbd. I&#8217;ve updated the screensaver toggle [...]]]></description>
			<content:encoded><![CDATA[<p class="update">UPDATE! &#8211; see <a href="http://muffinresearch.co.uk/archives/2011/10/27/linux-spotify-screensaver-d-bus-script-update/">This post for the latest version of the spotify screensaver toggle</a></p>
<p>The latest version of the spotify client for linux (0.4.8) has added partial <a href="http://xmms2.org/wiki/MPRIS">mpris support</a>.</p>
<p>This is great as it means controlling spotify via D-bus is far easier than the previous hacks using <a href="http://muffinresearch.co.uk/archives/2010/09/13/ubuntu-spotify-screensaver-toggle/">wmctrl and xvkbd</a>. </p>
<p>I&#8217;ve updated the screensaver toggle script to use spotify&#8217;s D-bus interface to play/pause spotify. This also means that I&#8217;ve been able to de-couple the script from having to run the screensaver which a big improvement on the old version.</p>
<p>To run it just add the script to your start-up items.</p>
<p><img src="http://mrl.staticfil.es/img/startup_program.png" alt="Edit Startup Program Dialogue" /></p>
<p>Here&#8217;s the code, which is a lot more concise compared to the previous version.</p>
<p class="update">Updated to use Mpris2 as of <a href="http://code.projectfondue.com/stuart.colville/spotify-screensaver-toggle/revision/9">revision 9</a> for v0.4.8.306&#8230;</p>
<pre><code>#!/usr/bin/env python

"""
Title: Spotify Screensaver Toggle
Author: Stuart Colville, http://muffinresearch.co.uk/
License: BSD

Requires Spotify Linux Preview.

Usage:

 * Save the script
 * Ensure it is executable: chmod +x /path/to/script
 * Add the script to your start-up items. 

"""

import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop

class SpotifyScreenSaverPause(object):
    """This pauses and plays spotify when the screensaver is activated"""

    def __init__(self):
        """init class."""
        dbus_loop = DBusGMainLoop(set_as_default=True)
        self.bus = dbus.SessionBus(mainloop = dbus_loop)
        self.loop = gobject.MainLoop()
        self.start_listen()
        self.was_playing = 0
        self.loop.run()

    def start_listen(self):
        """Listen to screensaver ActiveChanged events from dbus."""
        screensaver = self.bus.get_object('org.gnome.ScreenSaver',
                                                  '/org/gnome/ScreenSaver')
        screensaver.connect_to_signal("ActiveChanged", self.play_pause)

    def play_pause(self, *args, **kwargs):
        """Toggle play/pause."""
        try:
            spotify = self.bus.get_object("org.mpris.MediaPlayer2.spotify", "/")
            spotify_iface = dbus.Interface(spotify, dbus_interface="org.freedesktop.MediaPlayer2")
            if self.was_playing:
                spotify_iface.Play()
                self.was_playing = 0
            else:
                if spotify_iface.GetMetadata():
                    self.was_playing = 1
                spotify_iface.Pause()
        except dbus.exceptions.DBusException, e:
            # Ignore exception caused by spotify not being started.
            if e.get_dbus_name() != 'org.freedesktop.DBus.Error.ServiceUnknown':
                raise

if __name__ == "__main__":
    ss = SpotifyScreenSaverPause()
</code></pre>
<p>See the latest version of the code here <a href="http://code.projectfondue.com/stuart.colville/spotify-screensaver-toggle/annotate/head:/spotify_dbus_screensaver">Spotify Screensaver Toggle</a> </p>
<p>If you want to investigate what&#8217;s possible with D-bus and spotify, <a href="http://live.gnome.org/DFeet/">D-feet</a> is an excellent tool for investigating D-bus:</p>
<p><a href="http://mrl.staticfil.es/img/d-feet-lg.png"><img src="http://mrl.staticfil.es/img/d-feet-sm.png" alt="D-feet D-bus Debugger" />Click for a larger version.</a></p>
<h3>Further Examples</h3>
<p>Here&#8217;s an example to get the metadata from a track currently playing. (Note: if Spotify isn&#8217;t playing this will be an empty dictionary.)</p>
<pre><code>>>> import dbus
>>> bus = dbus.SessionBus()
>>> spotify = bus.get_object("org.mpris.spotify", "/")
>>> spotify_iface = dbus.Interface(spotify, dbus_interface="org.freedesktop.MediaPlayer")
>>> spotify_iface.GetMetadata()
dbus.Dictionary({dbus.String(u'album'): dbus.String(u'Getz/Gilberto #2', variant_level=1), dbus.String(u'title'): dbus.String(u"Here's That Rainy Day", variant_level=1), dbus.String(u'artist'): dbus.String(u'Stan Getz', variant_level=1), dbus.String(u'year'): dbus.Int32(1964, variant_level=1), dbus.String(u'location'): dbus.String(u'spotify:track:1RIfT0Y0TwP2M38pLLfDeJ', variant_level=1), dbus.String(u'time'): dbus.UInt32(242L, variant_level=1), dbus.String(u'tracknumber'): dbus.Int32(4, variant_level=1)}, signature=dbus.Signature('sv'))
>>> print spotify_iface.GetMetadata().get("title")
Here's That Rainy Day
>>> print spotify_iface.GetMetadata().get("location")
spotify:track:1BTO5gV9xSAB7EOBKSlcFY
>>></code></pre>
<p class="update"><del datetime="2011-03-22T20:48:34+00:00">With the latest Spotify update to use MPRIS2 (0.4.8.306.xxx) &#8211; the TrackChanged signal has gone and there&#8217;s no PropertiesChanged signal as per MPRIS2 spec http://www.mpris.org/2.0/spec/ I&#8217;ll update the notification example script below as soon as that is rectified.</del><ins datetime="2011-03-22T20:48:34+00:00"> It was there all along. I&#8217;ve updated the code to reflect the use of PropertiesChanged</ins></p>
<p>To take that example further here&#8217;s a demo that listens to the <del datetime="2011-03-22T20:48:34+00:00">TrackChanged</del><ins>PropertiesChanged</ins> event. It uses the notification id so we can replace the notification details as you move through the tracks. This avoids waiting for the timeout before displaying the current track information.</p>
<pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Title: Spotify Notification Demo
Author: Stuart Colville, http://muffinresearch.co.uk
License: BSD

"""

import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop
import pynotify

class SpotifyNotifier(object):

    def __init__(self):
        """initialise."""
        bus_loop = DBusGMainLoop(set_as_default=True)
        bus = dbus.SessionBus(mainloop=bus_loop)
        loop = gobject.MainLoop()
        self.spotify = bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
        self.spotify.connect_to_signal("PropertiesChanged", self.track_changed)
        self.notify_id = None
        loop.run()

    def track_changed(self, interface, changed_props, invalidated_props):
        """Handle track changes."""
        metadata = changed_props.get("Metadata", {})
        if metadata:
            if pynotify.init("Spotify Notifier Demo"):

                title = unicode(metadata.get("xesam:title").encode("latin1"))
                album = unicode(metadata.get("xesam:album").encode("latin1"))
                artist = unicode(metadata.get("xesam:artist").encode("latin1"))

                alert = pynotify.Notification(title,
                                 "by %s from %s" % (artist, album))
                if self.notify_id:
                    alert.props.id = self.notify_id
                alert.set_urgency (pynotify.URGENCY_NORMAL)
                alert.show()
                self.notify_id = alert.props.id

if __name__ == "__main__":
    SpotifyNotifier()</code></pre>
<p>Note this notification demo assumes spotify is running to set-up the listener, so it&#8217;s not something you can just set running at start-up unless you use it to wrap the start-up of spotify.</p>
<p><img src="http://mrl.staticfil.es/img/spotify-notification.jpg" alt="Spotify Notifications of Track Changes" /></p>
<p>Both scripts are BSD licensed so feel free to use and adapt to your own purposes.</p>
]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2010/11/03/spotify-screensaver-toggle-with-dbus/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Spotify: Linking to a specific time in a track</title>
		<link>http://muffinresearch.co.uk/archives/2009/11/11/spotify-linking-to-a-specific-time-in-a-track/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/11/11/spotify-linking-to-a-specific-time-in-a-track/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 11:56:10 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[social]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=757</guid>
		<description><![CDATA[For a while I&#8217;ve wanted to be able to share a link to a track on spotify so that it jumps the right place. An example is when learning covers for the band I play in; or just to point out a great part of the track. The good new is that this is already [...]]]></description>
			<content:encoded><![CDATA[<p>For a while I&#8217;ve wanted to be able to share a link to a track on spotify so that it jumps the right place. An example is when learning covers for the band I play in; or just to point out a great part of the track.</p>
<p>The good new is that this is already possible! I asked a question on <a href="http://getsatisfaction.com/spotify/topics/allow_linking_to_a_point_into_a_track">Get Satisfaction</a> and a Spotify employee Emil Hesslow answered straight away that this feature already exists. Here&#8217;s some examples:</p>
<ul class="ext">
<li>Check out George Benson&#8217;s guitar break: <a href="http://open.spotify.com/track/39Bi2scq80BWdgnxz2llWT%2304%3A04">Uncle Albert/Admiral Halsey 4:04</a></li>
<li>A Nice hammond organ break from Greg Rolie: <a href="http://open.spotify.com/track/6s3pzloNKkO3dzZaHaKaoi%230%3A46">Toussaint L&#8217;Overture 0:46</a></li>
</ul>
<p>You can also use the spotify protocol:</p>
<p>e.g: <a href="spotify:track:39Bi2scq80BWdgnxz2llWT#04:04">spotify:track:39Bi2scq80BWdgnxz2llWT#04:04</a></p>
<p>The format for the link is just a simple fragment identifier added to the end of the link in the format #mins:secs e.g: #4:04</p>
<p>From using this (I&#8217;m running Spotify under wine) I&#8217;ve found you need to URLencode this in the &#8220;http://open.spotify&hellip;&#8221; links for it to work so #4:04 becomes %2304%3A04.</p>
]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/11/11/spotify-linking-to-a-specific-time-in-a-track/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Amazon now offers DRM free mp3s in the UK</title>
		<link>http://muffinresearch.co.uk/archives/2008/12/03/amazon-now-offers-drm-free-mp3s-in-the-uk/</link>
		<comments>http://muffinresearch.co.uk/archives/2008/12/03/amazon-now-offers-drm-free-mp3s-in-the-uk/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 22:31:20 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=406</guid>
		<description><![CDATA[Amazon&#8217;s Mp3 store is now available in the UK which is great news. They seem to have a lot of tracks and albums available and track pricing is variable but seems tio start at the 69p which undercuts Apple&#8217;s iTunes music store by quite a bit. Amazon&#8217;s tracks are DRM free tracks which means that [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://muffinresearch.co.uk/i/amazon-mp3.jpg" alt="Amazon's mp3 downloader" /></p>
<p>Amazon&#8217;s Mp3 store is now available in the UK which is great news. They seem to have a lot of tracks and albums available and track pricing is variable but seems tio start at the 69p which undercuts Apple&#8217;s iTunes music store by quite a bit. </p>
<p>Amazon&#8217;s tracks are <acronym title="Digital Rights Management">DRM</acronym> free tracks which means that you will always have access to your music. Whereas DRM tracks could become unplayable should the DRM service be switched off in the future. Think it won&#8217;t happen? Sadly there&#8217;s been several cases of DRM services being shutdown. <a href="http://news.cnet.com/8301-1023_3-9998504-93.html">MSN and Yahoo have both shut-down DRM based services in the past</a> so it&#8217;s a big problem potentially. Clearly if Amazon can negotiate their way around the DRM problem companies like Apple should be able to just as well. (Granted apple does have the iTunes Plus tracks which are DRM free but this is a Minor subset of their overall catalogue.)</p>
<p>Album pricing seems to start at around Â£3.00 which is surprisingly aggressive, and it&#8217;s good to see major players like iTunes getting some decent competition. Also right now there seems to be lots of recently released albums available for Â£3.00 such as the <a href="http://www.amazon.co.uk/gp/product/B001GTPI7O?ie=UTF8&#038;tag=muffinresearc-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=B001GTPI7O">Kings Of Leon album &#8211; Only By The Night</a>. Can&#8217;t really complain at paying Â£3.00 for that. It&#8217;s Â£7.99 on the iTunes store.</p>
<p>The bit-rate is 256 kbps and whilst this is ok it would be good to see this upped in the future. Also I&#8217;d personally love to see the addition of open lossless formats such as <a href="http://flac.sourceforge.net/">flac</a>. Though I can see that this possibly has a limited audience.</p>
<p>To download the tracks a software downloader is required but crucially this is available for OSX, windows <em>and</em> Linux. Purchasing a track is straight forward enough &#8211; a download of a .amz file is triggered which you open with the downloader and it proceeds to download the tracks.</p>
<p>Provided their music catalogue continues to grow to match their CD market I&#8217;m pretty sure Amazon&#8217;s UK mp3 offering will be a success. And Apple needs to start to wake up to this competition &#8211; whilst alternative mp3 services such as 7Digitial might not be widely known to the average Joe &#8211; Amazon is well known and anyone who uses amazon is likely to find the mp3 store pretty quickly if they&#8217;d not already heard of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2008/12/03/amazon-now-offers-drm-free-mp3s-in-the-uk/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Radio Paradise</title>
		<link>http://muffinresearch.co.uk/archives/2004/05/14/radio-paradise/</link>
		<comments>http://muffinresearch.co.uk/archives/2004/05/14/radio-paradise/#comments</comments>
		<pubDate>Fri, 14 May 2004 01:11:00 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://dev.muffinresearch.co.uk/archives/2004/05/14/radio-paradise/</guid>
		<description><![CDATA[I&#8217;ve recently found out about radio paradise which I&#8217;m listening to via my apple itunes software. It can be found at radioparadise.com. It&#8217;s playlist is quite varied but I&#8217;ve been finding I like most of the stuff they play. There&#8217;s a whole bunch of tracks that I&#8217;m going to hunt down after listening. I really [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently found out about radio paradise which I&#8217;m listening to via my <a href="http://www.apple.com/itunes/">apple itunes</a> software. It can be found at <a href="http://www.radioparadise.com">radioparadise.com</a>. It&#8217;s playlist is quite varied but I&#8217;ve been finding I like most of the stuff they play. There&#8217;s a whole bunch of tracks that I&#8217;m going to hunt down after listening. I really liked <a href="http://www.amazon.co.uk/exec/obidos/redirect?tag=muffinresearc-21%26link_code=xm2%26camp=2025%26creative=165953%26path=http://www.amazon.co.uk/gp/redirect.html%253fASIN=B0000AQVCN%2526tag=muffinresearc-21%2526lcode=xm2%2526cID=2025%2526ccmID=165953%2526location=/o/ASIN/B0000AQVCN%25253FSubscriptionId=0EMV44A9A5YT1RVDGZ82" title="View product details at Amazon">Bela Fleck&#8217;s track &#8220;gravity wheel&#8221;</a>. I&#8217;ve also got into listening to <a href="http://www.amazon.co.uk/exec/obidos/redirect?tag=muffinresearc-21%26link_code=xm2%26camp=2025%26creative=165953%26path=http://www.amazon.co.uk/gp/redirect.html%253fASIN=B0001AUAY0%2526tag=muffinresearc-21%2526lcode=xm2%2526cID=2025%2526ccmID=165953%2526location=/o/ASIN/B0001AUAY0%25253FSubscriptionId=0EMV44A9A5YT1RVDGZ82" title="View product details at Amazon">Vida Blue</a> who are a spin off from Phish. Really nice phreaky jazz sounds with a solid funk groove &#8211; highly recommended.</p>
]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2004/05/14/radio-paradise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

