-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateJSON.js
314 lines (294 loc) · 9.61 KB
/
createJSON.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
const {
getAllocineCriticsRating,
} = require("./content/getAllocineCriticsRating");
const { getAllocineInfo } = require("./content/getAllocineInfo");
const { getAllocinePopularity } = require("./content/getAllocinePopularity");
const { getBetaseriesRating } = require("./content/getBetaseriesRating");
const { getEpisodesDetails } = require("./content/getEpisodesDetails");
const { getImdbPopularity } = require("./content/getImdbPopularity");
const { getImdbRating } = require("./content/getImdbRating");
const { getLastEpisode } = require("./content/getLastEpisode");
const { getLetterboxdRating } = require("./content/getLetterboxdRating");
const { getMetacriticRating } = require("./content/getMetacriticRating");
const { getObjectByImdbId } = require("./content/getMojoBoxOffice");
const { getPlatformsLinks } = require("./content/getPlatformsLinks");
const {
getRottenTomatoesRating,
} = require("./content/getRottenTomatoesRating");
const { getSensCritiqueRating } = require("./content/getSensCritiqueRating");
const { getTheTvdbSlug } = require("./content/getTheTvdbSlug");
const { getTmdbRating } = require("./content/getTmdbRating");
const { getTraktRating } = require("./content/getTraktRating");
const { getTVTimeRating } = require("./content/getTVTimeRating");
/**
* Asynchronously creates a JSON object with various movie details from different sources.
* @param {Object} allocineCriticsDetails - The AlloCiné critics details
* @param {string} allocineURL - The AlloCiné URL
* @param {string} allocineHomepage - The AlloCiné homepage URL
* @param {number} allocineId - The AlloCiné ID
* @param {string} betaseriesHomepage - The BetaSeries homepage URL
* @param {string} betaseriesId - The BetaSeries ID
* @param {string} imdbHomepage - The IMDb homepage URL
* @param {string} imdbId - The IMDb ID
* @param {boolean} isActive - The active status of the item
* @param {string} item_type - The type of the item (e.g., movie, tvshow)
* @param {string} metacriticHomepage - The Metacritic homepage URL
* @param {string} metacriticId - The Metacritic ID
* @param {string} rottenTomatoesHomepage - The Rotten Tomatoes homepage URL
* @param {string} rottenTomatoesId - The Rotten Tomatoes ID
* @param {string} letterboxdHomepage - The Letterboxd homepage URL
* @param {string} letterboxdId - The Letterboxd ID
* @param {string} sensCritiqueHomepage - The SensCritique homepage URL
* @param {number} sensCritiqueId - The SensCritique ID
* @param {string} traktHomepage - The Trakt homepage URL
* @param {string} traktId - The Trakt ID
* @param {number} tmdbId - TMDB ID
* @param {string} tmdbHomepage - TMDB homepage URL
* @param {string} tvtimeHomepage - TV Time homepage URL
* @param {number} tvtimeId - TV Time ID
* @param {string} theTvdbHomepage - TheTVDB homepage URL
* @param {number} theTvdbId - TheTVDB ID
* @returns {Promise<object>} A Promise which resolves to a JSON object containing movie details
*/
const createJSON = async (
allocineCriticsDetails,
allocineURL,
allocineHomepage,
allocineId,
betaseriesHomepage,
betaseriesId,
imdbHomepage,
imdbId,
isActive,
item_type,
metacriticHomepage,
metacriticId,
rottenTomatoesHomepage,
rottenTomatoesId,
letterboxdHomepage,
letterboxdId,
sensCritiqueHomepage,
sensCritiqueId,
traktHomepage,
traktId,
mojoBoxOfficeArray,
tmdbId,
tmdbHomepage,
tvtimeHomepage,
tvtimeId,
theTvdbHomepage,
theTvdbId,
) => {
const allocineFirstInfo = await getAllocineInfo(
allocineHomepage,
betaseriesHomepage,
tmdbId,
false,
);
const allocineCriticInfo = await getAllocineCriticsRating(
allocineCriticsDetails,
);
const allocinePopularity = await getAllocinePopularity(
allocineURL,
item_type,
);
const betaseriesRating = await getBetaseriesRating(
betaseriesHomepage,
betaseriesId,
);
const platformsLinks = await getPlatformsLinks(
betaseriesId,
allocineHomepage,
imdbId,
);
const imdbRating = await getImdbRating(imdbHomepage);
const imdbPopularity = await getImdbPopularity(
imdbHomepage,
allocineURL,
item_type,
);
const episodesDetails = await getEpisodesDetails(
allocineHomepage,
imdbId,
imdbHomepage,
);
const lastEpisode = await getLastEpisode(
allocineHomepage,
imdbHomepage,
imdbId,
tmdbId,
);
const mojoValues = await getObjectByImdbId(
mojoBoxOfficeArray,
imdbId,
item_type,
);
const metacriticRating = await getMetacriticRating(
metacriticHomepage,
metacriticId,
);
const rottenTomatoesRating = await getRottenTomatoesRating(
rottenTomatoesHomepage,
rottenTomatoesId,
);
const letterboxdRating = await getLetterboxdRating(
letterboxdHomepage,
letterboxdId,
);
const sensCritiqueRating = await getSensCritiqueRating(
sensCritiqueHomepage,
sensCritiqueId,
);
const tmdbRating = await getTmdbRating(
allocineHomepage,
tmdbHomepage,
tmdbId,
);
const traktRating = await getTraktRating(
allocineHomepage,
traktHomepage,
traktId,
);
const tvtimeRating = await getTVTimeRating(tvtimeHomepage, tvtimeId);
const theTvdbSlug = await getTheTvdbSlug(allocineHomepage, theTvdbId);
/* Creating an object called allocineObj. */
const allocineObj = {
id: allocineId,
url: allocineHomepage,
users_rating: allocineFirstInfo && allocineFirstInfo.allocineUsersRating,
critics_rating: allocineCriticInfo && allocineCriticInfo.criticsRating,
critics_number: allocineCriticInfo && allocineCriticInfo.criticsNumber,
critics_rating_details:
allocineCriticInfo && allocineCriticInfo.criticsRatingDetails,
popularity: allocinePopularity && allocinePopularity.popularity,
};
/* Creating an object called betaseriesObj. */
const betaseriesObj =
betaseriesId !== "null"
? {
id: betaseriesId,
url: betaseriesHomepage,
users_rating: betaseriesRating,
}
: null;
/* Creating an object called imdbObj. */
const imdbObj = {
id: imdbId,
url: imdbHomepage,
users_rating: imdbRating,
popularity: imdbPopularity && imdbPopularity.popularity,
};
/* Creates a Letterboxd object if the letterboxd rating is not null. */
const letterboxdObj =
letterboxdRating !== null && letterboxdRating.id
? {
id: letterboxdRating.id,
url: letterboxdRating.url,
users_rating: letterboxdRating.usersRating,
}
: null;
/* Creates a Metacritic object if the metacritic rating is not null. */
const metacriticObj =
metacriticRating !== null && metacriticRating.id
? {
id: metacriticRating.id,
url: metacriticRating.url,
users_rating: metacriticRating.usersRating,
critics_rating: metacriticRating.criticsRating,
}
: null;
/* Creates a Rotten Tomatoes object if the rottenTomatoes rating is not null. */
const rottenTomatoesObj =
rottenTomatoesRating !== null && rottenTomatoesRating.id
? {
id: rottenTomatoesRating.id,
url: rottenTomatoesRating.url,
users_rating: rottenTomatoesRating.usersRating,
critics_rating: rottenTomatoesRating.criticsRating,
}
: null;
/* Creates a SensCritique object if the sensCritique rating is not null. */
const sensCritiqueObj =
sensCritiqueRating !== null && sensCritiqueRating.id
? {
id: sensCritiqueRating.id,
url: sensCritiqueRating.url,
users_rating: sensCritiqueRating.usersRating,
}
: null;
/* Creating an object called theTvdbObj. */
const theTvdbObj =
theTvdbSlug !== null
? {
id: theTvdbId,
slug: theTvdbSlug,
url: `${theTvdbHomepage}${theTvdbSlug}`,
}
: null;
/* Creates a TMDB object if the TMDB rating is not null. */
const tmdbObj =
tmdbRating !== null && tmdbRating.id
? {
id: tmdbRating.id,
url: tmdbRating.url,
users_rating: tmdbRating.usersRating,
}
: null;
/* Creates a Trakt object if the trakt rating is not null. */
const traktObj =
traktRating !== null && traktRating.id
? {
id: traktRating.id,
url: traktRating.url,
users_rating: traktRating.usersRating,
}
: null;
/* Creates a TV Time object if the tvtime rating is not null. */
const tvtimeObj =
tvtimeRating !== null && tvtimeRating.id
? {
id: tvtimeRating.id,
url: tvtimeRating.url,
users_rating: tvtimeRating.usersRating,
}
: null;
const mojoObj =
mojoValues !== null
? {
rank: mojoValues.rank,
url: mojoValues.url,
lifetime_gross: mojoValues.lifetimeGross,
}
: null;
const data = {
id: tmdbId,
item_type: item_type,
is_active: isActive,
title: allocineFirstInfo.allocineTitle,
directors: allocineFirstInfo.directors,
genres: allocineFirstInfo.genres,
image: allocineFirstInfo.image,
release_date: allocineFirstInfo && allocineFirstInfo.releaseDate,
tagline: traktRating && traktRating.tagline,
trailer: allocineFirstInfo.trailer,
episodes_details: episodesDetails,
last_episode: lastEpisode,
platforms_links: platformsLinks,
seasons_number: allocineFirstInfo.seasonsNumber,
status: allocineFirstInfo.status,
allocine: allocineObj,
betaseries: betaseriesObj,
imdb: imdbObj,
letterboxd: letterboxdObj,
metacritic: metacriticObj,
rotten_tomatoes: rottenTomatoesObj,
senscritique: sensCritiqueObj,
thetvdb: theTvdbObj,
tmdb: tmdbObj,
trakt: traktObj,
tv_time: tvtimeObj,
mojo: mojoObj,
};
return data;
};
module.exports = createJSON;