Added year to Movie.

This commit is contained in:
moonstar-x 2021-06-11 23:12:40 -05:00
parent 707ba88167
commit 9ef5ecab12
2 changed files with 31 additions and 8 deletions

View File

@ -1,6 +1,7 @@
class Movie { class Movie {
constructor(name, mediaURLs) { constructor(name, year, mediaURLs) {
this.name = name; this.name = name;
this.year = year;
this.mediaURLs = mediaURLs; this.mediaURLs = mediaURLs;
this.downloadURLs = []; this.downloadURLs = [];
} }

View File

@ -36,11 +36,8 @@ class KissAsianScraper {
Logger.info(`Visited ${mediaURL}`); Logger.info(`Visited ${mediaURL}`);
const name = await this.page.evaluate(() => { const name = await this.getCurrentMediaName();
const a = document.querySelector('div.barContent a.bigChar'); const type = await this.getCurrentMediaType();
return a.text;
});
const type = await this.getCurrentMediaPageType();
Logger.info(`Getting media links for ${type} ${name}...`); Logger.info(`Getting media links for ${type} ${name}...`);
@ -64,7 +61,9 @@ class KissAsianScraper {
return new Show(name, 1, mediaURLs); return new Show(name, 1, mediaURLs);
} }
return new Movie(name, mediaURLs); const year = await this.getCurrentMediaYear();
return new Movie(name, year, mediaURLs);
} }
async directlyVisitPlayerURL(playerURL) { async directlyVisitPlayerURL(playerURL) {
@ -118,7 +117,30 @@ class KissAsianScraper {
} }
} }
async getCurrentMediaPageType() { async getCurrentMediaName() {
return await this.page.evaluate(() => {
const a = document.querySelector('div.barContent a.bigChar');
return a.text;
});
}
async getCurrentMediaYear() {
return await this.page.evaluate(() => {
const infoSpans = document.querySelectorAll('span.info');
for (let i = 0; i < infoSpans.length; i++) {
const span = infoSpans.item(i);
if (span.textContent === 'Date aired:') {
const date = span.nextSibling.textContent;
const [year] = date.match(/\d{4}/);
return parseInt(year, 10);
}
}
});
}
async getCurrentMediaType() {
const isMovie = await this.page.evaluate(() => { const isMovie = await this.page.evaluate(() => {
const a = document.querySelector('a[href="/Genre/Movie"]'); const a = document.querySelector('a[href="/Genre/Movie"]');
return !!a; return !!a;