Package Exports
- @ytb-dw/sdk
- @ytb-dw/sdk/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ytb-dw/sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@ytb-dw/sdk
SDK officiel JavaScript/Node.js pour le service de téléchargement YouTube ytb-dw.
Installation
npm install @ytb-dw/sdk
Usage rapide
Node.js
const YtbDwClient = require('@ytb-dw/sdk');
const client = new YtbDwClient('votre-cle-api');
// Obtenir les informations d'une vidéo
const info = await client.getVideoInfo('https://youtube.com/watch?v=dQw4w9WgXcQ');
console.log(info.title, info.duration);
// Télécharger en MP3
await client.downloadToFile(
'https://youtube.com/watch?v=dQw4w9WgXcQ',
'audio.mp3',
{ format: 'audio' }
);
// Télécharger en vidéo 720p
await client.downloadToFile(
'https://youtube.com/watch?v=dQw4w9WgXcQ',
'video.mp4',
{ format: 'video', quality: '720' }
);
Navigateur
<script src="https://cdn.jsdelivr.net/npm/@ytb-dw/sdk@latest/index.js"></script>
<script>
const client = new YtbDwClient('votre-cle-api');
// Obtenir les informations d'une vidéo
client.getVideoInfo('https://youtube.com/watch?v=dQw4w9WgXcQ')
.then(info => console.log(info));
// Ouvrir le téléchargement dans un nouvel onglet
client.openDownload('https://youtube.com/watch?v=dQw4w9WgXcQ', {
format: 'audio'
});
</script>
API
Constructor
const client = new YtbDwClient(apiKey, baseUrl?)
apiKey
: Votre clé API ytb-dw (obligatoire)baseUrl
: URL de base de l'API (optionnel, par défaut:https://ytb-dw-api.onrender.com
)
Méthodes
getVideoInfo(url)
Récupère les métadonnées d'une vidéo sans la télécharger.
const info = await client.getVideoInfo('https://youtube.com/watch?v=VIDEO_ID');
// Retourne: { success, title, duration, uploader, view_count, formats }
downloadVideo(url, options)
Télécharge une vidéo avec des options personnalisées.
const response = await client.downloadVideo('https://youtube.com/watch?v=VIDEO_ID', {
format: 'video', // 'audio' ou 'video'
quality: '720' // '480', '720', '1080', 'best'
});
downloadAudio(url)
Raccourci pour télécharger l'audio uniquement.
const response = await client.downloadAudio('https://youtube.com/watch?v=VIDEO_ID');
downloadVideoQuality(url, quality)
Raccourci pour télécharger une vidéo dans une qualité spécifique.
const response = await client.downloadVideoQuality('https://youtube.com/watch?v=VIDEO_ID', '1080');
getDownloadUrl(url, options)
Génère l'URL de téléchargement (utile pour les navigateurs).
const downloadUrl = client.getDownloadUrl('https://youtube.com/watch?v=VIDEO_ID', {
format: 'audio'
});
downloadToFile(url, filename, options)
(Node.js seulement)
Télécharge et sauvegarde directement dans un fichier.
await client.downloadToFile(
'https://youtube.com/watch?v=VIDEO_ID',
'./downloads/video.mp4',
{ format: 'video', quality: '720' }
);
openDownload(url, options)
(Navigateur seulement)
Ouvre le téléchargement dans un nouvel onglet.
client.openDownload('https://youtube.com/watch?v=VIDEO_ID', {
format: 'audio'
});
Gestion des erreurs
Le SDK gère automatiquement les erreurs HTTP et fournit des messages d'erreur clairs :
try {
const info = await client.getVideoInfo('invalid-url');
} catch (error) {
console.error('Erreur:', error.message);
// Exemple: "HTTP 400: Bad Request - Missing or invalid parameters"
}
Codes d'erreur
400
: Paramètres manquants ou invalides401
: Clé API invalide ou inactive403
: Format non autorisé pour votre compte404
: Vidéo introuvable ou privée429
: Quota quotidien dépassé500
: Erreur serveur temporaire
Limites
- Gratuit: 10 téléchargements/jour
- Premium: 100 téléchargements/jour
- Unlimited: Illimité
- Timeout: 15 minutes max par téléchargement
- Taille max: 2 Go par fichier
- Concurrent: 3 téléchargements simultanés
Support
- Documentation: https://ytb-dw.social-networking.me/docs
- Issues: https://github.com/ytb-dw/sdk/issues
- Email: support@ytb-dw.com
Licence
MIT