npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

s3-music-library

v1.0.5

Published

API for retrieving music data in an S3 bucket

Downloads

22

Readme

S3MusicLibrary

What is it?

This module helps you turn an S3 bucket into a music library. It provides a convenient API for querying your music data.

Example Usage

const S3MusicLibrary = require("s3-music-library")

const musicLibrary = new S3MusicLibrary(
    AWS_S3_BUCKET,
    AWS_ACCESS_KEY_ID,
    AWS_SECRET_ACCESS_KEY
)

musicLibrary.fetchData()
    .then(() => {
        console.log(musicLibrary.filter({
            artist: "Artist1"
        }))
    })

Setup

First and foremost, you should have an S3 bucket with music data organized in folders according to the following format: s3://[artist]/[album]/[track.(mp3|flac)].

To install the module, execute npm install --save s3-music-library.

Require it at the top of your file, e.g. const S3MusicLibrary = require("s3-music-library").

Instantiate a new S3MusicLibrary instance with the following code:

const s3MusicLibrary = new S3MusicLibrary(
  AWS_S3_BUCKET, 
  AWS_ACCESS_KEY_ID, 
  AWS_SECRET_ACCESS_KEY
)

Source these variables from .env or however you'd like. Always keep them secret and never expose them to the client.

API

.fetchData()

You'll need to fetch data from your S3 bucket before doing anything else. Because this request is asynchronous, your data queries will fall within a .then() callback function.

fetchData calls _initializeStore, which, in turn, calls _parseListFormat and _parseAlbumFormat. These methods populates the s3MusicLibrary object's store with your music data in listFormat and albumFormat.

.filter(queryObject)

This method call's the lodash _.find method on the library instance's _store.albumFormat. Its result set only contains exact matches.

Example usage:

s3MusicLibrary.filter({
  artist: "Artist1"
})`

.search(key)

This method compares a string search key against all URLs in the instance's _store.listFormat.

s3MusicLibrary.search("artist1")`

Store

After the raw data is retrieved from S3, it's parsed and saved in the S3MusicLibrary object's store.

._store.listFormat

This returns a list of every track in your bucket, structured as follows:

{
    url: "Artist1/Album1/Track1.mp3"
    artist: "Artist1",
    album: "Album1",
    track: "Track1.mp3"
}

._store.albumFormat

This returns a list of albums structured as follows:

{ 
    artist: "Artist1",
    album: "Album1",
    tracks: [
        { title: "Track1", url: "Artist1/Album1/Track1.mp3" },
        { title: "Track2", url: "Artist1/Album1/Track2.mp3" },
        { title: "Track3", url: "Artist1/Album1/Track3.mp3" },
    ],
}

._store.artistFormat

This returns a list of artists structured as follows:

{ 
    artist: "Artist1",
    albums:[ 
        {
            artist: "Artist1"
            album: "Album1",
            tracks: [
                { title: "Track1", url: "Artist1/Album1/Track1.mp3" },
                { title: "Track2", url: "Artist1/Album1/Track2.mp3" },
                { title: "Track3", url: "Artist1/Album1/Track3.mp3" },
            ]
        },
        {
            artist: "Artist1"
            album: "Album2",
            tracks: [
                { title: "Track1", url: "Artist1/Album2/Track1.mp3" },
                { title: "Track2", url: "Artist1/Album2/Track2.mp3" },
                { title: "Track3", url: "Artist1/Album2/Track3.mp3" },
            ]
        },
    ]
}

In general, it's better to access data in the object's store through its getters. These are detailed below.

Getters

Note that these aren't method calls. The following are getters that retreive/filter data from the object's store.

.artists

Returns a list of artists in your library.

.albums

Returns a list of albums in your library, equivalent to ._store.albumFormat.

.tracks

Returns a list of tracks in your library, equivalent to ._store.listFormat.