Skip to content

radio4000/media-now

Repository files navigation

The Burning of the Library at Alexandria in 391 AD. Ambrose Dudley

Media Now

Parse URLs to extract provider and identifier. Fetch metadata from YouTube, Vimeo, Spotify, Discogs, MusicBrainz, SoundCloud, and direct audio/video files. No API keys.

Meant to be useful for people dealing with music tracks in one shape or another (hello https://radio4000.com).

All functions return at least provider, id and payload (the original response).

import { getMedia, parseUrl, parseTitle, cleanTitle, discoverDiscogsUrl } from 'media-now'

cleanTitle('Bohemian Rhapsody (Official Video) [HD]')
// 'Bohemian Rhapsody'

parseTitle('Nikolaj Nørlund - Hvid røg og tekno')
// { artist: 'Nikolaj Nørlund', title: 'Hvid røg og tekno', original: '...' }

parseUrl('https://vimeo.com/123456789')
// { provider: 'vimeo', id: '123456789' }

parseUrl('https://example.com/song.mp3')
// { provider: 'file', id: 'https://example.com/song.mp3', kind: 'audio' }

await getMedia('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
// { provider, id, url, title, thumbnail, author, payload }

await discoverDiscogsUrl('Massive Attack - Teardrop')
// 'https://www.discogs.com/release/...'

Providers

Note, the getMedia() methods automatically detects provider and calls these internally. But you can of course use them directly as well.

import { youtube } from 'media-now/providers/youtube'
import { vimeo } from 'media-now/providers/vimeo'
import { spotify } from 'media-now/providers/spotify'
import { discogs } from 'media-now/providers/discogs'
import { musicbrainz } from 'media-now/providers/musicbrainz'
import { soundcloud } from 'media-now/providers/soundcloud'
import { file } from 'media-now/providers/file'

youtube.fetch(id)              // ~100ms - basic metadata via oEmbed
youtube.fetchExtended(id)      // ~1s - includes music card data (song, artist, album)
youtube.search(query)
vimeo.fetch(id)
spotify.fetch(id)
soundcloud.fetch(id)           // id is 'user/track'
discogs.fetch(id)
discogs.fetchMaster(id)
musicbrainz.search(query)
musicbrainz.fetchRecording(id)
musicbrainz.fetchRelease(id)
file.fetch(url, kind)          // kind is 'audio' or 'video', title extracted from filename

Development

To validate the project

bun run check
bun test
bun run build

Releasing

Pushing a tag prefixed with v triggers the GitHub Actions workflow that publishes to npm.

# bump version in package.json
git commit -am "2.1.0"
git tag v2.1.0
git push origin main v2.1.0

History

We wrote this kind of package several times in the past: media-now, media-now-deno & media-url-parser.

Links

About

Get media information from YouTube and Vimeo videos, Spotify tracks and Discogs releases.

Topics

Resources

Stars

Watchers

Forks

Contributors