Use Python/IAC/AppleScript to Automate Spotify in Live/Push

Share your favorite Ableton Live tips, tricks, and techniques.
Post Reply
jasonbrent
Posts: 2
Joined: Tue Jun 27, 2017 3:50 am

Use Python/IAC/AppleScript to Automate Spotify in Live/Push

Post by jasonbrent » Tue Jun 27, 2017 3:59 am

This requires a little bit of unix knowledge, the python code could be cleaned up, and I'm a newbie to ableton, so I'm sure there are better ways of doing this, but....

TL:DR - Using AppleScript, MIDI IAC Driver, some kludgy Python, you can control Spotify from Ableton/Push

Prerequisite: Some ability to capture your spotify output. I'm using "Loopback" from Rogue Amoeba

MacOS:
1) Install SpotifyControl applescript from github
https://github.com/dronir/SpotifyControl
1a) Create the symlink to /usr/local/bin/spotify per the SpotifyControl instructions.
2) In 'Audio Midi Setup', create a new IAC driver port called "Spotify"

Ableton:
3) Under the MIDI configuration for the "Spotify" IAC port, set Input=Remote, Output=Track
3a) Create a new MIDI track, output to channel 16 (or whatever you want, edit the script accordingly)
3b) For each command you want to execute, create a midi note, with looping off
For mine, I named them "Track", "Playlist", "Restart", "Stop", "Play/Pause", "Next", "Prev", and "Shuffle" corresponding to notes 127-120 respectively.
I've edited the python script argument for note 127 and 126 to go to a specific song, and a specific playlist respectively.
4) From the command line, install "mido" and "python-rtmidi" modules:
e.g., "pip install mido" and "pip install python-rtmidi"

Python:

Save/run the code below in a Terminal:

Code: Select all

import mido
import os

DEBUG=False

# My desired MIDI channel
channel = 15

midiNotes = {
	127: {"command": "spotify play", "arg": "EnteraSpotifyURIHereToPlayIt" },
	126: {"command": "spotify play", "arg": "EnterASpotifyPlaylistURIHereToPlayIt"},
	125: {"command": "spotify jump", "arg": "0"},
	124: {"command": "spotify stop", "arg": "" },
	123: {"command": "spotify play/pause", "arg": ""},
	122: {"command": "spotify next", "arg": ""},
	121: {"command": "spotify prev", "arg": ""},
	120: {"command": "spotify shuffle", "arg": ""},
}

with mido.open_input('IAC Driver Spotify') as inport:
	for msg in inport:
		if DEBUG: print(msg)
		# only process "note_off" messages
		if msg.type == "note_off" and msg.channel == channel:
			try:
				if DEBUG: print(midiNotes[msg.note])
				os.system(midiNotes[msg.note]['command'] + " " + midiNotes[msg.note]['arg'])
			except KeyError as e:
				print("Unknown command received: ", (e))
Hope this helps someone...

-j

brianroach
Posts: 10
Joined: Mon Nov 12, 2012 8:49 pm

Re: Use Python/IAC/AppleScript to Automate Spotify in Live/Push

Post by brianroach » Mon Apr 06, 2020 8:45 pm

This is great! Thank you for sharing. Setting this up now.

jasonbrent
Posts: 2
Joined: Tue Jun 27, 2017 3:50 am

Re: Use Python/IAC/AppleScript to Automate Spotify in Live/Push

Post by jasonbrent » Mon Apr 06, 2020 8:54 pm

I've not tested this since Catalina -- but I used the setup as I described for a couple of years without issue. Feedback is welcomed.

-j

Post Reply