@3t.network/orchestra (1.0.0)
Published 2024-09-25 15:55:03 +00:00 by deployments
Installation
@3t.network:registry=npm install @3t.network/orchestra@1.0.0"@3t.network/orchestra": "1.0.0"About this package
orchestra-node
orchestra-node is a TypeScript library that provides a convenient interface for interacting with the 3t.network Orchestra music API. It allows you to search, retrieve, and download tracks and videos from providers like Spotify, YouTube, and your own local uploads.
Features
- Spotify: Search for tracks, get track details, and download tracks.
- YouTube: Search for videos, get video details, and download videos or audio.
- Local: Upload your own tracks, manage them, and download.
Table of Contents
Installation
Install the package via npm:
npm install orchestra
Or via Yarn:
yarn add orchestra
Prerequisites
- Node.js version 12 or higher.
- An API key to authenticate with the Orchestra API.
Usage
Importing the Client
Import the Orchestra class into your project:
import { Orchestra } from 'orchestra';
Instantiating the Client
Create an instance of the Orchestra, providing your API key:
const API_KEY = 'your-api-key-here'; // Replace with your actual API key
const client = new OrchestraClient('https://audio.3t.network/', API_KEY);
- The
baseURLparameter is optional and defaults to'https://audio.3t.network/'if not provided. - The
apiKeyparameter is required for authenticated requests.
Examples
Spotify
Search for Tracks
client.spotify
.searchTrack('Imagine')
.then((response) => {
console.log('Search Results:', response);
})
.catch((error) => {
console.error('Error searching for tracks:', error);
});
Get Track by ID
const trackId = '3H7ihDc1dqLriiWXwsc2po'; // Replace with a valid Spotify track ID
client.spotify
.getTrackById(trackId)
.then((track) => {
console.log('Track Details:', track);
})
.catch((error) => {
console.error('Error retrieving track:', error);
});
Download Track by ID
client.spotify
.downloadTrackById(trackId)
.then((data) => {
// 'data' is a Buffer containing the track audio
// Save it to a file or process it as needed
const fs = require('fs');
fs.writeFileSync('track.mp3', data);
})
.catch((error) => {
console.error('Error downloading track:', error);
});
YouTube
Search for Videos
client.youtube
.searchVideo('Funny cats')
.then((response) => {
console.log('Search Results:', response);
})
.catch((error) => {
console.error('Error searching for videos:', error);
});
Get Video by ID
const videoId = 'dQw4w9WgXcQ'; // Replace with a valid YouTube video ID
client.youtube
.getVideoById(videoId)
.then((video) => {
console.log('Video Details:', video);
})
.catch((error) => {
console.error('Error retrieving video:', error);
});
Download Video or Audio by ID
client.youtube
.downloadVideoById(videoId, 'audio') // Use 'video' or 'audio'
.then((data) => {
// 'data' is a Buffer containing the video or audio data
// Save it to a file or process it as needed
const fs = require('fs');
fs.writeFileSync('audio.mp3', data);
})
.catch((error) => {
console.error('Error downloading video/audio:', error);
});
Local
Upload a Local Track
import * as fs from 'fs';
const fileStream = fs.createReadStream('/path/to/your/audiofile.mp3');
client.local
.uploadTrack({
file: fileStream,
title: 'My Local Track',
artist: 'Unknown Artist',
album: 'Unknown Album',
year: 2021,
})
.then((track) => {
console.log('Uploaded Track:', track);
})
.catch((error) => {
console.error('Error uploading track:', error);
});
Get Uploaded Tracks
client.local
.getTracks()
.then((response) => {
console.log('Local Tracks:', response);
})
.catch((error) => {
console.error('Error retrieving local tracks:', error);
});
Download Local Track by ID
const localTrackId = 'your-local-track-id'; // Replace with your uploaded track ID
client.local
.downloadTrackById(localTrackId)
.then((data) => {
// 'data' is a Buffer containing the track audio
// Save it to a file or process it as needed
const fs = require('fs');
fs.writeFileSync('local-track.mp3', data);
})
.catch((error) => {
console.error('Error downloading local track:', error);
});
API Reference
OrchestraClient
- Constructor:
new OrchestraClient(baseURL?: string, apiKey?: string)- Parameters:
baseURL(optional): The base URL of the Orchestra API.apiKey(optional): Your API key for authentication.
- Properties:
spotify: Instance ofSpotifyClient.youtube: Instance ofYouTubeClient.local: Instance ofLocalClient.
- Parameters:
SpotifyClient
- Methods:
searchTrack(query: string, limit?: number, offset?: number): Promise<MetadataResponse<Track>>getTrackById(id: string): Promise<Track>downloadTrackById(id: string): Promise<Buffer>
YouTubeClient
- Methods:
searchVideo(query: string, limit?: number, offset?: number): Promise<MetadataResponse<Video>>getVideoById(id: string): Promise<Video>downloadVideoById(id: string, format?: 'video' | 'audio'): Promise<Buffer>
LocalClient
- Methods:
getTracks(limit?: number, offset?: number): Promise<MetadataResponse<Track>>getTrackById(id: string): Promise<Track>uploadTrack(data: { file: Buffer | ReadStream; title: string; artist?: string; album?: string; year?: number; }): Promise<Track>downloadTrackById(id: string): Promise<Buffer>
Types
Track
Represents a music track.
interface Track {
id: string;
title: string;
artist: string;
album: string;
duration: number; // Duration in seconds
[key: string]: any; // Additional properties
}
Video
Represents a video.
interface Video {
id: string;
title: string;
description: string;
duration: number; // Duration in seconds
[key: string]: any; // Additional properties
}
MetadataResponse
Generic type representing a paginated response.
interface MetadataResponse<T> {
items: T[];
total: number;
limit: number;
offset: number;
}
Error Handling
All methods return Promises. Use .then() and .catch() or async/await with try...catch blocks to handle responses and errors.
Example with async/await:
async function searchSpotifyTrack(query: string) {
try {
const response = await client.spotify.searchTrack(query);
console.log('Search Results:', response);
} catch (error) {
console.error('Error searching for tracks:', error);
}
}
Dependencies
Dependencies
| ID | Version |
|---|---|
| axios | ^1.7.7 |
| form-data | ^4.0.0 |
Development Dependencies
| ID | Version |
|---|---|
| @types/form-data | ^2.2.1 |
| @types/node | ^22.5.5 |
| typescript | ^5.6.2 |
Details
2024-09-25 15:55:03 +00:00
Assets (1)
Versions (1)
View all
npm
17
3t.network
ISC
latest
5.7 KiB
orchestra-1.0.0.tgz
5.7 KiB
1.0.0
2024-09-25