π΅ rikn-music-fetcher

π»π³ 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',
GL: 'US',
HL: 'en'
},
ytdlp: {
autoUpdate: true,
updateIntervalDays: 7,
}
});
Search Songs
const tracks = await client.searchSong('Imagine Dragons Believer');
const spotifyTracks = await client.searchSong('Shape of You', 'spotify');
console.log(tracks[0].title, tracks[0].artist);
Search and Stream Instantly
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
const track = await client.getSongByUrl(
'https://open.spotify.com/track/3n3Ppam7vgaVa1iaRUc9Lp',
true
);
const ytTrack = await client.getSongByUrl(
'https://www.youtube.com/watch?v=kJQP7kiw5Fk'
);
Get Playlist
const playlist = await client.getSongsByPlaylist(
'https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M'
);
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';
const stream = await client.streamSongByUrl(
'https://www.youtube.com/watch?v=kJQP7kiw5Fk'
);
stream.pipe(createWriteStream('output.m4a'));
const connection = joinVoiceChannel({...});
const player = createAudioPlayer();
player.play(createAudioResource(stream));
Get Lyrics
const lyrics = await client.getLyrics(
'Shape of You',
'Ed Sheeran',
'Divide',
233
);
console.log('Plain lyrics:', lyrics.plainLyrics);
console.log('Synced lyrics:', lyrics.syncedLyrics);
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;
GL?: string;
HL?: string;
};
ytdlp?: {
binDir?: string;
cookiesPath?: string;
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
git clone https://github.com/Riikon-Team/rikn-music-fetcher-wrapper.git
cd rikn-music-fetcher-wrapper
npm install
npm run build
npm run dev
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
π 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
MIT