diff --git a/src/classes/media/Movie.js b/src/classes/media/Movie.js index 4f24b9d..0d95a0a 100644 --- a/src/classes/media/Movie.js +++ b/src/classes/media/Movie.js @@ -1,6 +1,7 @@ class Movie { - constructor(name, mediaURLs) { + constructor(name, year, mediaURLs) { this.name = name; + this.year = year; this.mediaURLs = mediaURLs; this.downloadURLs = []; } diff --git a/src/classes/scraping/KissAsianScraper.js b/src/classes/scraping/KissAsianScraper.js index 629c7aa..7dbae31 100644 --- a/src/classes/scraping/KissAsianScraper.js +++ b/src/classes/scraping/KissAsianScraper.js @@ -36,11 +36,8 @@ class KissAsianScraper { Logger.info(`Visited ${mediaURL}`); - const name = await this.page.evaluate(() => { - const a = document.querySelector('div.barContent a.bigChar'); - return a.text; - }); - const type = await this.getCurrentMediaPageType(); + const name = await this.getCurrentMediaName(); + const type = await this.getCurrentMediaType(); Logger.info(`Getting media links for ${type} ${name}...`); @@ -64,7 +61,9 @@ class KissAsianScraper { 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) { @@ -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 a = document.querySelector('a[href="/Genre/Movie"]'); return !!a;