Created downloadURLs population method in scraper.
This commit is contained in:
parent
48132155f8
commit
ab65c9f15a
@ -1,9 +1,7 @@
|
||||
const { JdownloaderClient: Client, JdownloaderClient } = require('jdownloader-client-yaac');
|
||||
const Logger = require('../utils/Logger');
|
||||
const Utils = require('../utils/Utils');
|
||||
const { FatalError, JDownloaderError } = require('../../errors');
|
||||
const Show = require('../media/Show');
|
||||
const Movie = require('../media/Movie');
|
||||
const { JDownloaderError } = require('../../errors');
|
||||
const Media = require('../media/Media');
|
||||
|
||||
class JDownloaderClient {
|
||||
@ -20,7 +18,7 @@ class JDownloaderClient {
|
||||
|
||||
async addLinks(media) {
|
||||
if (!(media instanceof Media)) {
|
||||
throw new FatalError('Invalid Media instance passed to downloader!');
|
||||
throw new TypeError('Invalid Media instance passed to downloader!');
|
||||
}
|
||||
|
||||
await this.client.linkgrabberV2.addLinks(this.device.id, {
|
||||
@ -58,7 +56,7 @@ class JDownloaderClient {
|
||||
|
||||
getRenamedCrawledLinks(crawledLinks, media) {
|
||||
if (!(media instanceof Media)) {
|
||||
throw new FatalError('Invalid Media instance passed to downloader!');
|
||||
throw new TypeError('Invalid Media instance passed to downloader!');
|
||||
}
|
||||
|
||||
return crawledLinks.map((link) => {
|
||||
|
@ -1,7 +1,9 @@
|
||||
const Logger = require('../utils/Logger');
|
||||
const Utils = require('../utils/Utils');
|
||||
const { ScraperError } = require('../../errors');
|
||||
const Show = require('../media/Show');
|
||||
const Movie = require('../media/Movie');
|
||||
const Media = require('../media/Media');
|
||||
|
||||
class KissAsianScraper {
|
||||
constructor(page) {
|
||||
@ -71,6 +73,19 @@ class KissAsianScraper {
|
||||
return new Movie(name, year, mediaURLs);
|
||||
}
|
||||
|
||||
async populateMediaDownloadURLs(media) {
|
||||
if (!(media instanceof Media)) {
|
||||
throw new TypeError('Invalid Media instance passed to scraper!');
|
||||
}
|
||||
|
||||
const downloadURLs = await Utils.mapSeries(media.mediaURLs, async(mediaURL) => {
|
||||
await this.directlyVisitPlayerURL(mediaURL);
|
||||
return this.getDownloadLinkForCurrentPlayer();
|
||||
});
|
||||
|
||||
media.setDownloadURLs(downloadURLs);
|
||||
}
|
||||
|
||||
async directlyVisitPlayerURL(playerURL) {
|
||||
await this.page.goto(`${playerURL}&s=mp`);
|
||||
await this.page.waitForSelector(KissAsianScraper.DEFAULTS.SITE_SELECTOR);
|
||||
|
@ -1,9 +1,11 @@
|
||||
class Utils {
|
||||
static async mapSeries(iterable, action) {
|
||||
const resolved = [];
|
||||
|
||||
for (const x of iterable) {
|
||||
await action(x);
|
||||
resolved.push(await action(x));
|
||||
}
|
||||
return Promise.resolve();
|
||||
return Promise.resolve(resolved);
|
||||
}
|
||||
|
||||
static wait(duration) {
|
||||
|
13
src/index.js
13
src/index.js
@ -3,6 +3,7 @@ const StealthPlugin = require('puppeteer-extra-plugin-stealth');
|
||||
const AdBlockerPlugin = require('puppeteer-extra-plugin-adblocker');
|
||||
const ArgsParser = require('./classes/utils/ArgsParser');
|
||||
const KissAsianScraper = require('./classes/scraping/KissAsianScraper');
|
||||
const JDownloaderClient = require('./classes/download/JDownloaderClient');
|
||||
const credentials = require('../data/credentials.json');
|
||||
|
||||
const args = new ArgsParser().parse(process.argv.slice(2));
|
||||
@ -13,15 +14,17 @@ puppeteer.use(AdBlockerPlugin({ blockTrackers: true }));
|
||||
const main = async() => {
|
||||
const browser = await puppeteer.launch({ headless: !args.display, slowMo: 250 });
|
||||
const page = await browser.newPage();
|
||||
const scraper = new KissAsianScraper(page);
|
||||
|
||||
const scraper = new KissAsianScraper(page);
|
||||
const downloader = new JDownloaderClient(credentials.jdownloader);
|
||||
|
||||
await downloader.load();
|
||||
await scraper.load();
|
||||
await scraper.authenticate(credentials.kissasian);
|
||||
|
||||
const data = await scraper.getMediaData('https://kissasian.li/Drama/My-Roommate-is-a-Gumiho');
|
||||
await scraper.directlyVisitPlayerURL(data.mediaURLs[0]);
|
||||
|
||||
console.log(await scraper.getDownloadLinkForCurrentPlayer());
|
||||
const media = await scraper.getMediaData('https://kissasian.li/Drama/My-Roommate-is-a-Gumiho');
|
||||
|
||||
await scraper.populateMediaDownloadURLs(media);
|
||||
};
|
||||
|
||||
main();
|
||||
|
Loading…
Reference in New Issue
Block a user