Blacklist Spotify tracks/artists

I was tired of hearing songs and artists I hate, and not having any way to globally ban them. So, I put together this very simple flow.

It relies on a Spotify connection in Home Assistant, along with a Home Assistant input_boolean named input_boolean.spotify_skipper_enabled. When true, the skipper will be active. Otherwise, it'll be disabled. This is just for convenient enabling/disabling of the flow.

To setup the blacklists, open the is track blacklisted? node, and place the track and artist names you don't want to hear in the corresponding arrays.

This will run as often as the Spotify entity updates. By default, it is rather slow, so you can use a simple NodeRED or Home Assistant automation to poll it and keep it updated, like this.

Video

[{"id":"8d40d4c4e8931e0e","type":"server-state-changed","z":"64a0843b03b54b5b","name":"spotify changed","server":"734558bc.cd8f48","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"media_player.spotify_ben_scholer","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"playing","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":120,"y":500,"wires":[["600451992bb3f8a1"],[]]},{"id":"467ea80d6eb3c24a","type":"function","z":"64a0843b03b54b5b","name":"is track blacklisted?","func":"// Add a cooldown so we don't double-skip.\nconst lastSkipped = flow.get('lastSkipped') || 0;\nconst currentTime = Date.now();\n\nif (currentTime - lastSkipped < 5000) {\n    return [null, msg]; // Exit if last skip was less than 5 seconds ago\n}\n\nconst trackBlacklist = [\n    \"Stoned Again\",\n];\nconst artistBlacklist = [\n    \"Matt Maeson\",\n];\n\nlet shouldSkip = false;\n\n// Change this line to match track names, assume `media_title` holds the track name\nif (trackBlacklist.some(blacklisted => msg.data.new_state.attributes.media_title.includes(blacklisted)) ||\n    artistBlacklist.some(blacklisted => msg.data.new_state.attributes.media_artist.includes(blacklisted))) {\n    shouldSkip = true;\n    msg.payload = true;\n}\n\nif (shouldSkip) {\n    // Update lastSkipped timestamp\n    flow.set('lastSkipped', currentTime);\n\n    return msg;\n}\n\nreturn null;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":500,"wires":[["8b196b640dd21f20"]]},{"id":"8b196b640dd21f20","type":"api-call-service","z":"64a0843b03b54b5b","name":"skip","server":"734558bc.cd8f48","version":5,"debugenabled":false,"domain":"media_player","service":"media_next_track","areaId":[],"deviceId":[],"entityId":["media_player.spotify_ben_scholer"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":730,"y":500,"wires":[[]]},{"id":"600451992bb3f8a1","type":"api-current-state","z":"64a0843b03b54b5b","name":"skipper enabled?","server":"734558bc.cd8f48","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.spotify_skipper_enabled","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":330,"y":500,"wires":[["467ea80d6eb3c24a"],[]]},{"id":"bf091f7614735a30","type":"comment","z":"64a0843b03b54b5b","name":"skip blacklisted tracks and artists","info":"","x":170,"y":460,"wires":[]},{"id":"734558bc.cd8f48","type":"server","name":"Home Assistant","addon":true}]

Flow Info

Created 1 year, 9 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x1)
  • function (x1)
Other

Tags

  • spotify
  • homeassistant
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option