Scrape now identifies movies and shows.

This commit is contained in:
moonstar-x 2021-06-11 22:44:51 -05:00
parent 7467b699df
commit 707ba88167
4 changed files with 61 additions and 7 deletions

View File

@ -0,0 +1,13 @@
class Movie {
constructor(name, mediaURLs) {
this.name = name;
this.mediaURLs = mediaURLs;
this.downloadURLs = [];
}
setDownloadURLs(downloadURLs) {
this.downloadURLs = downloadURLs;
}
}
module.exports = Movie;

14
src/classes/media/Show.js Normal file
View File

@ -0,0 +1,14 @@
class Show {
constructor(name, season, mediaURLs) {
this.name = name;
this.season = season < 10 ? `0${season}` : `${season}`;
this.mediaURLs = mediaURLs;
this.downloadURLs = [];
}
setDownloadURLs(downloadURLs) {
this.downloadURLs = downloadURLs;
}
}
module.exports = Show;

View File

@ -1,5 +1,7 @@
const Logger = require('../utils/Logger');
const { ScraperError } = require('../../errors');
const Show = require('../media/Show');
const Movie = require('../media/Movie');
class KissAsianScraper {
constructor(page) {
@ -28,14 +30,21 @@ class KissAsianScraper {
Logger.success(`Successfully logged in as ${credentials.username}.`);
}
async getMediaLinks(mediaURL) {
async getMediaData(mediaURL) {
await this.page.goto(mediaURL);
await this.page.waitForSelector(KissAsianScraper.DEFAULTS.SITE_SELECTOR);
Logger.info(`Visited ${mediaURL}`);
Logger.info('Getting media links...');
const links = await this.page.evaluate(() => {
const name = await this.page.evaluate(() => {
const a = document.querySelector('div.barContent a.bigChar');
return a.text;
});
const type = await this.getCurrentMediaPageType();
Logger.info(`Getting media links for ${type} ${name}...`);
const mediaURLs = await this.page.evaluate(() => {
const table = document.querySelector('.episodeList table.listing');
const tableBody = table.firstElementChild;
@ -49,9 +58,13 @@ class KissAsianScraper {
return links;
});
Logger.success(`Scraped ${links.length} media links.`);
Logger.success(`Scraped ${mediaURLs.length} media links.`);
return links;
if (type === KissAsianScraper.MEDIA_TYPES.SHOW) {
return new Show(name, 1, mediaURLs);
}
return new Movie(name, mediaURLs);
}
async directlyVisitPlayerURL(playerURL) {
@ -104,6 +117,15 @@ class KissAsianScraper {
throw new ScraperError(`Server ${server} is unavailable.`);
}
}
async getCurrentMediaPageType() {
const isMovie = await this.page.evaluate(() => {
const a = document.querySelector('a[href="/Genre/Movie"]');
return !!a;
});
return isMovie ? KissAsianScraper.MEDIA_TYPES.MOVIE : KissAsianScraper.MEDIA_TYPES.SHOW;
}
}
KissAsianScraper.BASE_URL = 'https://kissasian.li';
@ -112,4 +134,9 @@ KissAsianScraper.DEFAULTS = {
SITE_SELECTOR: '#head a.logo'
};
KissAsianScraper.MEDIA_TYPES = {
MOVIE: 'movie',
SHOW: 'show'
};
module.exports = KissAsianScraper;

View File

@ -15,8 +15,8 @@ const main = async() => {
await scraper.load();
await scraper.authenticate(credentials.kissasian);
const links = await scraper.getMediaLinks('https://kissasian.li/Drama/My-Roommate-is-a-Gumiho');
await scraper.directlyVisitPlayerURL(links[0]);
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());
};