koja-api
Version:
A complete Node.js wrapper for Koja API services including Ephoto generation, YouTube MP4 and MP3 downloads
83 lines (70 loc) • 2.04 kB
JavaScript
const axios = require('axios');
class KojaAPI {
constructor() {
this.baseUrl = 'https://koja-api.web-server.xyz';
}
/**
* Generate an ephoto image
* @param {string} url - The ephoto360 effect URL
* @param {string} text - The text to apply the effect to
* @returns {Promise<Object>} - The API response
*/
async ephoto(url, text) {
try {
if (!url || !text) {
throw new Error('Both url and text parameters are required');
}
const response = await axios.get(`${this.baseUrl}/ephoto`, {
params: {
url,
text
}
});
return response.data;
} catch (error) {
console.error('Error generating ephoto:', error.message);
throw error;
}
}
/**
* Download YouTube video as MP4
* @param {string} url - YouTube video URL
* @param {string} [quality] - Preferred quality (optional)
* @returns {Promise<Object>} - The API response
*/
async ytmp4(url, quality) {
try {
if (!url) {
throw new Error('YouTube URL is required');
}
const params = { url };
if (quality) params.quality = quality;
const response = await axios.get(`${this.baseUrl}/ytmp4`, { params });
return response.data;
} catch (error) {
console.error('Error downloading YouTube MP4:', error.message);
throw error;
}
}
/**
* Download YouTube video as MP3
* @param {string} url - YouTube video URL
* @param {string} [quality] - Preferred quality (optional)
* @returns {Promise<Object>} - The API response
*/
async ytmp3(url, quality) {
try {
if (!url) {
throw new Error('YouTube URL is required');
}
const params = { url };
if (quality) params.quality = quality;
const response = await axios.get(`${this.baseUrl}/ytmp3`, { params });
return response.data;
} catch (error) {
console.error('Error downloading YouTube MP3:', error.message);
throw error;
}
}
}
module.exports = new KojaAPI();