Explore Discogs from the currently playing album using Raycast and LastFM

X @urre

Explore Discogs from the currently plaing song using Raycast

If you’re looking for a fast and highly extensible launcher, Raycast is an excellent choice. As someone who has used Alfred for a long time, I recently made the switch and have been impressed with the features and functionality of Raycast. One of the things I often do when listening to music is browse Discogs to explore new albums and records. With this script command, I can open Discogs and automatically search for the current album I’m listening to, which I find very handy. To fetch the music I’m currently listening to, I use LastFM to scrobble tracks from TIDAL. Many music services and apps supports LastFM natively, or as plugins. Even though some apps supports getting the currently playing track/artist/album via Apple Script, it’s not possible for all apps. That’s why I like the option of using LastFM, since I already scrobble all my music.

Raycast scripts

Raycast executes your local scripts and enables you to perform frequent and useful commands without having to open a terminal window. Getting started with Raycast Scripts

Under Raycast Preferences you can go to “Extensions → Scripts and find your scripts. Manage them, set aliases, record a hotkey and more.

Creating the script

Explore Discogs from the currently plaing song using Raycast

When you launch Raycast, type “script” and key down to “Create Script Command”. Select template, mode, title, description and more.

All scripts have parameters to instruct Raycast on how to process and output your request. You can read more about them here. In the example, we have set the @raycast.mode parameter to silent, which means that the script will run instantly and silently, allowing you to access the newly opened page when you are ready.

#!/usr/bin/env bash

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Discogs Now Playing
# @raycast.mode silent
# Optional parameters:
# @raycast.icon icon.png
# @raycast.iconDark icon.png
# Documentation:
# @raycast.description Open Discogs and explore the currently playing album
# @raycast.author Urban Sanden
# @raycast.authorURL https://urre.me

# Read secrets from the .env file
source "./.env"

# Specify LastFM API and specify JSON as the format

# Query the LastFM API with cURL
result=`curl -s ${URL}`

# Get currently playing track using jq, Artist and Album name, flatten and remove whitespace
nowplaying=`echo ${result} | jq -r '[.recenttracks.track[0].artist["#text"], .recenttracks.track[0].album["#text"]] | flatten[]' | xargs`

# Now open Discogs in the browser
open "https://discogs.com/search?q=${nowplaying}"

I’m using jq. It’s a lightweight and flexible command-line JSON processor. You can install it with brew install jq

LastFM credentials

Create an .env file with your credentials


How to use it

Play some music, open Raycast and start typing Disc…

Get it on GitHub