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

@euterpe.js/music-library

v1.0.12

Published

A simple music library, acting as a Local DB as JS Object. Contains everything a person would need to store their music data for website playback.

Downloads

43

Readme

music-library

A simple music library, acting as a Local DB as JS Object. Contains everything a person would need to store their music data for website playback.

How to use:

Simple demo using euterpe player here

Recommended to make a db.ts file where one instanciates their database, then exports it for use elsewhere.

db.ts

import { DB, Artist, Song, RefTo, Ref, Platforms } from "@euterpe/music-library";
export const db = new DB

db.add([
    //The IDs are added incrementally & are 0 based., so first artists ID added is 0, next 1 etc...
    //You can specify the ID manually if you want
    new Artist({
        name: "Jamie xx",
    }),
    new Artist({
        name: "Machinedrum",
    }),
    new Artist({
        name: "Tanerélle",
    }),
    new Artist({
        name: "Mono/Poly",
    }),
    new Artist({
        name: "IMANU",
        links: [
            [Platforms.Spotify, new URL("https://open.spotify.com/artist/5Y7rFm0tiJTVDzGLMzz0W1?si=DRaZyugTTIqlBHDkMGKVqA&nd=1")]
        ]
    })])
db.add([
    new Song({
        //Refrences are constructed as such. This allows to get to the artist from either collection or song
        artists: [new Ref(RefTo.Artists, 2), new Ref(RefTo.Artists, 3), new Ref(RefTo.Artists, 4)],
        duration: 252,
        name: "Star",
        remix_artists: [new Ref(RefTo.Artists, 5)],
        url: new URL("http://127.0.0.1:4200/Machinedrum, Tanerelle & Mono Poly - Star (IMANU Remix) final.mp3")
    }),
    new Song({
        //If you don't like guessing the IDs, then this is also a way to do it
        artists: [new Ref(RefTo.Artists, db.artists.find((a) => a.name == "Jamie xx")!.id!)],
        duration: 331,
        name: "Sleep Sound",
        url: new URL("http://127.0.0.1:4200/Jamie xx - Sleep Sound.mp3")
    }),
])

And then we can easily get any data we want elsewhere, like: main.ts

import { db } from "./db";

let curr_song_id = 1;
// Some buttons in the DOM to act on the library, snippet is using euterpe-js/player
document.querySelector("#previous")?.addEventListener("click", () => {
    curr_song_id--
    if (curr_song_id < 0) curr_song_id = 2
    music_player.try_new_song(db.songs[curr_song_id].url.pathname).then((s) => {
        change_current_song_text(db)
        music_player.try_play().catch((err) => { console.log(err) })
    }, (e) => { console.log(e) })
})
document.querySelector("#next")?.addEventListener("click", () => {
    curr_song_id++
    if (curr_song_id > 2) curr_song_id = 0
    music_player.try_new_song(db.songs[curr_song_id].url.pathname).then((s) => {
        change_current_song_text(db)
        music_player.try_play().catch((err) => { console.log(err) })
    }, (e) => { console.log(e) })
})

Example on how to produce final titles:

  • If the current song has multiple titles, add them with , between, then append " - " and song name.
  • If the song has remix artists, we add a " (", add all artists with ", " between, and even make them link to artists' links if there are some.
  • Results with given db: - Machinedrum, Tanerélle, Mono/Poly - Star (<a href="{{spotify link}}">IMANU</a> Remix) - Jamie xx - Sleep Sound
function change_current_song_text(db: DB) {
    const curr_song = db.songs[curr_song_id]
    let final_text = ""

    for (const artist of curr_song.artists) {
        const curr_artist = artist.get(db) as Artist
        final_text += curr_artist.name + ", "
    }

    final_text = final_text.slice(0, final_text.length - 2) // remove trailing ", "
    final_text += " - " + curr_song.name

    if (curr_song.remix_artists.length > 0) {
        final_text += " ("

        for (const artist of curr_song.remix_artists) {
            const curr_artist = artist.get(db) as Artist
            if (curr_artist.links && curr_artist.links.length > 0) {
                //returns "found a link! Spotify"
                console.log("found a link! " + Platforms[curr_artist.links[0][0]])

                const url = curr_artist.links[0][1]
                final_text += `<a href=${url}>${curr_artist.name}</a>, `
            } else {
                final_text += curr_artist.name + ", "
            }
        }

        final_text = final_text.slice(0, final_text.length - 2) // remove trailing ", "
        final_text += " Remix)"
    }

    elem_curr_song!.innerHTML = final_text
}

What data this database stores right now:

class Song {
    name: string
    artists: Ref[] //Ref(RefTo.Artist, {ID})
    url: URL
    duration: number
    remix_artists: Ref[] //Ref(RefTo.Artist, {ID})
    publish_date?: Date
    in_collection?: Ref //Ref(RefTo.Collection, {ID})
    cover?: URL
    bpm?: number
    key?: string
    fft_data?: number[]
    id?: ID
}
class Artist {
    name = ""
    pfp?: URL
    songs: Ref[] //Ref(RefTo.Song, {ID})
    collections: Ref[] //Ref(RefTo.Collection, {ID})
    links?: [Platforms, URL][]
    id?: ID
}
//can be used as EP, Album etc...
class Collection {
    artists: Ref[] //Ref(RefTo.Artist, {ID})
    songs: Ref[] //Ref(RefTo.Song, {ID})
    cover: URL
    duration: number
    publish_date?: Date
    id?: ID
}