diff --git a/index.js b/index.js index b33ede6..38ac033 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,12 @@ const Cheerio = require('cheerio'); -const { promises: fs } = require('fs'); +const { promises: fs, createWriteStream } = require('fs'); const debug = require('debug')('vk-music-dl'); const vm = require('vm'); const Request = require('request-promise'); const Promise = require('bluebird'); const _ = require('lodash'); const leven = require('leven'); +const fetch = require('node-fetch'); require('dotenv').config(); @@ -64,6 +65,10 @@ async function main(i = 0){ return item; }).sortBy('score').last().value(); debug(bestMatch); + await fetch(bestMatch.url).then(res => { + res.body.pipe(createWriteStream(`./${bestMatch.title} - ${bestMatch.artist}.mp3`)); + }); + debug('Done'); }); // best match for Love Is a Bitch id:456240390 //const results = await searchOnVkMusic('Two Feet Love Is a Bitch'); diff --git a/package-lock.json b/package-lock.json index edbab8a..8a3316e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -338,6 +338,11 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "node-fetch": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + }, "nth-check": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz", diff --git a/package.json b/package.json index df97577..f975840 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "debug": "^4.1.1", "dotenv": "^8.2.0", "leven": "^3.1.0", + "node-fetch": "^2.6.0", "request": "^2.88.2", "request-promise": "^4.2.5" },