Skip to content

Instantly share code, notes, and snippets.

@dnnsmnstrr
Last active April 23, 2023 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnnsmnstrr/cab9bbeca50da62f2ac7580ed61f7c0f to your computer and use it in GitHub Desktop.
Save dnnsmnstrr/cab9bbeca50da62f2ac7580ed61f7c0f to your computer and use it in GitHub Desktop.
PastePal transform Spotify URL to URI
function transform(clip) {
const pathRegex = /^[a-z]+:\/\/[^:\/]+(:[0-9]+)?\/(.*?)(\/[0-9]+)?(\?.*)?$/
const uriPath = clip.text.replace(pathRegex, '$2');
const spotifyUri = "spotify:" + uriPath.replaceAll('/', ':')
return spotifyUri;
}
@dnnsmnstrr
Copy link
Author

Ported to BTT:

async (clipboardContentString) => {
    const pathRegex = /^[a-z]+:\/\/[^:\/]+(:[0-9]+)?\/(.*?)(\/[0-9]+)?(\?.*)?$/
    const uriPath = clipboardContentString.replace(pathRegex, '$2');
    const spotifyUri = "spotify:" + uriPath.replaceAll('/', ':')
    return spotifyUri;
}

@dnnsmnstrr
Copy link
Author

dnnsmnstrr commented Apr 23, 2023

Codelime formatter:

function format(text) {
    const pathRegex = /^[a-z]+:\/\/[^:\/]+(:[0-9]+)?\/(.*?)(\/[0-9]+)?(\?.*)?$/
    const uriPath = text.replace(pathRegex, '$2');
    const spotifyUri = "spotify:" + uriPath.replaceAll('/', ':')
    return spotifyUri;
}

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