yt-dlp-typescript-wrapper
Version:
TypeScript OOP wrapper for youtube-dl-exec with advanced YouTube Shorts support
177 lines • 5.21 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.YtDlpConfigManager = void 0;
/**
* Класс для управления конфигурацией yt-dlp
*/
class YtDlpConfigManager {
constructor() {
this.config = {
binPath: process.env['YT_DL_BIN_PATH'] || '/usr/local/bin/yt-dlp',
downloadPath: './downloads',
defaultOptions: {
noCheckCertificates: true,
noWarnings: true,
preferFreeFormats: true,
addHeader: ['referer:youtube.com', 'user-agent:googlebot'],
geoBypass: true
},
videoQualities: {
best: 'best',
worst: 'worst',
'720p': 'best[height<=720]',
'1080p': 'best[height<=1080]',
'480p': 'best[height<=480]',
'360p': 'best[height<=360]'
},
audioFormats: ['mp3', 'm4a', 'wav', 'ogg'],
audioQualities: {
best: '0',
high: '1',
medium: '5',
low: '9'
},
subtitleLanguages: [
'en',
'ru',
'es',
'fr',
'de',
'it',
'pt',
'ja',
'ko',
'zh'
],
maxFileSize: '100M',
playlistOptions: {
playlistStart: 1,
playlistEnd: 0,
playlistReverse: false,
playlistRandom: false
}
};
}
/**
* Получить полную конфигурацию
*/
getConfig() {
return this.config;
}
/**
* Получить путь к yt-dlp
*/
getBinPath() {
return this.config.binPath;
}
/**
* Установить путь к yt-dlp
*/
setBinPath(path) {
this.config.binPath = path;
}
/**
* Получить путь для загрузок
*/
getDownloadPath(subPath) {
const fullPath = subPath
? `${this.config.downloadPath}/${subPath}`
: this.config.downloadPath;
return fullPath;
}
/**
* Установить путь для загрузок
*/
setDownloadPath(path) {
this.config.downloadPath = path;
}
/**
* Получить опции по умолчанию
*/
getDefaultOptions() {
return this.config.defaultOptions;
}
/**
* Получить полные опции с пользовательскими настройками
*/
getFullOptions(customOptions = {}) {
return {
...this.config.defaultOptions,
...customOptions
};
}
/**
* Получить опции качества видео
*/
getVideoQualityOptions(quality = 'best') {
return (this.config.videoQualities[quality] || this.config.videoQualities.best);
}
/**
* Получить опции аудио
*/
getAudioOptions(format = 'mp3', quality = 'best') {
return {
extractAudio: true,
audioFormat: format,
audioQuality: this.config.audioQualities[quality] || this.config.audioQualities.best
};
}
/**
* Обновить конфигурацию
*/
updateConfig(newConfig) {
this.config = { ...this.config, ...newConfig };
}
/**
* Сбросить конфигурацию к значениям по умолчанию
*/
resetConfig() {
this.config = {
binPath: process.env['YT_DL_BIN_PATH'] || '/usr/local/bin/yt-dlp',
downloadPath: './downloads',
defaultOptions: {
noCheckCertificates: true,
noWarnings: true,
preferFreeFormats: true,
addHeader: ['referer:youtube.com', 'user-agent:googlebot'],
geoBypass: true
},
videoQualities: {
best: 'best',
worst: 'worst',
'720p': 'best[height<=720]',
'1080p': 'best[height<=1080]',
'480p': 'best[height<=480]',
'360p': 'best[height<=360]'
},
audioFormats: ['mp3', 'm4a', 'wav', 'ogg'],
audioQualities: {
best: '0',
high: '1',
medium: '5',
low: '9'
},
subtitleLanguages: [
'en',
'ru',
'es',
'fr',
'de',
'it',
'pt',
'ja',
'ko',
'zh'
],
maxFileSize: '100M',
playlistOptions: {
playlistStart: 1,
playlistEnd: 0,
playlistReverse: false,
playlistRandom: false
}
};
}
}
exports.YtDlpConfigManager = YtDlpConfigManager;
//# sourceMappingURL=YtDlpConfig.js.map
;