/musical-doodle

Last.fm + Song.link integration

Primary LanguageTypeScript

Last.fm & Song.link API Integration

Basic idea: want to leverage to Last.fm API to pull what music I've been listening to for e.g. the past week and generate nice little song.link UI widgets. I've done a bit of research around this before and I believe the (albeit somewhat hacky) steps are:

  • Create Last.fm account & API key (open question: is this API key supposed to be secret?)
  • Grab the JSON API endpoint results for the top tracks for the past week
  • Use the artist + track string to query the iTunes/Apple Music API for their ID
  • Plop that into the song.link embed API

Note: the weirdness in the middle steps are because Last.fm returns a MusicBrainz ID (MBID) which, from my research, doesn't actually get us anywhere useful. And, in practice, not all tracks have a MusicBrainz ID so can't rely on it for anything useful. In an ideal world, would figure out how to convert to a Spotify Track URI but this slightly hacky solution is fine for now.

Usage

Setup

  • git clone this to wherever you desire
  • .env.local as explained below
  • nvm install grabs the LTS (at the time of writing) Node version
  • npm install pulls in dependencies

Running

  • npm start spins up the app locally

Testing

  • npm test runs the minimal test suite

.env.local

You'll need a Last.fm API key and the Last.fm username to be querying against, an example .env.local looks like:

REACT_APP_LAST_FM_API_KEY=abc123
# optional, defaults to:
REACT_APP_LAST_FM_USER=pinjasaur

Bruno

For this project I'm trying out Bruno which is an API client similar to Postman or Insomnia, except it all lives locally in the repo in the bruno/ directory.

If you're on a fresh clone you might need to create the .env symlink for Bruno from the CRA-compliant .env.local:

cd bruno
ln -s ../.env.local .env
cd -

Resources

Copypasta from CRA install

Getting Started with Create React App

This project was bootstrapped with Create React App.

Available Scripts

In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

npm test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

npm run build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

npm run eject

Note: this is a one-way operation. Once you eject, you can’t go back!

If you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.