@@ -58,7 +58,10 @@ def main():
58
58
perform_spotify_action ("Next" )
59
59
elif args .prev :
60
60
perform_spotify_action ("Previous" )
61
-
61
+ elif args .songuri :
62
+ perform_spotify_action ("OpenUri" , f"string:spotify:track:{ args .songuri } " )
63
+ elif args .listuri :
64
+ perform_spotify_action ("OpenUri" , f"string:spotify:playlist:{ args .listuri } " )
62
65
63
66
def start_shell ():
64
67
while True :
@@ -82,32 +85,37 @@ def start_shell():
82
85
def add_arguments ():
83
86
parser = argparse .ArgumentParser (description = __doc__ )
84
87
for argument in get_arguments ():
85
- parser .add_argument (argument [0 ], help = argument [1 ], action = "store_true" )
88
+ if not argument [2 ]:
89
+ parser .add_argument (argument [0 ], help = argument [1 ], action = "store_true" )
90
+ else :
91
+ parser .add_argument (argument [0 ], help = argument [1 ], action = "store" )
86
92
parser .add_argument ("--client" , action = "store" , dest = "client" ,
87
93
help = "sets client's dbus name" , default = "spotify" )
88
94
return parser .parse_args ()
89
95
90
96
91
97
def get_arguments ():
92
98
return [
93
- ("--version" , "shows version number" ),
94
- ("--status" , "shows song name and artist" ),
95
- ("--statusposition" , "shows song name and artist, with current playback position" ),
96
- ("--statusshort" , "shows status in a short way" ),
97
- ("--song" , "shows the song name" ),
98
- ("--songshort" , "shows the song name in a short way" ),
99
- ("--artist" , "shows artist name" ),
100
- ("--artistshort" , "shows artist name in a short way" ),
101
- ("--album" , "shows album name" ),
102
- ("--position" , "shows song position" ),
103
- ("--arturl" , "shows album image url" ),
104
- ("--playbackstatus" , "shows playback status" ),
105
- ("--play" , "plays the song" ),
106
- ("--pause" , "pauses the song" ),
107
- ("--playpause" , "plays or pauses the song (toggles a state)" ),
108
- ("--lyrics" , "shows the lyrics for the song" ),
109
- ("--next" , "plays the next song" ),
110
- ("--prev" , "plays the previous song" )
99
+ ("--version" , "shows version number" , False ),
100
+ ("--status" , "shows song name and artist" , False ),
101
+ ("--statusposition" , "shows song name and artist, with current playback position" , False ),
102
+ ("--statusshort" , "shows status in a short way" , False ),
103
+ ("--song" , "shows the song name" , False ),
104
+ ("--songshort" , "shows the song name in a short way" , False ),
105
+ ("--artist" , "shows artist name" , False ),
106
+ ("--artistshort" , "shows artist name in a short way" , False ),
107
+ ("--album" , "shows album name" , False ),
108
+ ("--position" , "shows song position" , False ),
109
+ ("--arturl" , "shows album image url" , False ),
110
+ ("--playbackstatus" , "shows playback status" , False ),
111
+ ("--play" , "plays the song" , False ),
112
+ ("--pause" , "pauses the song" , False ),
113
+ ("--playpause" , "plays or pauses the song (toggles a state)" , False ),
114
+ ("--lyrics" , "shows the lyrics for the song" , False ),
115
+ ("--next" , "plays the next song" , False ),
116
+ ("--prev" , "plays the previous song" , False ),
117
+ ("--songuri" , "plays the track at the provided Uri" , True ),
118
+ ("--listuri" , "plays the playlist at the provided Uri" , True ),
111
119
]
112
120
113
121
@@ -253,11 +261,18 @@ def get_spotify_property(spotify_property):
253
261
sys .exit (1 )
254
262
255
263
256
- def perform_spotify_action (spotify_command ):
257
- Popen ('dbus-send --print-reply --dest=org.mpris.MediaPlayer2."%s" ' %
258
- client +
259
- '/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player."%s"' %
260
- spotify_command , shell = True , stdout = PIPE )
264
+ def perform_spotify_action (spotify_command , extra_arg = None ):
265
+ command_list = [
266
+ "dbus-send" ,
267
+ "--print-reply" ,
268
+ f"--dest=org.mpris.MediaPlayer2.{ client } " ,
269
+ "/org/mpris/MediaPlayer2" ,
270
+ f"org.mpris.MediaPlayer2.Player.{ spotify_command } " ,
271
+ ]
272
+ if extra_arg is not None :
273
+ command_list .append (extra_arg )
274
+ command_string = " " .join (command_list ) # could avoid this by taking out shell=False below
275
+ Popen (command_string , shell = True , stdout = PIPE )
261
276
262
277
def show_position ():
263
278
metadata = get_spotify_property ("Metadata" )
0 commit comments