Skip to content

Instantly share code, notes, and snippets.

@iolloyd
Created September 2, 2012 20:09
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save iolloyd/3604106 to your computer and use it in GitHub Desktop.
Save iolloyd/3604106 to your computer and use it in GitHub Desktop.
Use Audio Hijack Pro to record Spotify tracks while you listen
* Script to record and tag spotify tracks, by Lloyd Moore *)
(* Make sure you are already recording in Audio Hijack Pro with a session called 'spotifySession' *)
tell application "Spotify"
set currentTrack to (current track)
set trackName to (name of currentTrack)
tell application "Audio Hijack Pro"
set theSession to my getSession()
end tell
repeat
if trackName is not equal to (name of currentTrack) then
set trackName to name of current track
set trackArtist to artist of current track
my recordTrack(theSession, trackName, trackArtist)
end if
delay 1
end repeat
end tell
on recordTrack(theSession, trackName, trackArtist)
tell application "Audio Hijack Pro"
tell theSession
split recording
set output folder to "~/Desktop"
set output name format to "%tag_title -- %tag_artist"
set title tag to trackName
set artist tag to trackArtist
end tell
end tell
end recordTrack
on getSession()
tell application "Audio Hijack Pro"
set sessionName to "spotifySession"
try
set theSession to (first item of (every session whose name is sessionName))
theSession is not null
on error
set theSession to (make new application session at end of sessions)
set name of theSession to sessionName
end try
end tell
return theSession
end getSession
@vinsheep
Copy link

vinsheep commented Sep 5, 2012

doesn't work the way I want it to.. Sometimes the song name gets duplicated but the files are actually 2 different songs.

So for example I got 2 files like:
"Courage -- The Whitest Boy Alive.mp3"
"Courage -- The Whitest Boy Alive1.mp3"

am I doing something wrong?

@rohitrs
Copy link

rohitrs commented Sep 9, 2012

Hi Lloydmoore..I created an account just to thank you. I tried out your script a few hours back and was amazed at how well it works. Cheers for this brilliant solution.

@Machiel692
Copy link

Hi Lloydmoore,

Could I please ask you to help me out with running this script? I have tried every possible way of running the script (from the Applescript-editor, so outside Audio Hijack Pro, and from within Audio Hijack Pro, at the Input tab and on the Recording tab "When recording finishes") but don't seem to get it to work. Within Audio Hijack Pro I am getting Applescript error 1708. I am an absolute noob with Applescript. Could you please help me out by providing a step-by-step fool-proof idiot-guide of making your script work? I'm sure you would make millions of Spotify users on the Mac absolutely happy.....

@ryanaslett
Copy link

@Machiel692 - save it as an applescript file (spotthejack.scpt) - also, do not include lines 1-2, those comments do not work in applescript.

Also, I fixed the problem that rohitrs was having by re-arranging the split and the data assignment. Additionally I added all the other useful metadata fields that spotify provides, like album name so that it populates the id3 tags - see my fork (https://gist.github.com/4340205) of this gist.

@iolloyd
Copy link
Author

iolloyd commented Dec 28, 2012

good work @ryanaslett

@zippy1982
Copy link

Hi!

I really want this to work for me. So I've created a new session called spotifySession. In the Input tab I've ticket Open URL/File/Applescript and linked to the script ryanaslett posted, which I've called spotthejack.scpt.

However the programme then freezes when I press Hijack. Can anyone help please?

Thanks!
Zippy

@marzzed
Copy link

marzzed commented Jan 14, 2013

  1. download.
  2. unzip
  3. open AHP.
  4. create new session "spotifySession"
  5. select session on left and choose application spotify and tick box "open file..." (and choose downloaded file).
  6. click "hijack" -> error -1728
  7. press ok (dismiss).
  8. click record
  9. start song in spotify (should be opened by AHP)
  10. recording starts. (file appears: spotifySession.mp3 on desktop)
  11. next song named spotifySession 1.mp3

other times I get error 1708.

So... on my end this script is not working :-(

@denverdigiman
Copy link

I'm having the same problem vinsheep was having... I get two files with the same name... the 2nd song is actually a different song... its the next song that played... after that, all the files are named one off from what the song really is... and I also have the problem that zippy1982 is having, where if I tell my AHJ 'spotifySession' to run the script, AHJ freezes when I press the Hijack button... the only way I can get it to work, is to open the applescript in AppleScripte editor, and click the run button, and then do the AHJ hijack... it works, so if I don't get the freezing part fixed, no biggie.. though I'd like to get the duplicate filename issue fixed, as it means I have to re-hijack every song after the duplicates, as everything is wrong after it does that.

update: I switched to using ryanaslett's fork, and that seems to have resolved the duplicate issue, as well as the other features he mentioned... now just need to solve the issue with AHJ locking when I set up my AHJ session to run the script.

@Dynalon
Copy link

Dynalon commented May 16, 2013

Any chance to extract the song number of the album and put in the filename? Like 01-artist_titlle.mp3 etc?

@inspire22
Copy link

seems useless... can anyone get this to do anything besides freeze?

@balboah
Copy link

balboah commented Sep 6, 2013

@tiffanygwilson
Copy link

I know this thread is a little old now, but I was still having problems with the file splitting and tagging properly (even with balboah's update). I cobbled together a few similar scripts to get one that works for me; see my fork of this gist (https://gist.github.com/tiffanygwilson/1914c3b7724e65d736f6). I also added some automation for starting/stopping Spotify and the recording session and the option to select the output folder upon running the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment