react-native-consumet 0.7.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/Consumet.podspec +26 -26
  2. package/LICENSE +673 -673
  3. package/README.md +49 -49
  4. package/android/build.gradle +106 -106
  5. package/android/gradle.properties +5 -5
  6. package/android/src/main/AndroidManifest.xml +4 -4
  7. package/android/src/main/AndroidManifestNew.xml +3 -3
  8. package/android/src/main/java/com/consumet/ConsumetModule.kt +49 -49
  9. package/android/src/main/java/com/consumet/ConsumetPackage.kt +33 -33
  10. package/ios/Consumet.h +6 -6
  11. package/ios/Consumet.mm +18 -18
  12. package/lib/commonjs/extractors/luffy.js +2 -1
  13. package/lib/commonjs/extractors/luffy.js.map +1 -1
  14. package/lib/commonjs/extractors/megacloud/index.js +12 -27
  15. package/lib/commonjs/extractors/megacloud/index.js.map +1 -1
  16. package/lib/commonjs/extractors/megacloud/megacloud.getsrcs.js +99 -0
  17. package/lib/commonjs/extractors/megacloud/megacloud.getsrcs.js.map +1 -0
  18. package/lib/commonjs/extractors/vidcloud.js +39 -48
  19. package/lib/commonjs/extractors/vidcloud.js.map +1 -1
  20. package/lib/commonjs/extractors/voe.js.map +1 -1
  21. package/lib/commonjs/models/types.js +1 -0
  22. package/lib/commonjs/models/types.js.map +1 -1
  23. package/lib/commonjs/providers/anime/animeowl.js +55 -53
  24. package/lib/commonjs/providers/anime/animeowl.js.map +1 -1
  25. package/lib/commonjs/providers/meta/anilist.js +22 -7
  26. package/lib/commonjs/providers/meta/anilist.js.map +1 -1
  27. package/lib/commonjs/providers/meta/tmdb.js +1 -1
  28. package/lib/commonjs/providers/meta/tmdb.js.map +1 -1
  29. package/lib/commonjs/providers/movies/himovies.js +16 -16
  30. package/lib/commonjs/providers/movies/index.js +3 -1
  31. package/lib/commonjs/providers/movies/index.js.map +1 -1
  32. package/lib/commonjs/providers/movies/multimovies.js +2 -2
  33. package/lib/commonjs/providers/movies/multimovies.js.map +1 -1
  34. package/lib/commonjs/providers/movies/multistream/index.js +208 -0
  35. package/lib/commonjs/providers/movies/multistream/index.js.map +1 -0
  36. package/lib/commonjs/providers/movies/multistream/utils.js +267 -0
  37. package/lib/commonjs/providers/movies/multistream/utils.js.map +1 -0
  38. package/lib/commonjs/providers/movies/netflixmirror.js +2 -2
  39. package/lib/commonjs/providers/movies/netflixmirror.js.map +1 -1
  40. package/lib/commonjs/utils/utils.js +58 -34
  41. package/lib/commonjs/utils/utils.js.map +1 -1
  42. package/lib/module/extractors/luffy.js +2 -1
  43. package/lib/module/extractors/luffy.js.map +1 -1
  44. package/lib/module/extractors/megacloud/index.js +12 -26
  45. package/lib/module/extractors/megacloud/index.js.map +1 -1
  46. package/lib/module/extractors/megacloud/megacloud.getsrcs.js +95 -0
  47. package/lib/module/extractors/megacloud/megacloud.getsrcs.js.map +1 -0
  48. package/lib/module/extractors/vidcloud.js +38 -47
  49. package/lib/module/extractors/vidcloud.js.map +1 -1
  50. package/lib/module/extractors/voe.js.map +1 -1
  51. package/lib/module/models/types.js +1 -0
  52. package/lib/module/models/types.js.map +1 -1
  53. package/lib/module/providers/anime/animeowl.js +56 -53
  54. package/lib/module/providers/anime/animeowl.js.map +1 -1
  55. package/lib/module/providers/meta/anilist.js +22 -7
  56. package/lib/module/providers/meta/anilist.js.map +1 -1
  57. package/lib/module/providers/meta/tmdb.js +1 -1
  58. package/lib/module/providers/meta/tmdb.js.map +1 -1
  59. package/lib/module/providers/movies/himovies.js +16 -16
  60. package/lib/module/providers/movies/index.js +3 -1
  61. package/lib/module/providers/movies/index.js.map +1 -1
  62. package/lib/module/providers/movies/multimovies.js +2 -2
  63. package/lib/module/providers/movies/multimovies.js.map +1 -1
  64. package/lib/module/providers/movies/multistream/index.js +205 -0
  65. package/lib/module/providers/movies/multistream/index.js.map +1 -0
  66. package/lib/module/providers/movies/multistream/utils.js +259 -0
  67. package/lib/module/providers/movies/multistream/utils.js.map +1 -0
  68. package/lib/module/providers/movies/netflixmirror.js +2 -2
  69. package/lib/module/providers/movies/netflixmirror.js.map +1 -1
  70. package/lib/module/utils/utils.js +55 -30
  71. package/lib/module/utils/utils.js.map +1 -1
  72. package/lib/typescript/commonjs/src/extractors/luffy.d.ts.map +1 -1
  73. package/lib/typescript/commonjs/src/extractors/megacloud/index.d.ts.map +1 -1
  74. package/lib/typescript/commonjs/src/extractors/megacloud/megacloud.getsrcs.d.ts +10 -0
  75. package/lib/typescript/commonjs/src/extractors/megacloud/megacloud.getsrcs.d.ts.map +1 -0
  76. package/lib/typescript/commonjs/src/extractors/vidcloud.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/src/index.d.ts +1 -1
  78. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/src/models/types.d.ts +2 -1
  80. package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/src/providers/anime/animeowl.d.ts.map +1 -1
  82. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
  83. package/lib/typescript/commonjs/src/providers/meta/tmdb.d.ts.map +1 -1
  84. package/lib/typescript/commonjs/src/providers/movies/index.d.ts +2 -0
  85. package/lib/typescript/commonjs/src/providers/movies/index.d.ts.map +1 -1
  86. package/lib/typescript/commonjs/src/providers/movies/multimovies.d.ts.map +1 -1
  87. package/lib/typescript/commonjs/src/providers/movies/multistream/index.d.ts +37 -0
  88. package/lib/typescript/commonjs/src/providers/movies/multistream/index.d.ts.map +1 -0
  89. package/lib/typescript/commonjs/src/providers/movies/multistream/utils.d.ts +10 -0
  90. package/lib/typescript/commonjs/src/providers/movies/multistream/utils.d.ts.map +1 -0
  91. package/lib/typescript/commonjs/src/providers/movies/netflixmirror.d.ts.map +1 -1
  92. package/lib/typescript/commonjs/src/utils/index.d.ts +1 -1
  93. package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
  94. package/lib/typescript/commonjs/src/utils/utils.d.ts +8 -8
  95. package/lib/typescript/commonjs/src/utils/utils.d.ts.map +1 -1
  96. package/lib/typescript/module/src/extractors/luffy.d.ts.map +1 -1
  97. package/lib/typescript/module/src/extractors/megacloud/index.d.ts.map +1 -1
  98. package/lib/typescript/module/src/extractors/megacloud/megacloud.getsrcs.d.ts +10 -0
  99. package/lib/typescript/module/src/extractors/megacloud/megacloud.getsrcs.d.ts.map +1 -0
  100. package/lib/typescript/module/src/extractors/vidcloud.d.ts.map +1 -1
  101. package/lib/typescript/module/src/index.d.ts +1 -1
  102. package/lib/typescript/module/src/index.d.ts.map +1 -1
  103. package/lib/typescript/module/src/models/types.d.ts +2 -1
  104. package/lib/typescript/module/src/models/types.d.ts.map +1 -1
  105. package/lib/typescript/module/src/providers/anime/animeowl.d.ts.map +1 -1
  106. package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
  107. package/lib/typescript/module/src/providers/meta/tmdb.d.ts.map +1 -1
  108. package/lib/typescript/module/src/providers/movies/index.d.ts +2 -0
  109. package/lib/typescript/module/src/providers/movies/index.d.ts.map +1 -1
  110. package/lib/typescript/module/src/providers/movies/multimovies.d.ts.map +1 -1
  111. package/lib/typescript/module/src/providers/movies/multistream/index.d.ts +37 -0
  112. package/lib/typescript/module/src/providers/movies/multistream/index.d.ts.map +1 -0
  113. package/lib/typescript/module/src/providers/movies/multistream/utils.d.ts +10 -0
  114. package/lib/typescript/module/src/providers/movies/multistream/utils.d.ts.map +1 -0
  115. package/lib/typescript/module/src/providers/movies/netflixmirror.d.ts.map +1 -1
  116. package/lib/typescript/module/src/utils/index.d.ts +1 -1
  117. package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
  118. package/lib/typescript/module/src/utils/utils.d.ts +8 -8
  119. package/lib/typescript/module/src/utils/utils.d.ts.map +1 -1
  120. package/package.json +3 -2
  121. package/react-native.config.js +12 -12
  122. package/src/extractors/luffy.ts +33 -32
  123. package/src/extractors/megacloud/index.ts +14 -27
  124. package/src/extractors/megacloud/megacloud.getsrcs.ts +104 -0
  125. package/src/extractors/vidcloud.ts +39 -49
  126. package/src/extractors/voe.ts +3 -3
  127. package/src/index.tsx +137 -137
  128. package/src/models/types.ts +1 -0
  129. package/src/providers/anime/animeowl.ts +565 -564
  130. package/src/providers/meta/anilist.ts +20 -7
  131. package/src/providers/meta/tmdb.ts +1 -2
  132. package/src/providers/movies/himovies.ts +495 -495
  133. package/src/providers/movies/index.ts +2 -0
  134. package/src/providers/movies/multimovies.ts +3 -3
  135. package/src/providers/movies/multistream/index.ts +232 -0
  136. package/src/providers/movies/multistream/utils.ts +393 -0
  137. package/src/providers/movies/netflixmirror.ts +2 -2
  138. package/src/utils/index.ts +2 -2
  139. package/src/utils/utils.ts +66 -31
@@ -1,495 +1,495 @@
1
- import { load } from 'cheerio';
2
-
3
- import {
4
- MovieParser,
5
- TvType,
6
- type IMovieInfo,
7
- type IEpisodeServer,
8
- StreamingServers,
9
- type ISource,
10
- type IMovieResult,
11
- type ISearch,
12
- } from '../../models';
13
- import { MegaCloud, VidCloud } from '../../extractors';
14
-
15
- class HiMovies extends MovieParser {
16
- override readonly name = 'HiMovies';
17
- protected override baseUrl = 'https://himovies.sx';
18
- protected override logo = 'https://himovies.sx/images/group_1/theme_1/favicon.png';
19
- protected override classPath = 'MOVIES.HiMovies';
20
- override supportedTypes = new Set([TvType.MOVIE, TvType.TVSERIES]);
21
- constructor(customBaseURL?: string) {
22
- super(...arguments);
23
- if (customBaseURL) {
24
- if (customBaseURL.startsWith('http://') || customBaseURL.startsWith('https://')) {
25
- this.baseUrl = customBaseURL;
26
- } else {
27
- this.baseUrl = `http://${customBaseURL}`;
28
- }
29
- } else {
30
- this.baseUrl = this.baseUrl;
31
- }
32
- }
33
-
34
- /**
35
- *
36
- * @param query search query string
37
- * @param page page number (default 1) (optional)
38
- */
39
- override search = async (query: string, page: number = 1): Promise<ISearch<IMovieResult>> => {
40
- const searchResult: ISearch<IMovieResult> = {
41
- currentPage: page,
42
- hasNextPage: false,
43
- results: [],
44
- };
45
- try {
46
- const { data } = await this.client.get(`${this.baseUrl}/search/${query.replace(/[\W_]+/g, '-')}?page=${page}`);
47
-
48
- const $ = load(data);
49
-
50
- const navSelector = 'div.pre-pagination > nav:nth-child(1) > ul:nth-child(1)';
51
- searchResult.hasNextPage =
52
- $(navSelector).length > 0 ? !$(navSelector).children().last().hasClass('active') : false;
53
-
54
- $('.film_list-wrap > div.flw-item').each((i, el) => {
55
- const releaseDate = $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text();
56
- searchResult.results.push({
57
- id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
58
- title: $(el).find('div.film-detail > h2 > a').attr('title')!,
59
- url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
60
- image: $(el).find('div.film-poster > img').attr('data-src'),
61
- releaseDate: isNaN(parseInt(releaseDate)) ? undefined : releaseDate,
62
- seasons: releaseDate.includes('SS') ? parseInt(releaseDate.split('SS')[1]!) : undefined,
63
- type:
64
- $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
65
- ? TvType.MOVIE
66
- : TvType.TVSERIES,
67
- });
68
- });
69
-
70
- return searchResult;
71
- } catch (err) {
72
- throw new Error((err as Error).message);
73
- }
74
- };
75
-
76
- /**
77
- *
78
- * @param mediaId media link or id
79
- */
80
- override fetchMediaInfo = async (mediaId: string): Promise<IMovieInfo> => {
81
- if (!mediaId.startsWith(this.baseUrl)) {
82
- mediaId = `${this.baseUrl}/${mediaId}`;
83
- }
84
-
85
- const movieInfo: IMovieInfo = {
86
- id: mediaId.split('sx/').pop()!,
87
- title: '',
88
- url: mediaId,
89
- };
90
- try {
91
- const { data } = await this.client.get(mediaId);
92
- const $ = load(data);
93
- const recommendationsArray: IMovieResult[] = [];
94
-
95
- $('section.block_area > div.block_area-content > div.film_list-wrap > div.flw-item').each((i, el) => {
96
- recommendationsArray.push({
97
- id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
98
- title: $(el).find('div.film-detail > h3.film-name > a').text(),
99
- image: $(el).find('div.film-poster > img').attr('data-src'),
100
- duration: $(el).find('div.film-detail > div.fd-infor > span.fdi-duration').text().replace('m', '') ?? null,
101
- type:
102
- $(el).find('div.film-detail > div.fd-infor > span.fdi-type').text() === 'TV'
103
- ? TvType.TVSERIES
104
- : (TvType.MOVIE ?? null),
105
- });
106
- });
107
-
108
- const uid = $('.detail_page-watch').attr('data-id')!;
109
- movieInfo.cover = $('div.cover_follow').attr('style')?.slice(22).replace(')', '').replace(';', '');
110
- movieInfo.title = $('.heading-name > a:nth-child(1)').text();
111
- movieInfo.image = $('.film-poster > img:nth-child(1)').attr('src');
112
- movieInfo.description = $('.description').text().trim();
113
- movieInfo.type = movieInfo.id.includes('tv/') ? TvType.TVSERIES : TvType.MOVIE;
114
- movieInfo.releaseDate = $('div.row-line:contains(Released:)').text().replace('Released:', '').trim();
115
- movieInfo.genres = $('div.row-line:contains(Genre:) a')
116
- .map((i, el) => $(el).text().split('&'))
117
- .get()
118
- .map((v) => v.trim());
119
- movieInfo.casts = $('.row-line:contains(Casts:) a')
120
- .map((i, el) => $(el).text())
121
- .get();
122
- movieInfo.production = $('.row-line:contains(Production:) a').text().trim();
123
- movieInfo.country = $('.row-line:contains(Country:) a').text().trim();
124
- movieInfo.duration = $('.row-line:contains(Duration:)')
125
- .text()
126
- .replace('Duration:', '')
127
- .replace(/\s+/g, ' ')
128
- .trim();
129
- movieInfo.rating = parseFloat($('.dp-i-stats > span.item:nth-child(3)').text().replace('IMDB:', '').trim());
130
- movieInfo.recommendations = recommendationsArray as any;
131
- const ajaxReqUrl = (id: string, type: string, isSeasons: boolean = false) =>
132
- `${this.baseUrl}/ajax/${type === 'movie' ? type : ``}${isSeasons ? 'season/list' : 'season/episodes'}/${id}`;
133
-
134
- if (movieInfo.type === TvType.TVSERIES) {
135
- const { data } = await this.client.get(ajaxReqUrl(uid, 'tv', true));
136
- const $$ = load(data);
137
- const seasonsIds = $$('.dropdown-menu > a')
138
- .map((i, el) => $(el).attr('data-id'))
139
- .get();
140
-
141
- movieInfo.episodes = [];
142
- let season = 1;
143
- for (const id of seasonsIds) {
144
- const { data } = await this.client.get(ajaxReqUrl(id, 'season'));
145
- const $$$ = load(data);
146
-
147
- $$$('.nav > li')
148
- .map((i, el) => {
149
- const episode = {
150
- id: $$$(el).find('a').attr('id')!.split('-')[1]!,
151
- title: $$$(el).find('a').attr('title')!,
152
- number: parseInt($$$(el).find('a').attr('title')!.split(':')[0]!.slice(3).trim()),
153
- season: season,
154
- url: `${this.baseUrl}/ajax/episode/servers/${$$$(el).find('a').attr('id')!.split('-')[1]}`,
155
- };
156
- movieInfo.episodes?.push(episode);
157
- })
158
- .get();
159
- season++;
160
- }
161
- } else {
162
- movieInfo.episodes = [
163
- {
164
- id: uid,
165
- title: movieInfo.title,
166
- url: `${this.baseUrl}/ajax/episode/list/${uid}`,
167
- },
168
- ];
169
- }
170
-
171
- return movieInfo;
172
- } catch (err) {
173
- console.log(err);
174
- throw new Error((err as Error).message);
175
- }
176
- };
177
-
178
- /**
179
- *
180
- * @param episodeId episode id
181
- * @param mediaId media id
182
- * @param server server type (default `MegaCloud`) (optional)
183
- */
184
- override fetchEpisodeSources = async (
185
- episodeId: string,
186
- mediaId: string,
187
- server: StreamingServers = StreamingServers.MegaCloud
188
- ): Promise<ISource> => {
189
- if (episodeId.startsWith('http')) {
190
- const serverUrl = new URL(episodeId);
191
- switch (server) {
192
- case StreamingServers.MegaCloud:
193
- return {
194
- headers: { Referer: serverUrl.href },
195
- ...(await new MegaCloud(this.proxyConfig, this.adapter).extract(serverUrl, this.baseUrl)),
196
- };
197
- case StreamingServers.UpCloud:
198
- return {
199
- headers: { Referer: serverUrl.href },
200
- ...(await new VidCloud(this.proxyConfig, this.adapter).extract(serverUrl, undefined, this.baseUrl)),
201
- };
202
- default:
203
- return {
204
- headers: { Referer: serverUrl.href },
205
- ...(await new MegaCloud(this.proxyConfig, this.adapter).extract(serverUrl, this.baseUrl)),
206
- };
207
- }
208
- }
209
-
210
- try {
211
- const servers = await this.fetchEpisodeServers(episodeId, mediaId);
212
-
213
- const i = servers.findIndex((s) => s.name === server);
214
-
215
- if (i === -1) {
216
- throw new Error(`Server ${server} not found`);
217
- }
218
-
219
- const { data } = await this.client.get(
220
- `${this.baseUrl}/ajax/episode/sources/${servers[i]!.url.split('.').slice(-1).shift()}`
221
- );
222
-
223
- const serverUrl: URL = new URL(data.link);
224
-
225
- return await this.fetchEpisodeSources(serverUrl.href, mediaId, server);
226
- } catch (err) {
227
- console.log(err, 'err');
228
- throw new Error((err as Error).message);
229
- }
230
- };
231
-
232
- /**
233
- *
234
- * @param episodeId takes episode link or movie id
235
- * @param mediaId takes movie link or id (found on movie info object)
236
- */
237
- override fetchEpisodeServers = async (episodeId: string, mediaId: string): Promise<IEpisodeServer[]> => {
238
- if (!episodeId.startsWith(this.baseUrl + '/ajax') && !mediaId.includes('movie')) {
239
- episodeId = `${this.baseUrl}/ajax/episode/servers/${episodeId}`;
240
- } else {
241
- episodeId = `${this.baseUrl}/ajax/episode/list/${episodeId}`;
242
- }
243
- try {
244
- const { data } = await this.client.get(episodeId);
245
- const $ = load(data);
246
-
247
- const servers = $('ul.nav > li')
248
- .map((i, el) => {
249
- const server = {
250
- name: $(el).find('a').attr('title')!.slice(6).toLowerCase().replace('server', '').trim(),
251
- url: `${this.baseUrl}/${mediaId}.${$(el).find('a').attr('data-id')}`.replace(
252
- !mediaId.includes('movie') ? /\/tv\// : /\/movie\//,
253
- !mediaId.includes('movie') ? '/watch-tv/' : '/watch-movie/'
254
- ),
255
- };
256
- return server;
257
- })
258
- .get();
259
- return servers;
260
- } catch (err) {
261
- throw new Error((err as Error).message);
262
- }
263
- };
264
-
265
- fetchRecentMovies = async (): Promise<IMovieResult[]> => {
266
- try {
267
- const { data } = await this.client.get(`${this.baseUrl}/home`);
268
- const $ = load(data);
269
-
270
- const movies = $(
271
- 'section.block_area:contains("Latest Movies") > div:nth-child(2) > div:nth-child(1) > div.flw-item'
272
- )
273
- .map((i, el) => {
274
- const releaseDate = $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text();
275
- const movie: any = {
276
- id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
277
- title: $(el).find('div.film-detail > h3.film-name > a').attr('title')!,
278
- url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
279
- image: $(el).find('div.film-poster > img').attr('data-src'),
280
- releaseDate: isNaN(parseInt(releaseDate)) ? undefined : releaseDate,
281
- duration: $(el).find('div.film-detail > div.fd-infor > span.fdi-duration').text() || null,
282
- type:
283
- $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
284
- ? TvType.MOVIE
285
- : TvType.TVSERIES,
286
- };
287
- return movie;
288
- })
289
- .get();
290
- return movies;
291
- } catch (err) {
292
- throw new Error((err as Error).message);
293
- }
294
- };
295
-
296
- fetchRecentTvShows = async (): Promise<IMovieResult[]> => {
297
- try {
298
- const { data } = await this.client.get(`${this.baseUrl}/home`);
299
- const $ = load(data);
300
-
301
- const tvshows = $(
302
- 'section.block_area:contains("Latest TV Shows") > div:nth-child(2) > div:nth-child(1) > div.flw-item'
303
- )
304
- .map((i, el) => {
305
- const tvshow = {
306
- id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
307
- title: $(el).find('div.film-detail > h3.film-name > a').attr('title')!,
308
- url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
309
- image: $(el).find('div.film-poster > img').attr('data-src'),
310
- season: $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text().replace('SS', '').trim(),
311
- latestEpisode:
312
- $(el).find('div.film-detail > div.fd-infor > span:nth-child(3)').text().replace('EPS', '').trim() || null,
313
- type:
314
- $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
315
- ? TvType.MOVIE
316
- : TvType.TVSERIES,
317
- };
318
- return tvshow;
319
- })
320
- .get();
321
- return tvshows;
322
- } catch (err) {
323
- throw new Error((err as Error).message);
324
- }
325
- };
326
-
327
- fetchTrendingMovies = async (): Promise<IMovieResult[]> => {
328
- try {
329
- const { data } = await this.client.get(`${this.baseUrl}/home`);
330
- const $ = load(data);
331
-
332
- const movies = $('div#trending-movies div.film_list-wrap div.flw-item')
333
- .map((i, el) => {
334
- const releaseDate = $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text();
335
- const movie: any = {
336
- id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
337
- title: $(el).find('div.film-detail > h3.film-name > a').attr('title')!,
338
- url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
339
- image: $(el).find('div.film-poster > img').attr('data-src'),
340
- releaseDate: isNaN(parseInt(releaseDate)) ? undefined : releaseDate,
341
- duration: $(el).find('div.film-detail > div.fd-infor > span.fdi-duration').text() || null,
342
- type:
343
- $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
344
- ? TvType.MOVIE
345
- : TvType.TVSERIES,
346
- };
347
- return movie;
348
- })
349
- .get();
350
- return movies;
351
- } catch (err) {
352
- throw new Error((err as Error).message);
353
- }
354
- };
355
-
356
- fetchTrendingTvShows = async (): Promise<IMovieResult[]> => {
357
- try {
358
- const { data } = await this.client.get(`${this.baseUrl}/home`);
359
- const $ = load(data);
360
-
361
- const tvshows = $('div#trending-tv div.film_list-wrap div.flw-item')
362
- .map((i, el) => {
363
- const tvshow = {
364
- id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
365
- title: $(el).find('div.film-detail > h3.film-name > a').attr('title')!,
366
- url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
367
- image: $(el).find('div.film-poster > img').attr('data-src'),
368
- season: $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text().replace('SS', '').trim(),
369
- latestEpisode:
370
- $(el).find('div.film-detail > div.fd-infor > span:nth-child(3)').text().replace('EPS', '').trim() || null,
371
- type:
372
- $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
373
- ? TvType.MOVIE
374
- : TvType.TVSERIES,
375
- };
376
- return tvshow;
377
- })
378
- .get();
379
- return tvshows;
380
- } catch (err) {
381
- throw new Error((err as Error).message);
382
- }
383
- };
384
-
385
- fetchByCountry = async (country: string, page: number = 1): Promise<ISearch<IMovieResult>> => {
386
- const result: ISearch<IMovieResult> = {
387
- currentPage: page,
388
- hasNextPage: false,
389
- results: [],
390
- };
391
- const navSelector = 'div.pre-pagination > nav:nth-child(1) > ul:nth-child(1)';
392
-
393
- try {
394
- const { data } = await this.client.get(`${this.baseUrl}/country/${country}/?page=${page}`);
395
- const $ = load(data);
396
-
397
- result.hasNextPage = $(navSelector).length > 0 ? !$(navSelector).children().last().hasClass('active') : false;
398
-
399
- $('div.container > section.block_area > div.block_area-content > div.film_list-wrap > div.flw-item')
400
- .each((i, el) => {
401
- const resultItem: IMovieResult = {
402
- id: $(el).find('div.film-poster > a').attr('href')?.slice(1) ?? '',
403
- title: $(el).find('div.film-detail > h2.film-name > a').attr('title') ?? '',
404
- url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
405
- image: $(el).find('div.film-poster > img').attr('data-src'),
406
- type:
407
- $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
408
- ? TvType.MOVIE
409
- : TvType.TVSERIES,
410
- };
411
- const season = $(el)
412
- .find('div.film-detail > div.fd-infor > span:nth-child(1)')
413
- .text()
414
- .replace('SS', '')
415
- .trim();
416
- const latestEpisode =
417
- $(el).find('div.film-detail > div.fd-infor > span:nth-child(3)').text().replace('EPS', '').trim() ?? null;
418
- if (resultItem.type === TvType.TVSERIES) {
419
- resultItem.season = season;
420
- resultItem.latestEpisode = latestEpisode;
421
- } else {
422
- resultItem.releaseDate = season;
423
- resultItem.duration = latestEpisode;
424
- }
425
- result.results.push(resultItem);
426
- })
427
- .get();
428
- return result;
429
- } catch (err) {
430
- throw new Error((err as Error).message);
431
- }
432
- };
433
-
434
- fetchByGenre = async (genre: string, page: number = 1): Promise<ISearch<IMovieResult>> => {
435
- const result: ISearch<IMovieResult> = {
436
- currentPage: page,
437
- hasNextPage: false,
438
- results: [],
439
- };
440
- try {
441
- const { data } = await this.client.get(`${this.baseUrl}/genre/${genre}?page=${page}`);
442
-
443
- const $ = load(data);
444
-
445
- const navSelector = 'div.pre-pagination > nav:nth-child(1) > ul:nth-child(1)';
446
-
447
- result.hasNextPage = $(navSelector).length > 0 ? !$(navSelector).children().last().hasClass('active') : false;
448
-
449
- $('.film_list-wrap > div.flw-item')
450
- .each((i, el) => {
451
- const resultItem: IMovieResult = {
452
- id: $(el).find('div.film-poster > a').attr('href')?.slice(1) ?? '',
453
- title: $(el).find('div.film-detail > h2 > a').attr('title') ?? '',
454
- url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
455
- image: $(el).find('div.film-poster > img').attr('data-src'),
456
- type:
457
- $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
458
- ? TvType.MOVIE
459
- : TvType.TVSERIES,
460
- };
461
- const season = $(el)
462
- .find('div.film-detail > div.fd-infor > span:nth-child(1)')
463
- .text()
464
- .replace('SS', '')
465
- .trim();
466
- const latestEpisode =
467
- $(el).find('div.film-detail > div.fd-infor > span:nth-child(3)').text().replace('EPS', '').trim() ?? null;
468
- if (resultItem.type === TvType.TVSERIES) {
469
- resultItem.season = season;
470
- resultItem.latestEpisode = latestEpisode;
471
- } else {
472
- resultItem.releaseDate = season;
473
- resultItem.duration = latestEpisode;
474
- }
475
- result.results.push(resultItem);
476
- })
477
- .get();
478
-
479
- return result;
480
- } catch (err) {
481
- throw new Error((err as Error).message);
482
- }
483
- };
484
- }
485
-
486
- // (async () => {
487
- // const movie = new HiMovies();
488
- // const search = await movie.search('jujutsu');
489
- // const movieInfo = await movie.fetchMediaInfo(search.results[0].id);
490
- // // const recentTv = await movie.fetchTrendingTvShows();
491
- // const genre = await movie.fetchEpisodeSources(movieInfo.episodes![0].id, movieInfo.id);
492
- // console.log(genre);
493
- // })();
494
-
495
- export default HiMovies;
1
+ import { load } from 'cheerio';
2
+
3
+ import {
4
+ MovieParser,
5
+ TvType,
6
+ type IMovieInfo,
7
+ type IEpisodeServer,
8
+ StreamingServers,
9
+ type ISource,
10
+ type IMovieResult,
11
+ type ISearch,
12
+ } from '../../models';
13
+ import { MegaCloud, VidCloud } from '../../extractors';
14
+
15
+ class HiMovies extends MovieParser {
16
+ override readonly name = 'HiMovies';
17
+ protected override baseUrl = 'https://himovies.sx';
18
+ protected override logo = 'https://himovies.sx/images/group_1/theme_1/favicon.png';
19
+ protected override classPath = 'MOVIES.HiMovies';
20
+ override supportedTypes = new Set([TvType.MOVIE, TvType.TVSERIES]);
21
+ constructor(customBaseURL?: string) {
22
+ super(...arguments);
23
+ if (customBaseURL) {
24
+ if (customBaseURL.startsWith('http://') || customBaseURL.startsWith('https://')) {
25
+ this.baseUrl = customBaseURL;
26
+ } else {
27
+ this.baseUrl = `http://${customBaseURL}`;
28
+ }
29
+ } else {
30
+ this.baseUrl = this.baseUrl;
31
+ }
32
+ }
33
+
34
+ /**
35
+ *
36
+ * @param query search query string
37
+ * @param page page number (default 1) (optional)
38
+ */
39
+ override search = async (query: string, page: number = 1): Promise<ISearch<IMovieResult>> => {
40
+ const searchResult: ISearch<IMovieResult> = {
41
+ currentPage: page,
42
+ hasNextPage: false,
43
+ results: [],
44
+ };
45
+ try {
46
+ const { data } = await this.client.get(`${this.baseUrl}/search/${query.replace(/[\W_]+/g, '-')}?page=${page}`);
47
+
48
+ const $ = load(data);
49
+
50
+ const navSelector = 'div.pre-pagination > nav:nth-child(1) > ul:nth-child(1)';
51
+ searchResult.hasNextPage =
52
+ $(navSelector).length > 0 ? !$(navSelector).children().last().hasClass('active') : false;
53
+
54
+ $('.film_list-wrap > div.flw-item').each((i, el) => {
55
+ const releaseDate = $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text();
56
+ searchResult.results.push({
57
+ id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
58
+ title: $(el).find('div.film-detail > h2 > a').attr('title')!,
59
+ url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
60
+ image: $(el).find('div.film-poster > img').attr('data-src'),
61
+ releaseDate: isNaN(parseInt(releaseDate)) ? undefined : releaseDate,
62
+ seasons: releaseDate.includes('SS') ? parseInt(releaseDate.split('SS')[1]!) : undefined,
63
+ type:
64
+ $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
65
+ ? TvType.MOVIE
66
+ : TvType.TVSERIES,
67
+ });
68
+ });
69
+
70
+ return searchResult;
71
+ } catch (err) {
72
+ throw new Error((err as Error).message);
73
+ }
74
+ };
75
+
76
+ /**
77
+ *
78
+ * @param mediaId media link or id
79
+ */
80
+ override fetchMediaInfo = async (mediaId: string): Promise<IMovieInfo> => {
81
+ if (!mediaId.startsWith(this.baseUrl)) {
82
+ mediaId = `${this.baseUrl}/${mediaId}`;
83
+ }
84
+
85
+ const movieInfo: IMovieInfo = {
86
+ id: mediaId.split('sx/').pop()!,
87
+ title: '',
88
+ url: mediaId,
89
+ };
90
+ try {
91
+ const { data } = await this.client.get(mediaId);
92
+ const $ = load(data);
93
+ const recommendationsArray: IMovieResult[] = [];
94
+
95
+ $('section.block_area > div.block_area-content > div.film_list-wrap > div.flw-item').each((i, el) => {
96
+ recommendationsArray.push({
97
+ id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
98
+ title: $(el).find('div.film-detail > h3.film-name > a').text(),
99
+ image: $(el).find('div.film-poster > img').attr('data-src'),
100
+ duration: $(el).find('div.film-detail > div.fd-infor > span.fdi-duration').text().replace('m', '') ?? null,
101
+ type:
102
+ $(el).find('div.film-detail > div.fd-infor > span.fdi-type').text() === 'TV'
103
+ ? TvType.TVSERIES
104
+ : (TvType.MOVIE ?? null),
105
+ });
106
+ });
107
+
108
+ const uid = $('.detail_page-watch').attr('data-id')!;
109
+ movieInfo.cover = $('div.cover_follow').attr('style')?.slice(22).replace(')', '').replace(';', '');
110
+ movieInfo.title = $('.heading-name > a:nth-child(1)').text();
111
+ movieInfo.image = $('.film-poster > img:nth-child(1)').attr('src');
112
+ movieInfo.description = $('.description').text().trim();
113
+ movieInfo.type = movieInfo.id.includes('tv/') ? TvType.TVSERIES : TvType.MOVIE;
114
+ movieInfo.releaseDate = $('div.row-line:contains(Released:)').text().replace('Released:', '').trim();
115
+ movieInfo.genres = $('div.row-line:contains(Genre:) a')
116
+ .map((i, el) => $(el).text().split('&'))
117
+ .get()
118
+ .map((v) => v.trim());
119
+ movieInfo.casts = $('.row-line:contains(Casts:) a')
120
+ .map((i, el) => $(el).text())
121
+ .get();
122
+ movieInfo.production = $('.row-line:contains(Production:) a').text().trim();
123
+ movieInfo.country = $('.row-line:contains(Country:) a').text().trim();
124
+ movieInfo.duration = $('.row-line:contains(Duration:)')
125
+ .text()
126
+ .replace('Duration:', '')
127
+ .replace(/\s+/g, ' ')
128
+ .trim();
129
+ movieInfo.rating = parseFloat($('.dp-i-stats > span.item:nth-child(3)').text().replace('IMDB:', '').trim());
130
+ movieInfo.recommendations = recommendationsArray as any;
131
+ const ajaxReqUrl = (id: string, type: string, isSeasons: boolean = false) =>
132
+ `${this.baseUrl}/ajax/${type === 'movie' ? type : ``}${isSeasons ? 'season/list' : 'season/episodes'}/${id}`;
133
+
134
+ if (movieInfo.type === TvType.TVSERIES) {
135
+ const { data } = await this.client.get(ajaxReqUrl(uid, 'tv', true));
136
+ const $$ = load(data);
137
+ const seasonsIds = $$('.dropdown-menu > a')
138
+ .map((i, el) => $(el).attr('data-id'))
139
+ .get();
140
+
141
+ movieInfo.episodes = [];
142
+ let season = 1;
143
+ for (const id of seasonsIds) {
144
+ const { data } = await this.client.get(ajaxReqUrl(id, 'season'));
145
+ const $$$ = load(data);
146
+
147
+ $$$('.nav > li')
148
+ .map((i, el) => {
149
+ const episode = {
150
+ id: $$$(el).find('a').attr('id')!.split('-')[1]!,
151
+ title: $$$(el).find('a').attr('title')!,
152
+ number: parseInt($$$(el).find('a').attr('title')!.split(':')[0]!.slice(3).trim()),
153
+ season: season,
154
+ url: `${this.baseUrl}/ajax/episode/servers/${$$$(el).find('a').attr('id')!.split('-')[1]}`,
155
+ };
156
+ movieInfo.episodes?.push(episode);
157
+ })
158
+ .get();
159
+ season++;
160
+ }
161
+ } else {
162
+ movieInfo.episodes = [
163
+ {
164
+ id: uid,
165
+ title: movieInfo.title,
166
+ url: `${this.baseUrl}/ajax/episode/list/${uid}`,
167
+ },
168
+ ];
169
+ }
170
+
171
+ return movieInfo;
172
+ } catch (err) {
173
+ console.log(err);
174
+ throw new Error((err as Error).message);
175
+ }
176
+ };
177
+
178
+ /**
179
+ *
180
+ * @param episodeId episode id
181
+ * @param mediaId media id
182
+ * @param server server type (default `MegaCloud`) (optional)
183
+ */
184
+ override fetchEpisodeSources = async (
185
+ episodeId: string,
186
+ mediaId: string,
187
+ server: StreamingServers = StreamingServers.MegaCloud
188
+ ): Promise<ISource> => {
189
+ if (episodeId.startsWith('http')) {
190
+ const serverUrl = new URL(episodeId);
191
+ switch (server) {
192
+ case StreamingServers.MegaCloud:
193
+ return {
194
+ headers: { Referer: serverUrl.href },
195
+ ...(await new MegaCloud(this.proxyConfig, this.adapter).extract(serverUrl, this.baseUrl)),
196
+ };
197
+ case StreamingServers.UpCloud:
198
+ return {
199
+ headers: { Referer: serverUrl.href },
200
+ ...(await new VidCloud(this.proxyConfig, this.adapter).extract(serverUrl, undefined, this.baseUrl)),
201
+ };
202
+ default:
203
+ return {
204
+ headers: { Referer: serverUrl.href },
205
+ ...(await new MegaCloud(this.proxyConfig, this.adapter).extract(serverUrl, this.baseUrl)),
206
+ };
207
+ }
208
+ }
209
+
210
+ try {
211
+ const servers = await this.fetchEpisodeServers(episodeId, mediaId);
212
+
213
+ const i = servers.findIndex((s) => s.name === server);
214
+
215
+ if (i === -1) {
216
+ throw new Error(`Server ${server} not found`);
217
+ }
218
+
219
+ const { data } = await this.client.get(
220
+ `${this.baseUrl}/ajax/episode/sources/${servers[i]!.url.split('.').slice(-1).shift()}`
221
+ );
222
+
223
+ const serverUrl: URL = new URL(data.link);
224
+
225
+ return await this.fetchEpisodeSources(serverUrl.href, mediaId, server);
226
+ } catch (err) {
227
+ console.log(err, 'err');
228
+ throw new Error((err as Error).message);
229
+ }
230
+ };
231
+
232
+ /**
233
+ *
234
+ * @param episodeId takes episode link or movie id
235
+ * @param mediaId takes movie link or id (found on movie info object)
236
+ */
237
+ override fetchEpisodeServers = async (episodeId: string, mediaId: string): Promise<IEpisodeServer[]> => {
238
+ if (!episodeId.startsWith(this.baseUrl + '/ajax') && !mediaId.includes('movie')) {
239
+ episodeId = `${this.baseUrl}/ajax/episode/servers/${episodeId}`;
240
+ } else {
241
+ episodeId = `${this.baseUrl}/ajax/episode/list/${episodeId}`;
242
+ }
243
+ try {
244
+ const { data } = await this.client.get(episodeId);
245
+ const $ = load(data);
246
+
247
+ const servers = $('ul.nav > li')
248
+ .map((i, el) => {
249
+ const server = {
250
+ name: $(el).find('a').attr('title')!.slice(6).toLowerCase().replace('server', '').trim(),
251
+ url: `${this.baseUrl}/${mediaId}.${$(el).find('a').attr('data-id')}`.replace(
252
+ !mediaId.includes('movie') ? /\/tv\// : /\/movie\//,
253
+ !mediaId.includes('movie') ? '/watch-tv/' : '/watch-movie/'
254
+ ),
255
+ };
256
+ return server;
257
+ })
258
+ .get();
259
+ return servers;
260
+ } catch (err) {
261
+ throw new Error((err as Error).message);
262
+ }
263
+ };
264
+
265
+ fetchRecentMovies = async (): Promise<IMovieResult[]> => {
266
+ try {
267
+ const { data } = await this.client.get(`${this.baseUrl}/home`);
268
+ const $ = load(data);
269
+
270
+ const movies = $(
271
+ 'section.block_area:contains("Latest Movies") > div:nth-child(2) > div:nth-child(1) > div.flw-item'
272
+ )
273
+ .map((i, el) => {
274
+ const releaseDate = $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text();
275
+ const movie: any = {
276
+ id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
277
+ title: $(el).find('div.film-detail > h3.film-name > a').attr('title')!,
278
+ url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
279
+ image: $(el).find('div.film-poster > img').attr('data-src'),
280
+ releaseDate: isNaN(parseInt(releaseDate)) ? undefined : releaseDate,
281
+ duration: $(el).find('div.film-detail > div.fd-infor > span.fdi-duration').text() || null,
282
+ type:
283
+ $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
284
+ ? TvType.MOVIE
285
+ : TvType.TVSERIES,
286
+ };
287
+ return movie;
288
+ })
289
+ .get();
290
+ return movies;
291
+ } catch (err) {
292
+ throw new Error((err as Error).message);
293
+ }
294
+ };
295
+
296
+ fetchRecentTvShows = async (): Promise<IMovieResult[]> => {
297
+ try {
298
+ const { data } = await this.client.get(`${this.baseUrl}/home`);
299
+ const $ = load(data);
300
+
301
+ const tvshows = $(
302
+ 'section.block_area:contains("Latest TV Shows") > div:nth-child(2) > div:nth-child(1) > div.flw-item'
303
+ )
304
+ .map((i, el) => {
305
+ const tvshow = {
306
+ id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
307
+ title: $(el).find('div.film-detail > h3.film-name > a').attr('title')!,
308
+ url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
309
+ image: $(el).find('div.film-poster > img').attr('data-src'),
310
+ season: $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text().replace('SS', '').trim(),
311
+ latestEpisode:
312
+ $(el).find('div.film-detail > div.fd-infor > span:nth-child(3)').text().replace('EPS', '').trim() || null,
313
+ type:
314
+ $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
315
+ ? TvType.MOVIE
316
+ : TvType.TVSERIES,
317
+ };
318
+ return tvshow;
319
+ })
320
+ .get();
321
+ return tvshows;
322
+ } catch (err) {
323
+ throw new Error((err as Error).message);
324
+ }
325
+ };
326
+
327
+ fetchTrendingMovies = async (): Promise<IMovieResult[]> => {
328
+ try {
329
+ const { data } = await this.client.get(`${this.baseUrl}/home`);
330
+ const $ = load(data);
331
+
332
+ const movies = $('div#trending-movies div.film_list-wrap div.flw-item')
333
+ .map((i, el) => {
334
+ const releaseDate = $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text();
335
+ const movie: any = {
336
+ id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
337
+ title: $(el).find('div.film-detail > h3.film-name > a').attr('title')!,
338
+ url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
339
+ image: $(el).find('div.film-poster > img').attr('data-src'),
340
+ releaseDate: isNaN(parseInt(releaseDate)) ? undefined : releaseDate,
341
+ duration: $(el).find('div.film-detail > div.fd-infor > span.fdi-duration').text() || null,
342
+ type:
343
+ $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
344
+ ? TvType.MOVIE
345
+ : TvType.TVSERIES,
346
+ };
347
+ return movie;
348
+ })
349
+ .get();
350
+ return movies;
351
+ } catch (err) {
352
+ throw new Error((err as Error).message);
353
+ }
354
+ };
355
+
356
+ fetchTrendingTvShows = async (): Promise<IMovieResult[]> => {
357
+ try {
358
+ const { data } = await this.client.get(`${this.baseUrl}/home`);
359
+ const $ = load(data);
360
+
361
+ const tvshows = $('div#trending-tv div.film_list-wrap div.flw-item')
362
+ .map((i, el) => {
363
+ const tvshow = {
364
+ id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!,
365
+ title: $(el).find('div.film-detail > h3.film-name > a').attr('title')!,
366
+ url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
367
+ image: $(el).find('div.film-poster > img').attr('data-src'),
368
+ season: $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text().replace('SS', '').trim(),
369
+ latestEpisode:
370
+ $(el).find('div.film-detail > div.fd-infor > span:nth-child(3)').text().replace('EPS', '').trim() || null,
371
+ type:
372
+ $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
373
+ ? TvType.MOVIE
374
+ : TvType.TVSERIES,
375
+ };
376
+ return tvshow;
377
+ })
378
+ .get();
379
+ return tvshows;
380
+ } catch (err) {
381
+ throw new Error((err as Error).message);
382
+ }
383
+ };
384
+
385
+ fetchByCountry = async (country: string, page: number = 1): Promise<ISearch<IMovieResult>> => {
386
+ const result: ISearch<IMovieResult> = {
387
+ currentPage: page,
388
+ hasNextPage: false,
389
+ results: [],
390
+ };
391
+ const navSelector = 'div.pre-pagination > nav:nth-child(1) > ul:nth-child(1)';
392
+
393
+ try {
394
+ const { data } = await this.client.get(`${this.baseUrl}/country/${country}/?page=${page}`);
395
+ const $ = load(data);
396
+
397
+ result.hasNextPage = $(navSelector).length > 0 ? !$(navSelector).children().last().hasClass('active') : false;
398
+
399
+ $('div.container > section.block_area > div.block_area-content > div.film_list-wrap > div.flw-item')
400
+ .each((i, el) => {
401
+ const resultItem: IMovieResult = {
402
+ id: $(el).find('div.film-poster > a').attr('href')?.slice(1) ?? '',
403
+ title: $(el).find('div.film-detail > h2.film-name > a').attr('title') ?? '',
404
+ url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
405
+ image: $(el).find('div.film-poster > img').attr('data-src'),
406
+ type:
407
+ $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
408
+ ? TvType.MOVIE
409
+ : TvType.TVSERIES,
410
+ };
411
+ const season = $(el)
412
+ .find('div.film-detail > div.fd-infor > span:nth-child(1)')
413
+ .text()
414
+ .replace('SS', '')
415
+ .trim();
416
+ const latestEpisode =
417
+ $(el).find('div.film-detail > div.fd-infor > span:nth-child(3)').text().replace('EPS', '').trim() ?? null;
418
+ if (resultItem.type === TvType.TVSERIES) {
419
+ resultItem.season = season;
420
+ resultItem.latestEpisode = latestEpisode;
421
+ } else {
422
+ resultItem.releaseDate = season;
423
+ resultItem.duration = latestEpisode;
424
+ }
425
+ result.results.push(resultItem);
426
+ })
427
+ .get();
428
+ return result;
429
+ } catch (err) {
430
+ throw new Error((err as Error).message);
431
+ }
432
+ };
433
+
434
+ fetchByGenre = async (genre: string, page: number = 1): Promise<ISearch<IMovieResult>> => {
435
+ const result: ISearch<IMovieResult> = {
436
+ currentPage: page,
437
+ hasNextPage: false,
438
+ results: [],
439
+ };
440
+ try {
441
+ const { data } = await this.client.get(`${this.baseUrl}/genre/${genre}?page=${page}`);
442
+
443
+ const $ = load(data);
444
+
445
+ const navSelector = 'div.pre-pagination > nav:nth-child(1) > ul:nth-child(1)';
446
+
447
+ result.hasNextPage = $(navSelector).length > 0 ? !$(navSelector).children().last().hasClass('active') : false;
448
+
449
+ $('.film_list-wrap > div.flw-item')
450
+ .each((i, el) => {
451
+ const resultItem: IMovieResult = {
452
+ id: $(el).find('div.film-poster > a').attr('href')?.slice(1) ?? '',
453
+ title: $(el).find('div.film-detail > h2 > a').attr('title') ?? '',
454
+ url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`,
455
+ image: $(el).find('div.film-poster > img').attr('data-src'),
456
+ type:
457
+ $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie'
458
+ ? TvType.MOVIE
459
+ : TvType.TVSERIES,
460
+ };
461
+ const season = $(el)
462
+ .find('div.film-detail > div.fd-infor > span:nth-child(1)')
463
+ .text()
464
+ .replace('SS', '')
465
+ .trim();
466
+ const latestEpisode =
467
+ $(el).find('div.film-detail > div.fd-infor > span:nth-child(3)').text().replace('EPS', '').trim() ?? null;
468
+ if (resultItem.type === TvType.TVSERIES) {
469
+ resultItem.season = season;
470
+ resultItem.latestEpisode = latestEpisode;
471
+ } else {
472
+ resultItem.releaseDate = season;
473
+ resultItem.duration = latestEpisode;
474
+ }
475
+ result.results.push(resultItem);
476
+ })
477
+ .get();
478
+
479
+ return result;
480
+ } catch (err) {
481
+ throw new Error((err as Error).message);
482
+ }
483
+ };
484
+ }
485
+
486
+ // (async () => {
487
+ // const movie = new HiMovies();
488
+ // const search = await movie.search('jujutsu');
489
+ // const movieInfo = await movie.fetchMediaInfo(search.results[0].id);
490
+ // // const recentTv = await movie.fetchTrendingTvShows();
491
+ // const genre = await movie.fetchEpisodeSources(movieInfo.episodes![0].id, movieInfo.id);
492
+ // console.log(genre);
493
+ // })();
494
+
495
+ export default HiMovies;