Created
July 30, 2024 19:09
-
-
Save koiuo/1c68e108b8d5635c644c816908b9b403 to your computer and use it in GitHub Desktop.
Open Spotify HTTPs URLs from command line on Linux
This file contains 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
#!/usr/bin/env bash | |
# Convert HTTPS Spotify URL to spotify URI | |
convert_spotify_url() { | |
local url="$1" | |
# Remove query parameters | |
url="${url%%\?*}" | |
# Extract the path after the domain | |
local path="${url#https://open.spotify.com/}" | |
# Split the path into type and id | |
local type="${path%%/*}" | |
local id="${path#*/}" | |
# Create the spotify: URI | |
local spotify_uri="spotify:${type}:${id}" | |
echo "$spotify_uri" | |
} | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <spotify_https_url>" | |
exit 1 | |
fi | |
uri="$(convert_spotify_url "$1")" | |
echo "$uri" | |
dbus-send --print-reply --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify \ | |
/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri \ | |
"string:$uri" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment