Skip to content

Instantly share code, notes, and snippets.

@Caedilla
Last active June 8, 2021 22:38
Show Gist options
  • Save Caedilla/9c52063b0489b1a61669cfa871791c7a to your computer and use it in GitHub Desktop.
Save Caedilla/9c52063b0489b1a61669cfa871791c7a to your computer and use it in GitHub Desktop.
IFTTT Youtube liked video to Spotify playlist filter
// Removes stuff from YouTube video names to make it easier to find the song on Spotify
// Add this to the filter section of your IFTTT applet after the Youtube Trigger, before Spotify.
// Spotify title in the applet settings can be whatever (so long as it's not empty) this replaces it.
var title = Youtube.newLikedVideo.Title
// Some videos use a dash or colon instead of hyphen.
var titleSplit = title.split('-')
if (titleSplit.length != 2){
titleSplit = title.split('–')
if (titleSplit.length != 2){
titleSplit = title.split(':')
}
}
if (titleSplit.length == 2) {
var artistName = titleSplit[0].trim()
var trackName = titleSplit[1].trim()
// Remove non-track name stuff
var trackTerms = ['ft. ', 'ft ', 'feat. ', 'feat ', 'featuring ', '(', '['],
sl = trackTerms.length
while (sl--) {
if (trackName.indexOf(trackTerms[sl])!=-1) {
var removeIndex = (trackName.indexOf(trackTerms[sl]))
var removeString = (trackName.slice(removeIndex))
trackName = trackName.replace(removeString, '')
}
}
// Remove subsequent artists
var artistTerms = ['/',' & ',',',' and '],
al = artistTerms.length
while (al--) {
if (artistName.indexOf(artistTerms[al])!=-1){
var removeIndex = (artistName.indexOf(artistTerms[al]))
var removeString = (artistName.slice(removeIndex))
artistName = artistName.replace(removeString,'')
}
}
trackName = trackName.trim()
artistName = artistName.trim()
Spotify.addATrackToAPlaylist.setSearchQuery(trackName)
Spotify.addATrackToAPlaylist.setArtistName(artistName)
} else {
Spotify.addATrackToAPlaylist.skip()
}
@Caedilla
Copy link
Author

Modified from this reddit thread.

This one should result in long song names featuring multiple artists or information such as (Official Video) or [HD] etc. to be removed from the Spotify search query.

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