Дописал программку
21. Ноябрь, 2021 в 23:00,
Нет комментариев
const https = require('https'); // or 'https' for http:// URLsconst fs = require('fs');
function readURL(url) { // code for reading html page to data
return new Promise((resolve, reject) => {
https.get(url, (res) => {
const { statusCode } = res;
res.setEncoding('utf8');
let rawData = '';
res.on('data', chunk => rawData += chunk);
res.on('end', () => resolve(rawData));
}).on('error', (e) => reject(e)); // ошибка -> отклоняем Промис
})
};
let fileContent = fs.readFileSync('linksHere.txt', 'utf8'); // read the download sheet
ListOfLinks = fileContent.split('\n'); // separate by strokes
let download = ListOfLinks; // doubling the list (for indexating problems)
let html = 'kkfgk'; // why not?
let html = 'kkfgk'; // why not?for (let strokes=0; strokes < (ListOfLinks.length); strokes++) {
if ((ListOfLinks[strokes].includes('xvideos')) && (ListOfLinks[strokes].includes('/video'))) { // necessary site and necessary page of it
console.log('We found robust link :');
} else {
download[strokes]=null; // pointing out trash
console.log('Throwing trash....'); //i promise you...
};
};
function removeNull(array) {
return array.filter(x => x !== null)
};
download = removeNull(download); // ...as i said!
let count = 0;
let downloading = function(url, dest, cb) { //function for downloading files - with state texts
let file = fs.createWriteStream(dest);
https.get(url, function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(cb);
console.log('Got ' + dest + '.');
count++;
console.log('Downloaded '+count+' files out of '+download.length);
if (count == download.length) {
console.log('All tasks are completed. Type ".exit" or press Ctrl+C twice to quit the program');
} else {
eval(textCode[(1+count)]);
};
});
});
};
let textCode = '';
console.log('Creating a list of a download tasks.....');
for (let strokes = 0; strokes < download.length; strokes++) { //creating a list of a downloading functions - names and urls
readURL(download[strokes]).then(data => {
html = data;
let findTitle = ((html.split('title>'))[1]);
let cutTitle = ((findTitle.split('<'))[0]);
console.log(cutTitle+'-file is in a downloading order.');
let videoFile = (html.split("UrlHigh('"))[1];
videoFile = (videoFile.split("');"))[0];
textCode += 'DELETEdownloading("'+videoFile+'", "'+cutTitle+'")'; //yes, no fantasy at all
})
};
setTimeout(() => {
console.log('...starting the downloading process.....');
textCode = textCode.split('DELETE'); // it should be done AFTER creating a list of a downloading functions (↑), so ten seconds is enough
//counting();
eval(textCode[1]);
}, 10 * 1000 );