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d@1.0.5/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/ymp3d@1.0.5/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict'\r\n// @d1zz7\r\nconst ffmpegPath = require('@ffmpeg-installer/ffmpeg');\r\nconst ffmpeg = require('fluent-ffmpeg');\r\nconst { getVideoInfo, progressPercent } = require('./services');\r\nconst getStream = require('./audioStream');\r\nconst EventEmitter = require('events').EventEmitter;\r\nconst sanitize = require('sanitize-filename');\r\nconst HttpsProxyAgent = require('https-proxy-agent');\r\n\r\nffmpeg.setFfmpegPath(ffmpegPath.path) // ffmpeg path\r\n\r\nclass Ymp3 extends EventEmitter {\r\n\r\n    constructor(params = {}) {\r\n        super()\r\n        this.videoParams = params.videoParams ?? {\r\n            videoFormat: 'mp4',\r\n            quality: 'lowest',\r\n            audioFormat: 'mp3',\r\n        }\r\n        this.proxyAgent = params.proxy ? HttpsProxyAgent(params.proxy) : {}\r\n    }\r\n\r\n    async Download(url, outputPath = '') {\r\n        const stream = await getStream(url, this.videoParams, this.proxyAgent)\r\n        const videoInfo = await getVideoInfo(url)\r\n        const fileName = outputPath ? outputPath : sanitize(videoInfo.name + '.mp3')\r\n\r\n        const outputOptions = [\r\n            '-id3v2_version', '4',\r\n            '-metadata', 'title=' + videoInfo.title,\r\n            '-metadata', 'artist=' + videoInfo.artist,\r\n            '-metadata', 'thumbnail=' + videoInfo.thumbnail,\r\n        ];\r\n\r\n        try {\r\n            ffmpeg({\r\n                source: stream\r\n            })\r\n                .audioBitrate(192)\r\n                .withAudioCodec('libmp3lame')\r\n                .toFormat('mp3')\r\n                .outputOption(...outputOptions)\r\n                .on('start', function (commandLine) {\r\n                    this.emit('start', commandLine)\r\n                }.bind(this))\r\n                .on('progress', function (progress) {\r\n                    this.emit('progress', {\r\n                        videoId: videoInfo.id,\r\n                        percent: progressPercent(progress.timemark, videoInfo.seconds)\r\n                    })\r\n                }.bind(this))\r\n                .on('error', function (err) {\r\n                    console.log(err)\r\n                    this.emit('error', err)\r\n                }.bind(this))\r\n                .on('end', function () {\r\n                    this.emit('finish', fileName)\r\n                }.bind(this))\r\n                .saveToFile(fileName)\r\n        } catch (e) {\r\n            return e\r\n        }\r\n\r\n        return videoInfo\r\n    }\r\n}\r\n\r\nmodule.exports = Ymp3;"]}