# Buggy code
def _select_mixer_track(self, mixer, track_label):
    # Look for track with label == MIXER_TRACK, otherwise fallback to
    # master track which is also an output.
    for track in mixer.list_tracks():
        if track_label:
            if track.label == track_label:
                return track
        elif track.flags & (
            gst.interfaces.MIXER_TRACK_MASTER | gst.interfaces.MIXER_TRACK_OUTPUT
        ):
            return track


# Traceback (ZeroDivisionError)
INFO     2013-01-03 15:47:01,091 [7328:MainThread] mopidy.utils.log
Starting Mopidy 0.11.1
INFO     2013-01-03 15:47:01,095 [7328:MainThread] mopidy.utils.log
Platform: Linux-3.2.0-4-amd64-x86_64-with-debian-7.0
INFO     2013-01-03 15:47:01,095 [7328:MainThread] mopidy.utils.log
Python: CPython 2.7.3rc2
DEBUG    2013-01-03 15:47:01,097 [7328:MainThread] mopidy.utils
Loading: mopidy.backends.local.LocalBackend
WARNING  2013-01-03 15:47:01,101 [7328:MainThread] mopidy.backends.local
Could not open tag cache: [Errno 2] No such file or directory: u'/home/levesqu6/.local/share/mopidy/tag_cache'
INFO     2013-01-03 15:47:01,101 [7328:MainThread] mopidy.backends.local
Loading tracks from /home/levesqu6/None using /home/levesqu6/.local/share/mopidy/tag_cache
INFO     2013-01-03 15:47:01,102 [7328:MainThread] mopidy.backends.local
Loading playlists from /home/levesqu6/.local/share/mopidy/playlists
DEBUG    2013-01-03 15:47:01,104 [7328:MainThread] mopidy.utils
Loading: mopidy.backends.spotify.SpotifyBackend
INFO     2013-01-03 15:47:01,104 [7328:Audio-1] mopidy.audio
Audio output set to "alsasink"
DEBUG    2013-01-03 15:47:01,123 [7328:Audio-1] mopidy.audio.mixers.auto
AutoAudioMixer chose: alsamixerelement1
INFO     2013-01-03 15:47:01,124 [7328:Audio-1] mopidy.audio
Audio mixer set to "alsamixer" using track "Bass Boost"
INFO     2013-01-03 15:47:01,127 [7328:SpotifyBackend-4] mopidy.backends.spotify
Mopidy uses SPOTIFY(R) CORE
DEBUG    2013-01-03 15:47:01,129 [7328:SpotifyBackend-4] mopidy.backends.spotify
Connecting to Spotify
DEBUG    2013-01-03 15:47:01,132 [7328:SpotifyThread] mopidy.utils.process
SpotifyThread: Starting thread
DEBUG    2013-01-03 15:47:01,134 [7328:SpotifyThread] mopidy.backends.spotify
System message: 20:47:01.134 I [offline_authorizer.cpp:297] Unable to login offline: no such user
DEBUG    2013-01-03 15:47:01,134 [7328:SpotifyThread] pyspotify.manager.session
No message received before timeout. Processing events
DEBUG    2013-01-03 15:47:01,134 [7328:Dummy-5] mopidy.backends.spotify
System message: 20:47:01.134 I [ap:1752] Connecting to AP ap.spotify.com:4070
DEBUG    2013-01-03 15:47:01,135 [7328:SpotifyThread] pyspotify.manager.session
Will wait 300.041s for next message
ERROR    2013-01-03 15:47:01,139 [7328:MainThread] mopidy.main
float division by zero
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/mopidy/__main__.py", line 61, in main
core = setup_core(audio, backends)
File "/usr/lib/pymodules/python2.7/mopidy/__main__.py", line 164, in setup_core
return Core.start(audio=audio, backends=backends).proxy()
File "/usr/lib/pymodules/python2.7/pykka/actor.py", line 461, in proxy
return _ActorProxy(self)
File "/usr/lib/pymodules/python2.7/pykka/proxy.py", line 99, in __init__
self._known_attrs = self._get_attributes()
File "/usr/lib/pymodules/python2.7/pykka/proxy.py", line 111, in _get_attributes
attr = self._actor._get_attribute_from_path(attr_path)
File "/usr/lib/pymodules/python2.7/pykka/actor.py", line 296, in _get_attribute_from_path
attr = getattr(attr, attr_name)
File "/usr/lib/pymodules/python2.7/mopidy/core/playback.py", line 280, in get_volume
return self.audio.get_volume().get()
File "/usr/lib/pymodules/python2.7/pykka/future.py", line 116, in get
'raise exc_info[0], exc_info[1], exc_info[2]')
File "/usr/lib/pymodules/python2.7/pykka/actor.py", line 194, in _actor_loop
response = self._handle_receive(message)
File "/usr/lib/pymodules/python2.7/pykka/actor.py", line 265, in _handle_receive
return callee(*message['args'], **message['kwargs'])
File "/usr/lib/pymodules/python2.7/mopidy/audio/actor.py", line 393, in get_volume
avg_volume = float(sum(volumes)) / len(volumes)
ZeroDivisionError: float division by zero
DEBUG    2013-01-03 15:47:01,141 [7328:MainThread] mopidy.utils
Loading: mopidy.frontends.mpd.MpdFrontend
DEBUG    2013-01-03 15:47:01,183 [7328:MainThread] mopidy.utils.process
Stopping 0 instance(s) of MpdFrontend
DEBUG    2013-01-03 15:47:01,183 [7328:MainThread] mopidy.utils
Loading: mopidy.frontends.lastfm.LastfmFrontend
DEBUG    2013-01-03 15:47:01,199 [7328:MainThread] mopidy.utils.process
Stopping 0 instance(s) of LastfmFrontend
DEBUG    2013-01-03 15:47:01,200 [7328:Dummy-5] mopidy.backends.spotify
System message: 20:47:01.184 I [ap:1226] Connected to AP: 193.182.8.35:4070
DEBUG    2013-01-03 15:47:01,200 [7328:MainThread] mopidy.utils
Loading: mopidy.frontends.mpris.MprisFrontend
DEBUG    2013-01-03 15:47:01,247 [7328:MainThread] mopidy.utils.process
Stopping 0 instance(s) of MprisFrontend
DEBUG    2013-01-03 15:47:01,248 [7328:MainThread] mopidy.utils.process
Stopping 1 instance(s) of Core
DEBUG    2013-01-03 15:47:01,248 [7328:MainThread] mopidy.utils
Loading: mopidy.backends.local.LocalBackend
DEBUG    2013-01-03 15:47:01,248 [7328:MainThread] mopidy.utils.process
Stopping 1 instance(s) of LocalBackend
DEBUG    2013-01-03 15:47:01,248 [7328:MainThread] mopidy.utils
Loading: mopidy.backends.spotify.SpotifyBackend
DEBUG    2013-01-03 15:47:01,249 [7328:MainThread] mopidy.utils.process
Stopping 1 instance(s) of SpotifyBackend
DEBUG    2013-01-03 15:47:01,249 [7328:SpotifyBackend-4] mopidy.backends.spotify
Logging out from Spotify
DEBUG    2013-01-03 15:47:01,249 [7328:MainThread] mopidy.utils.process
Stopping 1 instance(s) of Audio
DEBUG    2013-01-03 15:47:01,250 [7328:MainThread] mopidy.utils.process
All actors stopped.

# Fixed code
def _select_mixer_track(self, mixer, track_label):
    # Ignore tracks without volumes, then look for track with
    # label == settings.MIXER_TRACK, otherwise fallback to first usable
    # track hoping the mixer gave them to us in a sensible order.

    usable_tracks = []
    for track in mixer.list_tracks():
        if not mixer.get_volume(track):
            continue

        if track_label and track.label == track_label:
            return track
        elif track.flags & (
            gst.interfaces.MIXER_TRACK_MASTER | gst.interfaces.MIXER_TRACK_OUTPUT
        ):
            usable_tracks.append(track)

    if usable_tracks:
        return usable_tracks[0]