Last active
November 9, 2018 17:15
-
-
Save zamboOlino/71f67d8614a239fd8ad1 to your computer and use it in GitHub Desktop.
Now you can get the ALBUM ARTWORK -- set track_artwork_path to update_artwork(track_album, track_artwork, folder_path)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set output_folder to (choose folder with prompt "Please choose an output directory") | |
set folder_path to POSIX path of output_folder | |
property file_extension : ".mp3" | |
-- property file_extension : ".m4a" (* If format is changed to AAC *) | |
property check_delay : 0.1 (* How often to check for a new track *) | |
property write_delay : 2 (* How long to wait before updating file name *) | |
property stop_delay : 1 (* How long to wait before updating final file after playback stops *) | |
set track_counter to 1 | |
tell application "Spotify" | |
if player state is playing then pause | |
set track_name_x to (name of current track) | |
set track_artist_x to (artist of current track) | |
set track_album_x to (album of current track) | |
set track_artwork_x to (artwork of current track) | |
set track_album_artist_x to (album artist of current track) | |
--set track_year_x to (year of current track) | |
end tell | |
tell application "Audio Hijack Pro" | |
activate | |
set theSession to my getSession() | |
tell theSession | |
-- Recording file settings | |
set output folder to output_folder | |
set output name format to "%tag_comment" | |
set comment tag to track_counter | |
-- Update Track Session data | |
set title tag to track_name_x | |
set artist tag to track_artist_x | |
set album tag to track_album_x | |
set album artist tag to track_album_artist_x | |
--set year tag to track_year_x | |
-- Audio format settings | |
--set recording format to {encoding:MP3, bit rate:320, sample rate:44100, channels:Stereo, style:VBR} | |
--set recording format to {encoding:AAC, bit rate:256, sample rate: 44100, channels:Stereo} | |
end tell | |
if hijacked of theSession is false then start hijacking theSession | |
start recording theSession | |
end tell | |
set track_counter to (track_counter + 1) | |
tell application "Spotify" | |
-- Start playing Spotify from beginning of current track | |
set player position to 0 | |
set sound volume to 100 | |
play | |
set track_name to (name of current track) | |
set track_artist to (artist of current track) | |
set track_album to (album of current track) | |
set track_artwork to (artwork of current track) | |
set track_number to (track number of current track) | |
set track_album_artist to (album artist of current track) | |
--set track_year to (year of current track) | |
-- Add delay for resolve 1s recording and stop problem | |
delay 1 | |
repeat until player state is not playing | |
-- Get new track data | |
set track_name_x to (name of current track) | |
set track_artist_x to (artist of current track) | |
set track_album_x to (album of current track) | |
set track_artwork_x to (artwork of current track) | |
set track_album_artist_x to (album artist of current track) | |
--set track_year_x to (year of current track) | |
-- On change of track | |
if track_name is not equal to (name of current track) then | |
my update_artwork(track_album, track_artwork, folder_path) | |
tell application "Audio Hijack Pro" | |
tell theSession | |
set comment tag to track_counter | |
set title tag to track_name_x | |
set artist tag to track_artist_x | |
set album tag to track_album_x | |
set album artist tag to track_album_artist_x | |
--set year tag to track_year_x | |
split recording | |
end tell | |
end tell | |
delay write_delay | |
-- Update the file name from track_counter.mp3 to artist - ... - track.mp3 | |
my update_filename(track_counter - 1, track_artist, track_name, track_album, track_number, folder_path) | |
set track_counter to (track_counter + 1) | |
-- Get new track data | |
set track_name to (name of current track) | |
set track_artist to (artist of current track) | |
set track_album to (album of current track) | |
set track_artwork to (artwork of current track) | |
set track_number to (track number of current track) | |
set track_album_artist to (album artist of current track) | |
--set track_year to (year of current track) | |
end if | |
delay check_delay | |
end repeat | |
-- Stop recording and edit final file name once playback has stopped | |
delay stop_delay | |
tell application "Audio Hijack Pro" | |
stop recording theSession | |
stop hijacking theSession | |
end tell | |
my update_filename(track_counter - 1, track_artist, track_name, track_album, track_number, folder_path) | |
end tell | |
on replace_chars(this_text, search_string, replacement_string) | |
set AppleScript's text item delimiters to the search_string | |
set the item_list to every text item of this_text | |
set AppleScript's text item delimiters to the replacement_string | |
set this_text to the item_list as string | |
set AppleScript's text item delimiters to "" | |
return this_text | |
end replace_chars | |
-- Update file name so it can be tagged using Kid3 | |
on update_filename(track_counter, track_artist, track_name, track_album, track_number, folder_path) | |
set old_file to ("\"" & folder_path & track_counter & file_extension & "\"") | |
set new_file to (replace_chars(track_artist, "\"", "") & " - " & replace_chars(track_name, "\"", "") & file_extension & "\"") | |
set temp_final_file to replace_chars(new_file, "/", "-") | |
set final_file to ("\"" & folder_path & temp_final_file) | |
do shell script ("mv " & old_file & " " & final_file) | |
end update_filename | |
-- Update Artwork of current track | |
on update_artwork(track_album, track_artwork, folder_path) | |
set newPath to ((folder_path as text) & (my replace_chars(track_album, ":", "_")) & ".tiff") as text | |
try | |
set fileRef to (open for access newPath with write permission) | |
write track_artwork to fileRef starting at 0 | |
tell me to close access fileRef | |
on error m number n | |
log n | |
log m | |
try | |
tell me to close access fileRef | |
end try | |
end try | |
return newPath | |
end update_artwork | |
-- Set Spotify session in Audio Hijack Pro | |
on getSession() | |
tell application "Audio Hijack Pro" | |
set sessionName to "Spotify" | |
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 |
I had only now the time to test again your script, following your instructions... and it works!
My fault were using a spotify newer version and adding the script in audiohijack (instead should be used "standalone", after everything)
Only one thing.. is it normal that Album Cover are saved as .tiff images in the same folder as audio files?
Thanks!
Another question: after a while, spotify disconnects and so, the script end to run. Is it because I'm not using premium spotify or simply because after x time it disconnects?
I have the same problem.
But till now i cant solved it i don't finde the problem, i think it comes from spotifiy if the app switch the track.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I check it out and hope to make an update :)