πŸš€ DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more β†’
Socket
Book a DemoInstallSign in
Socket

rikn-music-fetcher

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rikn-music-fetcher

A TypeScript wrapper for Discord bots, unifying music fetching from YouTube, SoundCloud (comming soon), Spotify with ytmusic-api, yt-dlp, lrclib. Robust fallback & link parsing for reliable music search, download, streaming.

Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

🎡 rikn-music-fetcher

Version License Top language npm

πŸ‡»πŸ‡³ TiαΊΏng Việt

πŸ“– Introduction

rikn-music-fetcher is a TypeScript wrapper library that unifies multiple popular music sources (YouTube Music, Spotify) with capabilities for searching, streaming, downloading, and fetching lyrics (synced lyrics). Specially designed for Discord Music Bots with smart fallback features and flexible URL parsing.

✨ Key Features

  • 🎡 Multi-platform: YouTube Music, Spotify (SoundCloud in development)
  • 🎀 Synced Lyrics Support: Plain & synced lyrics from LRCLIB
  • πŸ“‘ Direct Streaming: Direct audio streaming via yt-dlp
  • πŸ” Smart Fallback: Auto-fallback from Spotify to YouTube when streaming
  • πŸ”— Intelligent URL Parsing: Auto-detect platform from URL
  • πŸ“¦ TypeScript: Full type safety with TypeScript
  • ⚑ Auto-update: Auto-update yt-dlp binary

πŸ“¦ Installation

npm install rikn-music-fetcher

πŸš€ Quick Start

Initialize Client

import RiknClient from 'rikn-music-fetcher';

const client = new RiknClient({
  spotify: {
    clientId: 'YOUR_SPOTIFY_CLIENT_ID',
    clientSecret: 'YOUR_SPOTIFY_CLIENT_SECRET'
  },
  ytmusic: {
    cookiesPath: './cookies-ytm.txt', // Optional: cookies for better stability, from music.youtube.com (Netscape format)
    GL: 'US',
    HL: 'en'
  },
  ytdlp: {
    autoUpdate: true, // Auto-update yt-dlp
    updateIntervalDays: 7,
  }
});

Search Songs

// Search on YouTube Music (default)
const tracks = await client.searchSong('Imagine Dragons Believer');

// Search on Spotify
const spotifyTracks = await client.searchSong('Shape of You', 'spotify');

console.log(tracks[0].title, tracks[0].artist);

Search and Stream Instantly

// Find first song and get stream URL
const song = await client.searchFirstAndStream('Shape of You');

console.log('Stream URL:', song.streamUrl);
console.log('Track info:', song.title, song.artist);

Get Info from URL

// Auto-detect platform
const track = await client.getSongByUrl(
  'https://open.spotify.com/track/3n3Ppam7vgaVa1iaRUc9Lp',
  true // withStreamUrl = true to get stream URL
);

// Or from YouTube
const ytTrack = await client.getSongByUrl(
  'https://www.youtube.com/watch?v=kJQP7kiw5Fk'
);

Get Playlist

// Spotify playlist
const playlist = await client.getSongsByPlaylist(
  'https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M'
);

// YouTube Music playlist
const ytPlaylist = await client.getSongsByPlaylist(
  'https://music.youtube.com/playlist?list=RDCLAK5uy_...'
);

console.log(`Playlist has ${playlist.length} songs`);

Stream Audio

import { createWriteStream } from 'fs';

// Stream from URL (auto-fallback if Spotify)
const stream = await client.streamSongByUrl(
  'https://www.youtube.com/watch?v=kJQP7kiw5Fk'
);

// Pipe to file or Discord voice connection
stream.pipe(createWriteStream('output.m4a'));

// Or use with Discord.js
const connection = joinVoiceChannel({...});
const player = createAudioPlayer();
player.play(createAudioResource(stream));

Get Lyrics

// Get exact lyrics
const lyrics = await client.getLyrics(
  'Shape of You',
  'Ed Sheeran',
  'Divide', // optional
  233 // duration in seconds (optional)
);

console.log('Plain lyrics:', lyrics.plainLyrics);
console.log('Synced lyrics:', lyrics.syncedLyrics);

// Search lyrics
const searchResults = await client.searchLyrics('Believer', 'Imagine Dragons');

πŸ“‚ Project Structure

rikn-music-fetcher-wrapper/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ RiknClient.ts           # Main client class
β”‚   β”œβ”€β”€ index.ts                # Export entry point
β”‚   β”œβ”€β”€ providers/
β”‚   β”‚   β”œβ”€β”€ spotify.ts          # Spotify API wrapper
β”‚   β”‚   β”œβ”€β”€ youtube.ts          # YouTube Music API wrapper
β”‚   β”‚   β”œβ”€β”€ yt-dlp.ts           # yt-dlp wrapper
β”‚   β”‚   └── lyrics.ts           # LRCLIB API wrapper
β”‚   β”œβ”€β”€ types/
β”‚   β”‚   β”œβ”€β”€ music.type.ts       # Common music types
β”‚   β”‚   β”œβ”€β”€ spotify.type.ts
β”‚   β”‚   β”œβ”€β”€ yt.type.ts
β”‚   β”‚   └── lyrics.type.ts
β”‚   β”œβ”€β”€ constants/
β”‚   β”‚   β”œβ”€β”€ spotify.constants.ts
β”‚   β”‚   β”œβ”€β”€ yt.contants.ts
β”‚   β”‚   └── lyrics.contants.ts
β”‚   └── core/
β”‚       └── utils.ts            # Utility functions
β”œβ”€β”€ tests/
β”‚   └── config.example.ts       # Config template
β”œβ”€β”€ dist/                       # Compiled output
β”œβ”€β”€ bin/                        # yt-dlp binaries
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ .npmignore
└── README.md

πŸ”§ API Reference

RiknClient

Constructor

new RiknClient(config?: RiknClientConfig)

RiknClientConfig:

{
  spotify?: {
    clientId: string;
    clientSecret: string;
    timeout?: number;
  };
  ytmusic?: {
    cookiesPath?: string; // Path to cookies file from music.youtube.com (Netscape format)
    GL?: string; // Country code (e.g., 'VN', 'US')
    HL?: string; // Language code (e.g., 'vi', 'en')
  };
  ytdlp?: {
    binDir?: string;
    cookiesPath?: string; // Path to cookies file from youtube.com (Netscape format)
    autoUpdate?: boolean;
    updateIntervalDays?: number;
  };
}

Methods

  • searchSong(query: string, platform?: Platform): Promise<Track[]>
  • searchFirstAndStream(query: string): Promise<SongWithStream | null>
  • getSongByUrl(url: string, withStreamUrl?: boolean): Promise<SongWithStream | null>
  • getSongsByPlaylist(url: string): Promise<Track[]>
  • streamSongByUrl(url: string): Promise<NodeJS.ReadableStream>
  • getLyrics(trackName: string, artistName: string, albumName?: string, duration?: number): Promise<Lyrics | null>
  • searchLyrics(trackName: string, artistName: string, albumName?: string): Promise<Lyrics[] | null>

πŸ› οΈ Build & Development

# Clone repository
git clone https://github.com/Riikon-Team/rikn-music-fetcher-wrapper.git
cd rikn-music-fetcher-wrapper

# Install dependencies
npm install

# Build
npm run build

# Development
npm run dev

# Test
npm test

πŸ“ Important Notes

⚠️ Beta Version: This library is currently in beta stage. Some features may not be fully complete or thoroughly tested.

Cookies (YouTube Music)

To improve stability when using YouTube Music API, you should provide a cookies file:

Spotify Credentials

Get credentials at Spotify Developer Dashboard:

  • Create new app
  • Get Client ID and Client Secret
  • No redirect URI needed (uses Client Credentials Flow)

🌟 Credits & Sources

This library is built upon these amazing open-source projects:

Special thanks to all maintainers and contributors of these projects! πŸ™

🀝 Contributing

We welcome all contributions from the community:

  • Fork the repo
  • Create new branch (git checkout -b feature/AmazingFeature)
  • Commit your changes (git commit -m 'Add some AmazingFeature')
  • Push to branch (git push origin feature/AmazingFeature)
  • Create Pull Request

Bug Reports & Feature Requests

Please create an issue with:

  • Detailed problem description
  • Example code to reproduce
  • Environment details (OS, Node version, etc.)

πŸ“‹ Roadmap

  • Complete test coverage
  • Add SoundCloud support
  • Cache layer for search results
  • Rate limiting & retry logic
  • Download progress tracking
  • Batch operations
  • CLI tool

πŸ“„ License

This project is distributed under the GNU General Public License v3.0.

See the LICENSE file for more details.

Made with ❀️ by Riikon Team

πŸ› Found a bug? Report it
πŸ’‘ Have an idea? Share it
⭐ Like it? Star it

searchFirstAndStream(query)

Search and get direct stream URL for first result.

getSongByUrl(url, withStreamUrl?)

Get track info from URL (auto-detect platform).

getSongsByPlaylist(url)

Get all tracks from playlist URL.

streamSongByUrl(url)

Get readable stream for audio (YouTube only).

getLyrics(trackName, artistName, ...)

Fetch lyrics from LRCLIB.

License

GPL-3.0

Keywords

music-fetcher

FAQs

Package last updated on 04 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts