You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

js-imdb-scraper

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-imdb-scraper - npm Package Compare versions

Comparing version

to
0.0.6

45

imdbScraper.js

@@ -1,7 +0,7 @@

const fetch = require("node-fetch");
const cheerio = require("cheerio");
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const HEADER = {
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",
'user-agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36',
};

@@ -11,3 +11,3 @@

const convertToQueryString = (showName) => {
return showName.replace(" ", "+");
return showName.replace(' ', '+');
};

@@ -34,19 +34,19 @@

const $ = cheerio.load(resultBody);
return $("table.findList > tbody > tr")
return $('table.findList > tbody > tr')
.map((i, e) => {
const url = $(e).children("td").find("a").attr("href");
const url = $(e).children('td').find('a').attr('href');
const title = $(e).text().trim();
if (
// Only return titles
url.includes("/title/") &&
url.includes('/title/') &&
// Only return tv shows
title.includes(" (TV Series)") &&
title.includes(' (TV Series)') &&
// Don't show individual episodes
!title.includes("(TV Episode)")
!title.includes('(TV Episode)')
) {
return {
title: $(e).text().trim().replace(" (TV Series)", ""),
id: $(e).children("td").find("a").attr("href").substr(7, 9),
title: $(e).text().trim().replace(' (TV Series)', ''),
id: $(e).children('td').find('a').attr('href').substr(7, 9),
img: getHighQualityImage(
$(e).children("td.primary_photo").find("img").attr("src")
$(e).children('td.primary_photo').find('img').attr('src')
),

@@ -62,3 +62,3 @@ };

const getHighQualityImage = (imgUrl) => {
return imgUrl.split("@.")[0] + "@._V1_UY268_CR8,0,182,268_AL_.jpg";
return imgUrl.split('@.')[0] + '@._V1_UY268_CR8,0,182,268_AL_.jpg';
};

@@ -75,3 +75,3 @@

// The page defaults to showing latest season, so we can use this to determine total number of seasons.
const seasons = parseInt($("#bySeason option:selected").text().trim());
const seasons = parseInt($('#bySeason option:selected').text().trim());

@@ -98,3 +98,3 @@ // Iterate through all seasons and populate ratings object

let seasonRatings = $(
"div.eplist > div > div.info > div.ipl-rating-widget > div.ipl-rating-star"
'div.eplist > div > div.info > div.ipl-rating-widget > div.ipl-rating-star'
)

@@ -104,3 +104,3 @@ .map(function (e, i) {

episode: e + 1,
rating: $(this).children("span.ipl-rating-star__rating").text(),
rating: $(this).children('span.ipl-rating-star__rating').text(),
};

@@ -138,2 +138,11 @@ })

module.exports = { getSearchResults, getAllRatings, getSeasonRatings };
// Gets the number of seasons of a show
// Returns integer
const getNumSeasons = async (imdbId) => {
const page = await fetch(`http://imdb.com/title/${imdbId}`);
const pageBody = await page.text();
const $ = cheerio.load(pageBody);
return $('div.seasons-and-year-nav > div').find('a').first().text();
};
module.exports = { getSearchResults, getAllRatings, getSeasonRatings, getNumSeasons };

2

package.json
{
"name": "js-imdb-scraper",
"version": "0.0.5",
"version": "0.0.6",
"description": "",

@@ -5,0 +5,0 @@ "main": "imdbScraper.js",

@@ -11,2 +11,3 @@ # js-imdb-scraper

- [Get all seasons ratings](#get-all-seasons-ratings)
- [Get number of seasons](#get-number-of-seasons)
- [License](#license)

@@ -29,3 +30,3 @@

const { getSearchResults, getSeasonRatings, getAllRatings } = require("js-imdb-scraper");
const { getSearchResults, getSeasonRatings, getAllRatings, getNumSeasons } = require("js-imdb-scraper");
```

@@ -155,4 +156,25 @@

### Get number of seasons
With the IMDB ID we can find the number of show seasons by using `getNumSeasons(showId)`:
```js
const imdb = require("js-imdb-scraper");
const example = async () => {
const searchResults = await imdb.getSearchResults("westworld");
const selectedShowId = searchResults[0].id;
const numSeasons = await imdb.getNumSeasons(selectedShowId);
return numSeasons;
}
```
This gives us:
```bash
1
```
## License
This project is licensed under the MIT license - see the [LICENSE](./LICENSE) file for details.