#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import dbus

def busaware(func):
    try:
        bus = dbus.SessionBus().get_object('org.mpris.MediaPlayer2.spotify', '/org/mpris/MediaPlayer2')
    except dbus.exceptions.DBusException:
        sys.exit(1)

    return lambda *args: func(bus, *args)

@busaware
def get_player(bus):
    return dbus.Interface(bus, 'org.mpris.MediaPlayer2.Player')

@busaware
def get_property(bus, name):
    interface = dbus.Interface(bus, 'org.freedesktop.DBus.Properties')
    return interface.Get('org.mpris.MediaPlayer2.Player', name)


if __name__ == '__main__':
    try:
        arg = sys.argv[1]
    except IndexError:
        print('Command was not specified')
        sys.exit(2)

    if arg == 'current':
        playing = get_property('PlaybackStatus') == 'Playing'
        if not playing:
            sys.exit(0)

        metadata = get_property('Metadata')
        title = metadata['xesam:artist'][0] + ' - ' + metadata['xesam:title']
        trimmed_title = (title[:35] + '...') if len(title) > 38 else title

        print '♫', trimmed_title
    elif arg == 'play':
        get_player().Play()
    elif arg == 'pause':
        get_player().Pause()
    elif arg == 'toggle':
        get_player().PlayPause()
    elif arg == 'next':
        get_player().Next()
    elif arg == 'previous':
        get_player().Previous()
    elif arg == 'stop':
        get_player().Stop()
    else:
        print 'Unknown command'
        sys.exit(3)

@@ -63,36 +63,69 @@
 bus%0A
-%0Adef busaware(func):%0A    try
+import argparse%0A%0Aclass SpotifyControl:%0A    def __init__(self)
 :%0A  
@@ -130,16 +130,21 @@
         
+self.
 bus = db
@@ -235,228 +235,17 @@
 2')%0A
-    except dbus.exceptions.DBusException:%0A        sys.exit(1)%0A%0A    return lambda *args: func(bus, *args)%0A%0A@busaware%0Adef get_player(bus):%0A    return dbus.Interface(bus, 'org.mpris.MediaPlayer2.Player')%0A%0A@busaware%0Adef get_
+%0A    def 
 prop
@@ -249,19 +249,20 @@
 roperty(
-bus
+self
 , name):
@@ -266,16 +266,20 @@
 e):%0A    
+    
 interfac
@@ -297,16 +297,21 @@
 terface(
+self.
 bus, 'or
@@ -342,16 +342,20 @@
 rties')%0A
+    
     retu
@@ -415,181 +415,35 @@
 e)%0A%0A
-%0Aif __name__ == '__main__':%0A    try:%0A        arg = sys.argv%5B1%5D%0A    except IndexError:%0A        print('Command was not specified')%0A        sys.exit(2)%0A%0A    if arg == '
+    def print_
 current
-'
+(self)
 :%0A  
@@ -458,20 +458,21 @@
 aying = 
-get_
+self.
 property
@@ -543,19 +543,14 @@
     
-sys.exit(0)
+return
 %0A%0A  
@@ -566,20 +566,21 @@
 adata = 
-get_
+self.
 property
@@ -783,31 +783,111 @@
 tle%0A
+%0A
     
-elif arg == 'play':
+def send(self, signal):%0A        player = dbus.Interface(self.bus, 'org.mpris.MediaPlayer2.Player')
 %0A   
@@ -898,126 +898,449 @@
  get
-_
+attr(
 player
-().Play
+, signal)()%0A%0A%0Adef main
 ()
+:
 %0A    
-elif arg =
+parser = argparse.ArgumentParser()%0A    subparsers 
 = 
-'
 pa
-use':%0A        get_player().Pause()%0A    elif arg == 'toggle':%0A        get_player().
+rser.add_subparsers(metavar='action')%0A%0A    parser_current = subparsers.add_parser('current', help='Print out a current song')%0A    parser_current.set_defaults(func=SpotifyControl.print_current)%0A%0A    parser_toggle = subparsers.add_parser('toggle', help='Toggle between Play/Pause')%0A    parser_toggle.set_defaults(func=lambda spotify: spotify.send('
 Play
@@ -1348,120 +1348,320 @@
 ause
-()
+'))%0A
 %0A    
-elif arg == 'next':%0A        get_player().
+parser_next = subparsers.add_parser('next', help='Play a next song')%0A    parser_next.set_defaults(func=lambda spotify: spotify.send('
 Next
-(
+')
 )%0A
+%0A
     
-elif arg == 'previous':%0A        get_player().
+parser_previous = subparsers.add_parser('previous', help='Play a previous song')%0A    parser_previous.set_defaults(func=lambda spotify: spotify.send('
 Previous
 ()%0A 
@@ -1660,121 +1660,214 @@
 ious
-()%0A    elif arg == 'stop':%0A        get_player().Stop()%0A    else:%0A        print 'Unknown command'%0A        sys.exit(3
+'))%0A%0A    args = parser.parse_args()%0A%0A    try:%0A        spotify = SpotifyControl()%0A        args.func(spotify)%0A    except dbus.exceptions.DBusException:%0A        sys.exit(1)%0A%0A%0Aif __name__ == '__main__':%0A    main(
 )%0A

Use argparse for parameter parsing in spotify.py