Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from tuhinpal/stage
Browse files Browse the repository at this point in the history
Migrate 2 API routes to new system
  • Loading branch information
tuhinpal authored Nov 23, 2023
2 parents 76df0ac + b9ecec5 commit 99ec6d7
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 372 deletions.
110 changes: 110 additions & 0 deletions src/helpers/getTitle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import apiRequestRawHtml from "./apiRequestRawHtml";
import DomParser from "dom-parser";
import seriesFetcher from "./seriesFetcher";

export default async function getTitle(id) {
const parser = new DomParser();
const html = await apiRequestRawHtml(`https://www.imdb.com/title/${id}`);
const dom = parser.parseFromString(html);
const nextData = dom.getElementsByAttribute("id", "__NEXT_DATA__");
const json = JSON.parse(nextData[0].textContent);

const props = json.props.pageProps;

const getCredits = (lookFor, v) => {
const result = props.aboveTheFoldData.principalCredits.find(
(e) => e?.category?.id === lookFor
);

return result
? result.credits.map((e) => {
if (v === "2")
return {
id: e.name.id,
name: e.name.nameText.text,
};

return e.name.nameText.text;
})
: [];
};

return {
id: id,
review_api_path: `/reviews/${id}`,
imdb: `https://www.imdb.com/title/${id}`,
contentType: props.aboveTheFoldData.titleType.id,
contentRating: props.aboveTheFoldData.certificate.rating,
isSeries: props.aboveTheFoldData.titleType.isSeries,
productionStatus:
props.aboveTheFoldData.productionStatus.currentProductionStage.id,
isReleased:
props.aboveTheFoldData.productionStatus.currentProductionStage.id ===
"released",
title: props.aboveTheFoldData.titleText.text,
image: props.aboveTheFoldData.primaryImage.url,
images: props.mainColumnData.titleMainImages.edges
.filter((e) => e.__typename === "ImageEdge")
.map((e) => e.node.url),
plot: props.aboveTheFoldData.plot.plotText.plainText,
runtime:
props.aboveTheFoldData.runtime?.displayableProperty?.value?.plainText ??
"",
runtimeSeconds: props.aboveTheFoldData.runtime?.seconds ?? 0,
rating: {
count: props.aboveTheFoldData.ratingsSummary.voteCount,
star: props.aboveTheFoldData.ratingsSummary.aggregateRating,
},
award: {
wins: props.mainColumnData.wins.total,
nominations: props.mainColumnData.nominations.total,
},
genre: props.aboveTheFoldData.genres.genres.map((e) => e.id),
releaseDetailed: {
date: new Date(
props.aboveTheFoldData.releaseDate.year,
props.aboveTheFoldData.releaseDate.month - 1,
props.aboveTheFoldData.releaseDate.day
).toISOString(),
day: props.aboveTheFoldData.releaseDate.day,
month: props.aboveTheFoldData.releaseDate.month,
year: props.aboveTheFoldData.releaseDate.year,
releaseLocation: {
country: props.mainColumnData.releaseDate?.country?.text,
cca2: props.mainColumnData.releaseDate?.country?.id,
},
originLocations: props.mainColumnData.countriesOfOrigin.countries.map(
(e) => ({
country: e.text,
cca2: e.id,
})
),
},
year: props.aboveTheFoldData.releaseDate.year,
spokenLanguages: props.mainColumnData.spokenLanguages.spokenLanguages.map(
(e) => ({
language: e.text,
id: e.id,
})
),
filmingLocations: props.mainColumnData.filmingLocations.edges.map(
(e) => e.node.text
),
actors: getCredits("cast"),
actors_v2: getCredits("cast", "2"),
creators: getCredits("creator"),
creators_v2: getCredits("creator", "2"),
directors: getCredits("director"),
directors_v2: getCredits("director", "2"),
writers: getCredits("writer"),
writers_v2: getCredits("writer", "2"),
top_credits: props.aboveTheFoldData.principalCredits.map((e) => ({
id: e.category.id,
name: e.category.text,
credits: e.credits.map((e) => e.name.nameText.text),
})),
...(props.aboveTheFoldData.titleType.isSeries
? await seriesFetcher(id)
: {}),
};
}
98 changes: 0 additions & 98 deletions src/helpers/parseMoreInfo.js

This file was deleted.

Loading

0 comments on commit 99ec6d7

Please sign in to comment.