react-native-consumet 1.0.0-rc.0 → 1.0.0-rc.2
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.
- package/android/generated/java/com/consumet/NativeConsumetSpec.java +4 -0
- package/android/generated/jni/RNConsumetSpec-generated.cpp +6 -0
- package/android/generated/jni/react/renderer/components/RNConsumetSpec/RNConsumetSpecJSI-generated.cpp +8 -0
- package/android/generated/jni/react/renderer/components/RNConsumetSpec/RNConsumetSpecJSI.h +9 -0
- package/android/src/main/java/com/consumet/ConsumetModule.kt +7 -0
- package/android/src/main/java/com/consumet/DdosGuardModule.kt +248 -189
- package/ios/generated/RNConsumetSpec/RNConsumetSpec-generated.mm +7 -0
- package/ios/generated/RNConsumetSpec/RNConsumetSpec.h +2 -0
- package/ios/generated/RNConsumetSpecJSI-generated.cpp +8 -0
- package/ios/generated/RNConsumetSpecJSI.h +9 -0
- package/lib/commonjs/NativeConsumet.ts +28 -26
- package/lib/commonjs/extension-registry.json +13 -13
- package/lib/commonjs/extractors/filemoon.js +2 -2
- package/lib/commonjs/extractors/kwik.js +60 -15
- package/lib/commonjs/extractors/kwik.js.map +1 -1
- package/lib/commonjs/extractors/megacloud.js +6 -6
- package/lib/commonjs/index.js +2 -11
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/types.js +4 -4
- package/lib/commonjs/models/video-extractor.js +4 -4
- package/lib/commonjs/providers/anime/animedrive.js +12 -12
- package/lib/commonjs/providers/anime/animekai.js +41 -41
- package/lib/commonjs/providers/anime/animepahe/animepahe.js +16 -15
- package/lib/commonjs/providers/anime/animepahe/animepahe.js.map +1 -1
- package/lib/commonjs/providers/anime/animepahe/create-animepahe.js +12 -9
- package/lib/commonjs/providers/anime/animepahe/create-animepahe.js.map +1 -1
- package/lib/commonjs/providers/anime/animesuge/animesuge.js +78 -0
- package/lib/commonjs/providers/anime/animesuge/animesuge.js.map +1 -0
- package/lib/commonjs/providers/anime/animesuge/create-animesuge.js +312 -0
- package/lib/commonjs/providers/anime/animesuge/create-animesuge.js.map +1 -0
- package/lib/commonjs/providers/anime/animeunity.js +13 -13
- package/lib/commonjs/providers/anime/index.js +4 -4
- package/lib/commonjs/providers/anime/index.js.map +1 -1
- package/lib/commonjs/providers/anime/marin.js +12 -12
- package/lib/commonjs/providers/anime/zoro/create-zoro.js +2 -2
- package/lib/commonjs/providers/anime/zoro/create-zoro.js.map +1 -1
- package/lib/commonjs/providers/anime/zoro/zoro.js +76 -74
- package/lib/commonjs/providers/anime/zoro/zoro.js.map +1 -1
- package/lib/commonjs/providers/manga/brmangas.js +3 -3
- package/lib/commonjs/providers/meta/anilist.js +91 -91
- package/lib/commonjs/providers/meta/mal.js +12 -12
- package/lib/commonjs/providers/meta/tmdb.js +21 -21
- package/lib/commonjs/providers/movies/himovies/create-himovies.js +16 -16
- package/lib/commonjs/providers/movies/himovies/himovies.js +16 -16
- package/lib/commonjs/providers/movies/multimovies.js +15 -15
- package/lib/commonjs/providers/movies/multistream/index.js +21 -20
- package/lib/commonjs/providers/movies/multistream/index.js.map +1 -1
- package/lib/commonjs/providers/movies/multistream/utils.js +142 -130
- package/lib/commonjs/providers/movies/multistream/utils.js.map +1 -1
- package/lib/commonjs/utils/ExtractorManager.js +15 -15
- package/lib/commonjs/utils/ExtractorManager.js.map +1 -1
- package/lib/commonjs/utils/ProviderManager.js +2 -1
- package/lib/commonjs/utils/ProviderManager.js.map +1 -1
- package/lib/commonjs/utils/create-extractor-context.js +9 -1
- package/lib/commonjs/utils/create-extractor-context.js.map +1 -1
- package/lib/commonjs/utils/create-provider-context.js +6 -2
- package/lib/commonjs/utils/create-provider-context.js.map +1 -1
- package/lib/commonjs/utils/extension-utils.js +44 -54
- package/lib/commonjs/utils/extension-utils.js.map +1 -1
- package/lib/commonjs/utils/index.js +2 -2
- package/lib/commonjs/utils/provider-maps.js +31 -0
- package/lib/commonjs/utils/provider-maps.js.map +1 -0
- package/lib/commonjs/utils/providers-list.js +4 -4
- package/lib/commonjs/utils/url-polyfill.js +4 -4
- package/lib/module/NativeConsumet.ts +28 -26
- package/lib/module/extension-registry.json +13 -13
- package/lib/module/extractors/filemoon.js +2 -2
- package/lib/module/extractors/kwik.js +60 -15
- package/lib/module/extractors/kwik.js.map +1 -1
- package/lib/module/extractors/megacloud.js +6 -6
- package/lib/module/index.js +3 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/types.js +4 -4
- package/lib/module/models/video-extractor.js +4 -4
- package/lib/module/providers/anime/animedrive.js +12 -12
- package/lib/module/providers/anime/animekai.js +41 -41
- package/lib/module/providers/anime/animepahe/animepahe.js +14 -14
- package/lib/module/providers/anime/animepahe/animepahe.js.map +1 -1
- package/lib/module/providers/anime/animepahe/create-animepahe.js +13 -9
- package/lib/module/providers/anime/animepahe/create-animepahe.js.map +1 -1
- package/lib/module/providers/anime/animesuge/animesuge.js +73 -0
- package/lib/module/providers/anime/animesuge/animesuge.js.map +1 -0
- package/lib/module/providers/anime/animesuge/create-animesuge.js +309 -0
- package/lib/module/providers/anime/animesuge/create-animesuge.js.map +1 -0
- package/lib/module/providers/anime/animeunity.js +13 -13
- package/lib/module/providers/anime/index.js +2 -2
- package/lib/module/providers/anime/index.js.map +1 -1
- package/lib/module/providers/anime/marin.js +12 -12
- package/lib/module/providers/anime/zoro/create-zoro.js +3 -2
- package/lib/module/providers/anime/zoro/create-zoro.js.map +1 -1
- package/lib/module/providers/anime/zoro/zoro.js +74 -73
- package/lib/module/providers/anime/zoro/zoro.js.map +1 -1
- package/lib/module/providers/manga/brmangas.js +3 -3
- package/lib/module/providers/meta/anilist.js +91 -91
- package/lib/module/providers/meta/mal.js +12 -12
- package/lib/module/providers/meta/tmdb.js +21 -21
- package/lib/module/providers/movies/himovies/create-himovies.js +16 -16
- package/lib/module/providers/movies/himovies/himovies.js +16 -16
- package/lib/module/providers/movies/multimovies.js +15 -15
- package/lib/module/providers/movies/multistream/index.js +21 -20
- package/lib/module/providers/movies/multistream/index.js.map +1 -1
- package/lib/module/providers/movies/multistream/utils.js +141 -129
- package/lib/module/providers/movies/multistream/utils.js.map +1 -1
- package/lib/module/utils/ExtractorManager.js +16 -16
- package/lib/module/utils/ExtractorManager.js.map +1 -1
- package/lib/module/utils/ProviderManager.js +2 -1
- package/lib/module/utils/ProviderManager.js.map +1 -1
- package/lib/module/utils/create-extractor-context.js +10 -1
- package/lib/module/utils/create-extractor-context.js.map +1 -1
- package/lib/module/utils/create-provider-context.js +8 -4
- package/lib/module/utils/create-provider-context.js.map +1 -1
- package/lib/module/utils/extension-utils.js +23 -33
- package/lib/module/utils/extension-utils.js.map +1 -1
- package/lib/module/utils/index.js +1 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/provider-maps.js +27 -0
- package/lib/module/utils/provider-maps.js.map +1 -0
- package/lib/module/utils/providers-list.js +4 -4
- package/lib/module/utils/url-polyfill.js +4 -4
- package/lib/typescript/commonjs/src/NativeConsumet.d.ts +2 -0
- package/lib/typescript/commonjs/src/NativeConsumet.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/extractors/kwik.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +6 -6
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/models/extractor-context.d.ts +8 -0
- package/lib/typescript/commonjs/src/models/extractor-context.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/models/index.d.ts +2 -2
- package/lib/typescript/commonjs/src/models/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/models/provider-context.d.ts +6 -2
- package/lib/typescript/commonjs/src/models/provider-context.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/animepahe/animepahe.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/animepahe/create-animepahe.d.ts +1 -1
- package/lib/typescript/commonjs/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/animesuge/animesuge.d.ts +34 -0
- package/lib/typescript/commonjs/src/providers/anime/animesuge/animesuge.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/providers/anime/animesuge/create-animesuge.d.ts +14 -0
- package/lib/typescript/commonjs/src/providers/anime/animesuge/create-animesuge.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/providers/anime/index.d.ts +2 -2
- package/lib/typescript/commonjs/src/providers/anime/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/zoro/create-zoro.d.ts +1 -1
- package/lib/typescript/commonjs/src/providers/anime/zoro/create-zoro.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/zoro/zoro.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/movies/multistream/index.d.ts +1 -1
- package/lib/typescript/commonjs/src/providers/movies/multistream/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/movies/multistream/utils.d.ts +2 -2
- package/lib/typescript/commonjs/src/providers/movies/multistream/utils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/ProviderManager.d.ts +1 -1
- package/lib/typescript/commonjs/src/utils/ProviderManager.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/create-extractor-context.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/create-provider-context.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/extension-utils.d.ts +1 -20
- package/lib/typescript/commonjs/src/utils/extension-utils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/provider-maps.d.ts +27 -0
- package/lib/typescript/commonjs/src/utils/provider-maps.d.ts.map +1 -0
- package/lib/typescript/module/src/NativeConsumet.d.ts +2 -0
- package/lib/typescript/module/src/NativeConsumet.d.ts.map +1 -1
- package/lib/typescript/module/src/extractors/kwik.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +6 -6
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/models/extractor-context.d.ts +8 -0
- package/lib/typescript/module/src/models/extractor-context.d.ts.map +1 -1
- package/lib/typescript/module/src/models/index.d.ts +2 -2
- package/lib/typescript/module/src/models/index.d.ts.map +1 -1
- package/lib/typescript/module/src/models/provider-context.d.ts +6 -2
- package/lib/typescript/module/src/models/provider-context.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/animepahe/animepahe.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/animepahe/create-animepahe.d.ts +1 -1
- package/lib/typescript/module/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/animesuge/animesuge.d.ts +34 -0
- package/lib/typescript/module/src/providers/anime/animesuge/animesuge.d.ts.map +1 -0
- package/lib/typescript/module/src/providers/anime/animesuge/create-animesuge.d.ts +14 -0
- package/lib/typescript/module/src/providers/anime/animesuge/create-animesuge.d.ts.map +1 -0
- package/lib/typescript/module/src/providers/anime/index.d.ts +2 -2
- package/lib/typescript/module/src/providers/anime/index.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/zoro/create-zoro.d.ts +1 -1
- package/lib/typescript/module/src/providers/anime/zoro/create-zoro.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/zoro/zoro.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/movies/multistream/index.d.ts +1 -1
- package/lib/typescript/module/src/providers/movies/multistream/index.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/movies/multistream/utils.d.ts +2 -2
- package/lib/typescript/module/src/providers/movies/multistream/utils.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/ProviderManager.d.ts +1 -1
- package/lib/typescript/module/src/utils/ProviderManager.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/create-extractor-context.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/create-provider-context.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/extension-utils.d.ts +1 -20
- package/lib/typescript/module/src/utils/extension-utils.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/index.d.ts +2 -1
- package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/provider-maps.d.ts +27 -0
- package/lib/typescript/module/src/utils/provider-maps.d.ts.map +1 -0
- package/package.json +6 -2
- package/src/NativeConsumet.ts +2 -0
- package/src/extension-registry.json +81 -81
- package/src/extractors/StreamP2P.ts +60 -60
- package/src/extractors/filemoon.ts +58 -58
- package/src/extractors/index.ts +41 -41
- package/src/extractors/kwik.ts +113 -50
- package/src/extractors/megacloud.ts +163 -163
- package/src/extractors/mixdrop.ts +31 -31
- package/src/extractors/mp4upload.ts +31 -31
- package/src/extractors/streamhub.ts +58 -58
- package/src/extractors/streamwish.ts +120 -120
- package/src/extractors/vidhide.ts +59 -59
- package/src/index.tsx +176 -175
- package/src/models/extension-manifest.ts +77 -77
- package/src/models/extractor-context.ts +55 -41
- package/src/models/index.ts +107 -106
- package/src/models/provider-context.ts +192 -182
- package/src/models/types.ts +531 -531
- package/src/models/video-extractor.ts +48 -48
- package/src/providers/anime/animedrive.ts +245 -245
- package/src/providers/anime/animekai.ts +627 -627
- package/src/providers/anime/animepahe/animepahe.ts +76 -76
- package/src/providers/anime/animepahe/create-animepahe.ts +350 -348
- package/src/providers/anime/animesuge/animesuge.ts +77 -0
- package/src/providers/anime/animesuge/create-animesuge.ts +327 -0
- package/src/providers/anime/animeunity.ts +216 -216
- package/src/providers/anime/index.ts +21 -21
- package/src/providers/anime/marin.ts +319 -319
- package/src/providers/anime/zoro/create-zoro.ts +656 -655
- package/src/providers/anime/zoro/zoro.ts +198 -197
- package/src/providers/index.ts +7 -7
- package/src/providers/manga/brmangas.ts +144 -144
- package/src/providers/meta/anilist.ts +2108 -2108
- package/src/providers/meta/mal.ts +635 -635
- package/src/providers/meta/tmdb.ts +470 -470
- package/src/providers/movies/himovies/create-himovies.ts +529 -529
- package/src/providers/movies/himovies/himovies.ts +90 -90
- package/src/providers/movies/index.ts +15 -15
- package/src/providers/movies/multimovies.ts +495 -495
- package/src/providers/movies/multistream/index.ts +232 -231
- package/src/providers/movies/multistream/utils.ts +147 -270
- package/src/utils/ExtractorManager.ts +311 -311
- package/src/utils/ProviderManager.ts +423 -424
- package/src/utils/create-extractor-context.ts +36 -22
- package/src/utils/create-provider-context.ts +117 -107
- package/src/utils/extension-utils.ts +105 -114
- package/src/utils/index.ts +96 -95
- package/src/utils/provider-maps.ts +31 -0
- package/src/utils/providers-list.ts +27 -27
- package/src/utils/url-polyfill.ts +642 -642
- package/src/utils/utils.ts +374 -374
|
@@ -1,470 +1,470 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import {
|
|
3
|
-
type ISearch,
|
|
4
|
-
type IAnimeInfo,
|
|
5
|
-
type IAnimeResult,
|
|
6
|
-
type ISource,
|
|
7
|
-
type IEpisodeServer,
|
|
8
|
-
MovieParser,
|
|
9
|
-
TvType,
|
|
10
|
-
type IMovieResult,
|
|
11
|
-
type IMovieInfo,
|
|
12
|
-
type ProxyConfig,
|
|
13
|
-
type IMovieEpisode,
|
|
14
|
-
} from '../../models';
|
|
15
|
-
import type { IPeopleResult } from '../../models/types';
|
|
16
|
-
import { calculateStringSimilarity } from '../../utils';
|
|
17
|
-
import type { AxiosAdapter } from 'axios';
|
|
18
|
-
import HiMovies from '../movies/himovies/himovies';
|
|
19
|
-
|
|
20
|
-
class TMDB extends MovieParser {
|
|
21
|
-
override readonly name = 'TMDB';
|
|
22
|
-
protected override baseUrl = 'https://www.themoviedb.org';
|
|
23
|
-
protected apiUrl = 'https://api.themoviedb.org/3';
|
|
24
|
-
protected override logo = 'https://pbs.twimg.com/profile_images/1243623122089041920/gVZIvphd_400x400.jpg';
|
|
25
|
-
protected override classPath = 'META.TMDB';
|
|
26
|
-
override supportedTypes = new Set([TvType.MOVIE, TvType.TVSERIES, TvType.ANIME]);
|
|
27
|
-
|
|
28
|
-
private provider: MovieParser;
|
|
29
|
-
|
|
30
|
-
constructor(
|
|
31
|
-
private apiKey: string = '5201b54eb0968700e693a30576d7d4dc',
|
|
32
|
-
provider?: MovieParser,
|
|
33
|
-
proxyConfig?: ProxyConfig,
|
|
34
|
-
adapter?: AxiosAdapter
|
|
35
|
-
) {
|
|
36
|
-
super();
|
|
37
|
-
this.provider = provider || new HiMovies();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @param type trending type: tv series, movie, people or all
|
|
42
|
-
* @param timePeriod trending time period day or week
|
|
43
|
-
* @param page page number
|
|
44
|
-
*/
|
|
45
|
-
fetchTrending = async (
|
|
46
|
-
type: string | 'all',
|
|
47
|
-
timePeriod: 'day' | 'week' = 'day',
|
|
48
|
-
page: number = 1
|
|
49
|
-
): Promise<ISearch<IMovieResult | IAnimeResult | IPeopleResult>> => {
|
|
50
|
-
const trendingUrl = `${this.apiUrl}/trending/${
|
|
51
|
-
type.toLowerCase() === TvType.MOVIE.toLowerCase()
|
|
52
|
-
? 'movie'
|
|
53
|
-
: type.toLowerCase() === TvType.TVSERIES.toLowerCase()
|
|
54
|
-
? 'tv'
|
|
55
|
-
: type.toLowerCase() === TvType.PEOPLE.toLowerCase()
|
|
56
|
-
? 'person'
|
|
57
|
-
: 'all'
|
|
58
|
-
}/${timePeriod}?page=${page}&api_key=${this.apiKey}&language=en-US`;
|
|
59
|
-
|
|
60
|
-
const result: ISearch<IMovieResult | IAnimeResult | IPeopleResult> = {
|
|
61
|
-
currentPage: page,
|
|
62
|
-
hasNextPage: false,
|
|
63
|
-
results: [],
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const { data } = await axios.get(trendingUrl);
|
|
68
|
-
|
|
69
|
-
if (data.results.length < 1) return result;
|
|
70
|
-
|
|
71
|
-
result.hasNextPage = page + 1 <= data.total_pages;
|
|
72
|
-
result.currentPage = page;
|
|
73
|
-
result.totalResults = data.total_results;
|
|
74
|
-
result.totalPages = data.total_pages;
|
|
75
|
-
|
|
76
|
-
result.results = data.results.map((result: any) => {
|
|
77
|
-
if (result.media_type !== 'person') {
|
|
78
|
-
const date = new Date(result?.release_date || result?.first_air_date);
|
|
79
|
-
|
|
80
|
-
const movie: IMovieResult = {
|
|
81
|
-
id: result.id,
|
|
82
|
-
title: result?.title || result?.name,
|
|
83
|
-
image: `https://image.tmdb.org/t/p/original${result?.poster_path}`,
|
|
84
|
-
type: result.media_type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
85
|
-
rating: result?.vote_average || 0,
|
|
86
|
-
releaseDate: `${date.getFullYear()}` || '0',
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
return movie;
|
|
90
|
-
} else {
|
|
91
|
-
const user: IPeopleResult = {
|
|
92
|
-
id: result.id,
|
|
93
|
-
name: result.name,
|
|
94
|
-
rating: result.popularity,
|
|
95
|
-
image: `https://image.tmdb.org/t/p/original${result?.profile_path}`,
|
|
96
|
-
movies: [],
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
user.movies = result.known_for.map((movie: any) => {
|
|
100
|
-
const date = new Date(movie?.release_date || movie?.first_air_date);
|
|
101
|
-
|
|
102
|
-
const xmovie: IMovieResult = {
|
|
103
|
-
id: movie.id,
|
|
104
|
-
title: movie?.title || movie?.name,
|
|
105
|
-
image: `https://image.tmdb.org/t/p/original${movie?.poster_path}`,
|
|
106
|
-
type: movie.media_type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
107
|
-
rating: movie?.vote_average || 0,
|
|
108
|
-
releaseDate: `${date.getFullYear()}` || '0',
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
return xmovie;
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
return user;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
return result;
|
|
119
|
-
} catch (err) {
|
|
120
|
-
throw new Error((err as Error).message);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @param query search query
|
|
126
|
-
* @param page page number
|
|
127
|
-
*/
|
|
128
|
-
override search = async (query: string, page: number = 1): Promise<ISearch<IMovieResult | IAnimeResult>> => {
|
|
129
|
-
const searchUrl = `${this.apiUrl}/search/multi?api_key=${this.apiKey}&language=en-US&page=${page}&include_adult=false&query=${query}`;
|
|
130
|
-
|
|
131
|
-
const search: ISearch<IMovieResult | IAnimeResult> = {
|
|
132
|
-
currentPage: page,
|
|
133
|
-
hasNextPage: false,
|
|
134
|
-
results: [],
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
try {
|
|
138
|
-
const { data } = await axios.get(searchUrl);
|
|
139
|
-
|
|
140
|
-
if (data.results.length < 1) return search;
|
|
141
|
-
|
|
142
|
-
search.hasNextPage = page + 1 <= data.total_pages;
|
|
143
|
-
search.currentPage = page;
|
|
144
|
-
search.totalResults = data.total_results;
|
|
145
|
-
search.totalPages = data.total_pages;
|
|
146
|
-
|
|
147
|
-
data.results.forEach((result: any) => {
|
|
148
|
-
const date = new Date(result?.release_date || result?.first_air_date);
|
|
149
|
-
|
|
150
|
-
const movie: IMovieResult = {
|
|
151
|
-
id: result.id,
|
|
152
|
-
title: result?.title || result?.name,
|
|
153
|
-
image: `https://image.tmdb.org/t/p/original${result?.poster_path}`,
|
|
154
|
-
type: result.media_type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
155
|
-
rating: result?.vote_average || 0,
|
|
156
|
-
releaseDate: `${date.getFullYear()}` || '0',
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
return search.results.push(movie);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
return search;
|
|
163
|
-
} catch (err) {
|
|
164
|
-
throw new Error((err as Error).message);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @param id media id (anime or movie/tv)
|
|
170
|
-
* @param type movie or tv
|
|
171
|
-
*/
|
|
172
|
-
override fetchMediaInfo = async (mediaId: string, type: string): Promise<IMovieInfo | IAnimeInfo> => {
|
|
173
|
-
type = type.toLowerCase() === 'movie' ? 'movie' : 'tv';
|
|
174
|
-
const infoUrl = `${this.apiUrl}/${type}/${mediaId}?api_key=${this.apiKey}&language=en-US&append_to_response=release_dates,watch/providers,alternative_titles,credits,external_ids,images,keywords,recommendations,reviews,similar,translations,videos&include_image_language=en`;
|
|
175
|
-
|
|
176
|
-
const info: IMovieInfo = {
|
|
177
|
-
id: mediaId,
|
|
178
|
-
title: '',
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
try {
|
|
182
|
-
//request api to get media info from tmdb
|
|
183
|
-
const { data } = await axios.get(infoUrl);
|
|
184
|
-
|
|
185
|
-
//get provider id from title and year (if available) to get the correct provider id for the movie/tv series (e.g. flixhq)
|
|
186
|
-
const providerId = await this.findIdFromTitle(data?.title || data?.name, {
|
|
187
|
-
type: type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
188
|
-
totalSeasons: data?.number_of_seasons,
|
|
189
|
-
totalEpisodes: data?.number_of_episodes,
|
|
190
|
-
year: new Date(data?.release_year || data?.first_air_date || data?.release_date).getFullYear(),
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
//fetch media info from provider
|
|
194
|
-
const InfoFromProvider = await this.provider.fetchMediaInfo(providerId as string);
|
|
195
|
-
|
|
196
|
-
info.id = providerId as string;
|
|
197
|
-
|
|
198
|
-
//check if the movie so episode id does not show on tv shows
|
|
199
|
-
if (type === 'movie') info.episodeId = InfoFromProvider?.episodes![0]?.id;
|
|
200
|
-
|
|
201
|
-
info.title = data?.title || data?.name;
|
|
202
|
-
|
|
203
|
-
//images
|
|
204
|
-
info.image = `https://image.tmdb.org/t/p/original${data?.poster_path}`;
|
|
205
|
-
info.cover = `https://image.tmdb.org/t/p/original${data?.backdrop_path}`;
|
|
206
|
-
|
|
207
|
-
info.type = type === 'movie' ? TvType.MOVIE : TvType.TVSERIES;
|
|
208
|
-
info.rating = data?.vote_average || 0;
|
|
209
|
-
info.releaseDate = data?.release_date || data?.first_air_date;
|
|
210
|
-
info.description = data?.overview;
|
|
211
|
-
info.genres = data?.genres.map((genre: { name: string }) => genre.name);
|
|
212
|
-
info.duration = data?.runtime || data?.episode_run_time[0];
|
|
213
|
-
info.totalEpisodes = data?.number_of_episodes;
|
|
214
|
-
info.totalSeasons = data?.number_of_seasons as number;
|
|
215
|
-
info.directors = data?.credits?.crew
|
|
216
|
-
.filter((crew: { job: string }) => crew.job === 'Director')
|
|
217
|
-
.map((crew: { name: string }) => crew.name);
|
|
218
|
-
info.writers = data?.credits?.crew
|
|
219
|
-
.filter((crew: { job: string }) => crew.job === 'Screenplay')
|
|
220
|
-
.map((crew: { name: string }) => crew.name);
|
|
221
|
-
info.actors = data?.credits?.cast.map((cast: { name: string }) => cast.name);
|
|
222
|
-
info.characters = data?.credits?.cast.map((cast: any) => ({
|
|
223
|
-
id: cast.id,
|
|
224
|
-
name: cast.name,
|
|
225
|
-
url: `https://www.themoviedb.org/person/${cast.id}`,
|
|
226
|
-
character: cast.character,
|
|
227
|
-
image: `https://image.tmdb.org/t/p/original${cast.profile_path}`,
|
|
228
|
-
}));
|
|
229
|
-
info.trailer = {
|
|
230
|
-
id: data?.videos?.results[0]?.key,
|
|
231
|
-
site: data?.videos?.results[0]?.site,
|
|
232
|
-
url: `https://www.youtube.com/watch?v=${data?.videos?.results[0]?.key}`,
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
info.mappings = {
|
|
236
|
-
imdb: data?.external_ids?.imdb_id || undefined,
|
|
237
|
-
tmdb: data?.id || undefined,
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
info.similar =
|
|
241
|
-
data?.similar?.results?.length <= 0
|
|
242
|
-
? undefined
|
|
243
|
-
: data?.similar?.results.map((result: any) => {
|
|
244
|
-
return {
|
|
245
|
-
id: result.id,
|
|
246
|
-
title: result.title || result.name,
|
|
247
|
-
image: `https://image.tmdb.org/t/p/original${result.poster_path}`,
|
|
248
|
-
type: type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
249
|
-
rating: result.vote_average || 0,
|
|
250
|
-
releaseDate: result.release_date || result.first_air_date,
|
|
251
|
-
};
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
info.recommendations =
|
|
255
|
-
data?.recommendations?.results?.length <= 0
|
|
256
|
-
? undefined
|
|
257
|
-
: data?.recommendations?.results.map((result: any) => {
|
|
258
|
-
return {
|
|
259
|
-
id: result.id,
|
|
260
|
-
title: result.title || result.name,
|
|
261
|
-
image: `https://image.tmdb.org/t/p/original${result.poster_path}`,
|
|
262
|
-
type: type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
263
|
-
rating: result.vote_average || 0,
|
|
264
|
-
releaseDate: result.release_date || result.first_air_date,
|
|
265
|
-
};
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
const totalSeasons = (info?.totalSeasons as number) || 0;
|
|
269
|
-
if (type === 'tv' && totalSeasons > 0) {
|
|
270
|
-
const seasonUrl = (season: string) => `${this.apiUrl}/tv/${mediaId}/season/${season}?api_key=${this.apiKey}`;
|
|
271
|
-
|
|
272
|
-
info.seasons = [];
|
|
273
|
-
const seasons = info.seasons as any[];
|
|
274
|
-
|
|
275
|
-
const providerEpisodes = InfoFromProvider?.episodes as any[];
|
|
276
|
-
|
|
277
|
-
if (providerEpisodes?.length < 1) return info;
|
|
278
|
-
|
|
279
|
-
info.nextAiringEpisode = data?.next_episode_to_air
|
|
280
|
-
? {
|
|
281
|
-
season: data.next_episode_to_air?.season_number || undefined,
|
|
282
|
-
episode: data.next_episode_to_air?.episode_number || undefined,
|
|
283
|
-
releaseDate: data.next_episode_to_air?.air_date || undefined,
|
|
284
|
-
title: data.next_episode_to_air?.name || undefined,
|
|
285
|
-
description: data.next_episode_to_air?.overview || undefined,
|
|
286
|
-
runtime: data.next_episode_to_air?.runtime || undefined,
|
|
287
|
-
}
|
|
288
|
-
: undefined;
|
|
289
|
-
|
|
290
|
-
for (let i = 1; i <= totalSeasons; i++) {
|
|
291
|
-
const { data: seasonData } = await axios.get(seasonUrl(i.toString()));
|
|
292
|
-
|
|
293
|
-
//find season in each episode (providerEpisodes)
|
|
294
|
-
const seasonEpisodes = providerEpisodes?.filter((episode) => episode.season === i);
|
|
295
|
-
const episodes =
|
|
296
|
-
seasonData?.episodes?.length <= 0
|
|
297
|
-
? undefined
|
|
298
|
-
: seasonData?.episodes.map((episode: any): IMovieEpisode => {
|
|
299
|
-
//find episode in each season (seasonEpisodes)
|
|
300
|
-
const episodeFromProvider = seasonEpisodes?.find((ep) => ep.number === episode.episode_number);
|
|
301
|
-
|
|
302
|
-
return {
|
|
303
|
-
id: episodeFromProvider?.id,
|
|
304
|
-
uniqueId: `${mediaId}-${type}-s${episode.season_number}-e${episode.episode_number}`,
|
|
305
|
-
title: episode.name,
|
|
306
|
-
episode: episode.episode_number,
|
|
307
|
-
season: episode.season_number,
|
|
308
|
-
releaseDate: episode.air_date,
|
|
309
|
-
description: episode.overview,
|
|
310
|
-
url: episodeFromProvider?.url || undefined,
|
|
311
|
-
image: !episode?.still_path
|
|
312
|
-
? undefined
|
|
313
|
-
: {
|
|
314
|
-
mobile: `https://image.tmdb.org/t/p/w300${episode.still_path}`,
|
|
315
|
-
hd: `https://image.tmdb.org/t/p/w780${episode.still_path}`,
|
|
316
|
-
},
|
|
317
|
-
};
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
seasons.push({
|
|
321
|
-
season: i,
|
|
322
|
-
image: !seasonData?.poster_path
|
|
323
|
-
? undefined
|
|
324
|
-
: {
|
|
325
|
-
mobile: `https://image.tmdb.org/t/p/w300${seasonData.poster_path}`,
|
|
326
|
-
hd: `https://image.tmdb.org/t/p/w780${seasonData.poster_path}`,
|
|
327
|
-
},
|
|
328
|
-
episodes,
|
|
329
|
-
isReleased: seasonData?.episodes[0]?.air_date > new Date().toISOString() ? false : true,
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
} else {
|
|
333
|
-
info.seasons = [];
|
|
334
|
-
info.seasons.push({
|
|
335
|
-
season: 1,
|
|
336
|
-
image: !data?.poster_path
|
|
337
|
-
? undefined
|
|
338
|
-
: {
|
|
339
|
-
mobile: `https://image.tmdb.org/t/p/w300${data.backdrop_path}`,
|
|
340
|
-
hd: `https://image.tmdb.org/t/p/w780${data.backdrop_path}`,
|
|
341
|
-
},
|
|
342
|
-
episodes: [
|
|
343
|
-
{
|
|
344
|
-
id: InfoFromProvider?.episodes![0]?.id!,
|
|
345
|
-
uniqueId: `${mediaId}-${type}-s1-e1`,
|
|
346
|
-
title: data.title || data.original_title,
|
|
347
|
-
episode: 1,
|
|
348
|
-
season: 1,
|
|
349
|
-
releaseDate: data.release_date,
|
|
350
|
-
description: data.overview,
|
|
351
|
-
url: InfoFromProvider?.episodes![0]?.url,
|
|
352
|
-
image: !data?.backdrop_path
|
|
353
|
-
? undefined
|
|
354
|
-
: {
|
|
355
|
-
mobile: `https://image.tmdb.org/t/p/w300${data.backdrop_path}`,
|
|
356
|
-
hd: `https://image.tmdb.org/t/p/w780${data.backdrop_path}`,
|
|
357
|
-
},
|
|
358
|
-
},
|
|
359
|
-
],
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
} catch (err) {
|
|
363
|
-
//console.log(err);
|
|
364
|
-
throw new Error((err as Error).message);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
return info;
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Find the id of a media from its title. and extra data. (year, totalSeasons, totalEpisodes)
|
|
372
|
-
* @param title
|
|
373
|
-
* @param extraData
|
|
374
|
-
* @returns id of the media
|
|
375
|
-
*/
|
|
376
|
-
private findIdFromTitle = async (
|
|
377
|
-
title: string,
|
|
378
|
-
extraData: {
|
|
379
|
-
type: TvType;
|
|
380
|
-
year?: number;
|
|
381
|
-
totalSeasons?: number;
|
|
382
|
-
totalEpisodes?: number;
|
|
383
|
-
[key: string]: any;
|
|
384
|
-
}
|
|
385
|
-
): Promise<string | undefined> => {
|
|
386
|
-
//clean title
|
|
387
|
-
title = title.replace(/[^a-zA-Z0-9 ]/g, '').toLowerCase();
|
|
388
|
-
|
|
389
|
-
const findMedia = (await this.provider.search(title)) as ISearch<IAnimeResult>;
|
|
390
|
-
if (findMedia.results.length === 0) return '';
|
|
391
|
-
|
|
392
|
-
// console.log(findMedia.results);
|
|
393
|
-
// console.log(extraData);
|
|
394
|
-
|
|
395
|
-
// Sort the retrieved info for more accurate results.
|
|
396
|
-
findMedia.results.sort((a, b) => {
|
|
397
|
-
const targetTitle = title;
|
|
398
|
-
|
|
399
|
-
let firstTitle: string;
|
|
400
|
-
let secondTitle: string;
|
|
401
|
-
|
|
402
|
-
if (typeof a.title === 'string') firstTitle = a?.title as string;
|
|
403
|
-
else firstTitle = (a?.title as string) ?? '';
|
|
404
|
-
|
|
405
|
-
if (typeof b.title === 'string') secondTitle = b.title as string;
|
|
406
|
-
else secondTitle = (b?.title as string) ?? '';
|
|
407
|
-
|
|
408
|
-
const firstRating = calculateStringSimilarity(targetTitle, firstTitle.toLowerCase());
|
|
409
|
-
const secondRating = calculateStringSimilarity(targetTitle, secondTitle.toLowerCase());
|
|
410
|
-
|
|
411
|
-
// Sort in descending order
|
|
412
|
-
return secondRating - firstRating;
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
//remove results that dont match the type
|
|
416
|
-
findMedia.results = findMedia.results.filter((result) => {
|
|
417
|
-
if (extraData.type === TvType.MOVIE) return (result.type as string) === TvType.MOVIE;
|
|
418
|
-
else if (extraData.type === TvType.TVSERIES) return (result.type as string) === TvType.TVSERIES;
|
|
419
|
-
else return result;
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
// if extraData contains a year, filter out the results that don't match the year
|
|
423
|
-
if (extraData && extraData.year) {
|
|
424
|
-
findMedia.results = findMedia.results.filter((result) => {
|
|
425
|
-
return String(result.releaseDate).split('-')[0]?.trim() === String(extraData.year).trim();
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// console.log({ test1: findMedia.results });
|
|
430
|
-
|
|
431
|
-
// Check if the result contains the total number of seasons and compare it to the extraData.
|
|
432
|
-
// Allow for a range of ±2 seasons and ensure that the seasons value is a number.
|
|
433
|
-
if (extraData && extraData.totalSeasons && extraData.type === TvType.TVSERIES) {
|
|
434
|
-
findMedia.results = findMedia.results.filter((result) => {
|
|
435
|
-
const totalSeasons = (result.seasons as number) || 0;
|
|
436
|
-
const extraDataSeasons = (extraData.totalSeasons as number) || 0;
|
|
437
|
-
return totalSeasons >= extraDataSeasons - 2 && totalSeasons <= extraDataSeasons + 2;
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// console.log(findMedia.results);
|
|
442
|
-
|
|
443
|
-
return findMedia?.results[0]?.id || undefined;
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* @param id media id (anime or movie/tv)
|
|
448
|
-
* @param args optional arguments
|
|
449
|
-
*/
|
|
450
|
-
override fetchEpisodeSources = async (id: string, ...args: any): Promise<ISource> => {
|
|
451
|
-
return this.provider.fetchEpisodeSources(id, ...args);
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* @param episodeId episode id
|
|
456
|
-
* @param args optional arguments
|
|
457
|
-
**/
|
|
458
|
-
override fetchEpisodeServers = async (episodeId: string, ...args: any): Promise<IEpisodeServer[]> => {
|
|
459
|
-
return this.provider.fetchEpisodeServers(episodeId, ...args);
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// (async () => {
|
|
464
|
-
// const tmdb = new TMDB();
|
|
465
|
-
// const search = await tmdb.search('the flash');
|
|
466
|
-
// const info = await tmdb.fetchMediaInfo(search.results[0].id, search.results![0].type as string);
|
|
467
|
-
// // console.log(info);
|
|
468
|
-
// })();
|
|
469
|
-
|
|
470
|
-
export default TMDB;
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import {
|
|
3
|
+
type ISearch,
|
|
4
|
+
type IAnimeInfo,
|
|
5
|
+
type IAnimeResult,
|
|
6
|
+
type ISource,
|
|
7
|
+
type IEpisodeServer,
|
|
8
|
+
MovieParser,
|
|
9
|
+
TvType,
|
|
10
|
+
type IMovieResult,
|
|
11
|
+
type IMovieInfo,
|
|
12
|
+
type ProxyConfig,
|
|
13
|
+
type IMovieEpisode,
|
|
14
|
+
} from '../../models';
|
|
15
|
+
import type { IPeopleResult } from '../../models/types';
|
|
16
|
+
import { calculateStringSimilarity } from '../../utils';
|
|
17
|
+
import type { AxiosAdapter } from 'axios';
|
|
18
|
+
import HiMovies from '../movies/himovies/himovies';
|
|
19
|
+
|
|
20
|
+
class TMDB extends MovieParser {
|
|
21
|
+
override readonly name = 'TMDB';
|
|
22
|
+
protected override baseUrl = 'https://www.themoviedb.org';
|
|
23
|
+
protected apiUrl = 'https://api.themoviedb.org/3';
|
|
24
|
+
protected override logo = 'https://pbs.twimg.com/profile_images/1243623122089041920/gVZIvphd_400x400.jpg';
|
|
25
|
+
protected override classPath = 'META.TMDB';
|
|
26
|
+
override supportedTypes = new Set([TvType.MOVIE, TvType.TVSERIES, TvType.ANIME]);
|
|
27
|
+
|
|
28
|
+
private provider: MovieParser;
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
private apiKey: string = '5201b54eb0968700e693a30576d7d4dc',
|
|
32
|
+
provider?: MovieParser,
|
|
33
|
+
proxyConfig?: ProxyConfig,
|
|
34
|
+
adapter?: AxiosAdapter
|
|
35
|
+
) {
|
|
36
|
+
super();
|
|
37
|
+
this.provider = provider || new HiMovies();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param type trending type: tv series, movie, people or all
|
|
42
|
+
* @param timePeriod trending time period day or week
|
|
43
|
+
* @param page page number
|
|
44
|
+
*/
|
|
45
|
+
fetchTrending = async (
|
|
46
|
+
type: string | 'all',
|
|
47
|
+
timePeriod: 'day' | 'week' = 'day',
|
|
48
|
+
page: number = 1
|
|
49
|
+
): Promise<ISearch<IMovieResult | IAnimeResult | IPeopleResult>> => {
|
|
50
|
+
const trendingUrl = `${this.apiUrl}/trending/${
|
|
51
|
+
type.toLowerCase() === TvType.MOVIE.toLowerCase()
|
|
52
|
+
? 'movie'
|
|
53
|
+
: type.toLowerCase() === TvType.TVSERIES.toLowerCase()
|
|
54
|
+
? 'tv'
|
|
55
|
+
: type.toLowerCase() === TvType.PEOPLE.toLowerCase()
|
|
56
|
+
? 'person'
|
|
57
|
+
: 'all'
|
|
58
|
+
}/${timePeriod}?page=${page}&api_key=${this.apiKey}&language=en-US`;
|
|
59
|
+
|
|
60
|
+
const result: ISearch<IMovieResult | IAnimeResult | IPeopleResult> = {
|
|
61
|
+
currentPage: page,
|
|
62
|
+
hasNextPage: false,
|
|
63
|
+
results: [],
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const { data } = await axios.get(trendingUrl);
|
|
68
|
+
|
|
69
|
+
if (data.results.length < 1) return result;
|
|
70
|
+
|
|
71
|
+
result.hasNextPage = page + 1 <= data.total_pages;
|
|
72
|
+
result.currentPage = page;
|
|
73
|
+
result.totalResults = data.total_results;
|
|
74
|
+
result.totalPages = data.total_pages;
|
|
75
|
+
|
|
76
|
+
result.results = data.results.map((result: any) => {
|
|
77
|
+
if (result.media_type !== 'person') {
|
|
78
|
+
const date = new Date(result?.release_date || result?.first_air_date);
|
|
79
|
+
|
|
80
|
+
const movie: IMovieResult = {
|
|
81
|
+
id: result.id,
|
|
82
|
+
title: result?.title || result?.name,
|
|
83
|
+
image: `https://image.tmdb.org/t/p/original${result?.poster_path}`,
|
|
84
|
+
type: result.media_type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
85
|
+
rating: result?.vote_average || 0,
|
|
86
|
+
releaseDate: `${date.getFullYear()}` || '0',
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return movie;
|
|
90
|
+
} else {
|
|
91
|
+
const user: IPeopleResult = {
|
|
92
|
+
id: result.id,
|
|
93
|
+
name: result.name,
|
|
94
|
+
rating: result.popularity,
|
|
95
|
+
image: `https://image.tmdb.org/t/p/original${result?.profile_path}`,
|
|
96
|
+
movies: [],
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
user.movies = result.known_for.map((movie: any) => {
|
|
100
|
+
const date = new Date(movie?.release_date || movie?.first_air_date);
|
|
101
|
+
|
|
102
|
+
const xmovie: IMovieResult = {
|
|
103
|
+
id: movie.id,
|
|
104
|
+
title: movie?.title || movie?.name,
|
|
105
|
+
image: `https://image.tmdb.org/t/p/original${movie?.poster_path}`,
|
|
106
|
+
type: movie.media_type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
107
|
+
rating: movie?.vote_average || 0,
|
|
108
|
+
releaseDate: `${date.getFullYear()}` || '0',
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return xmovie;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return user;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return result;
|
|
119
|
+
} catch (err) {
|
|
120
|
+
throw new Error((err as Error).message);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @param query search query
|
|
126
|
+
* @param page page number
|
|
127
|
+
*/
|
|
128
|
+
override search = async (query: string, page: number = 1): Promise<ISearch<IMovieResult | IAnimeResult>> => {
|
|
129
|
+
const searchUrl = `${this.apiUrl}/search/multi?api_key=${this.apiKey}&language=en-US&page=${page}&include_adult=false&query=${query}`;
|
|
130
|
+
|
|
131
|
+
const search: ISearch<IMovieResult | IAnimeResult> = {
|
|
132
|
+
currentPage: page,
|
|
133
|
+
hasNextPage: false,
|
|
134
|
+
results: [],
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
const { data } = await axios.get(searchUrl);
|
|
139
|
+
|
|
140
|
+
if (data.results.length < 1) return search;
|
|
141
|
+
|
|
142
|
+
search.hasNextPage = page + 1 <= data.total_pages;
|
|
143
|
+
search.currentPage = page;
|
|
144
|
+
search.totalResults = data.total_results;
|
|
145
|
+
search.totalPages = data.total_pages;
|
|
146
|
+
|
|
147
|
+
data.results.forEach((result: any) => {
|
|
148
|
+
const date = new Date(result?.release_date || result?.first_air_date);
|
|
149
|
+
|
|
150
|
+
const movie: IMovieResult = {
|
|
151
|
+
id: result.id,
|
|
152
|
+
title: result?.title || result?.name,
|
|
153
|
+
image: `https://image.tmdb.org/t/p/original${result?.poster_path}`,
|
|
154
|
+
type: result.media_type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
155
|
+
rating: result?.vote_average || 0,
|
|
156
|
+
releaseDate: `${date.getFullYear()}` || '0',
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return search.results.push(movie);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return search;
|
|
163
|
+
} catch (err) {
|
|
164
|
+
throw new Error((err as Error).message);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @param id media id (anime or movie/tv)
|
|
170
|
+
* @param type movie or tv
|
|
171
|
+
*/
|
|
172
|
+
override fetchMediaInfo = async (mediaId: string, type: string): Promise<IMovieInfo | IAnimeInfo> => {
|
|
173
|
+
type = type.toLowerCase() === 'movie' ? 'movie' : 'tv';
|
|
174
|
+
const infoUrl = `${this.apiUrl}/${type}/${mediaId}?api_key=${this.apiKey}&language=en-US&append_to_response=release_dates,watch/providers,alternative_titles,credits,external_ids,images,keywords,recommendations,reviews,similar,translations,videos&include_image_language=en`;
|
|
175
|
+
|
|
176
|
+
const info: IMovieInfo = {
|
|
177
|
+
id: mediaId,
|
|
178
|
+
title: '',
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
//request api to get media info from tmdb
|
|
183
|
+
const { data } = await axios.get(infoUrl);
|
|
184
|
+
|
|
185
|
+
//get provider id from title and year (if available) to get the correct provider id for the movie/tv series (e.g. flixhq)
|
|
186
|
+
const providerId = await this.findIdFromTitle(data?.title || data?.name, {
|
|
187
|
+
type: type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
188
|
+
totalSeasons: data?.number_of_seasons,
|
|
189
|
+
totalEpisodes: data?.number_of_episodes,
|
|
190
|
+
year: new Date(data?.release_year || data?.first_air_date || data?.release_date).getFullYear(),
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
//fetch media info from provider
|
|
194
|
+
const InfoFromProvider = await this.provider.fetchMediaInfo(providerId as string);
|
|
195
|
+
|
|
196
|
+
info.id = providerId as string;
|
|
197
|
+
|
|
198
|
+
//check if the movie so episode id does not show on tv shows
|
|
199
|
+
if (type === 'movie') info.episodeId = InfoFromProvider?.episodes![0]?.id;
|
|
200
|
+
|
|
201
|
+
info.title = data?.title || data?.name;
|
|
202
|
+
|
|
203
|
+
//images
|
|
204
|
+
info.image = `https://image.tmdb.org/t/p/original${data?.poster_path}`;
|
|
205
|
+
info.cover = `https://image.tmdb.org/t/p/original${data?.backdrop_path}`;
|
|
206
|
+
|
|
207
|
+
info.type = type === 'movie' ? TvType.MOVIE : TvType.TVSERIES;
|
|
208
|
+
info.rating = data?.vote_average || 0;
|
|
209
|
+
info.releaseDate = data?.release_date || data?.first_air_date;
|
|
210
|
+
info.description = data?.overview;
|
|
211
|
+
info.genres = data?.genres.map((genre: { name: string }) => genre.name);
|
|
212
|
+
info.duration = data?.runtime || data?.episode_run_time[0];
|
|
213
|
+
info.totalEpisodes = data?.number_of_episodes;
|
|
214
|
+
info.totalSeasons = data?.number_of_seasons as number;
|
|
215
|
+
info.directors = data?.credits?.crew
|
|
216
|
+
.filter((crew: { job: string }) => crew.job === 'Director')
|
|
217
|
+
.map((crew: { name: string }) => crew.name);
|
|
218
|
+
info.writers = data?.credits?.crew
|
|
219
|
+
.filter((crew: { job: string }) => crew.job === 'Screenplay')
|
|
220
|
+
.map((crew: { name: string }) => crew.name);
|
|
221
|
+
info.actors = data?.credits?.cast.map((cast: { name: string }) => cast.name);
|
|
222
|
+
info.characters = data?.credits?.cast.map((cast: any) => ({
|
|
223
|
+
id: cast.id,
|
|
224
|
+
name: cast.name,
|
|
225
|
+
url: `https://www.themoviedb.org/person/${cast.id}`,
|
|
226
|
+
character: cast.character,
|
|
227
|
+
image: `https://image.tmdb.org/t/p/original${cast.profile_path}`,
|
|
228
|
+
}));
|
|
229
|
+
info.trailer = {
|
|
230
|
+
id: data?.videos?.results[0]?.key,
|
|
231
|
+
site: data?.videos?.results[0]?.site,
|
|
232
|
+
url: `https://www.youtube.com/watch?v=${data?.videos?.results[0]?.key}`,
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
info.mappings = {
|
|
236
|
+
imdb: data?.external_ids?.imdb_id || undefined,
|
|
237
|
+
tmdb: data?.id || undefined,
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
info.similar =
|
|
241
|
+
data?.similar?.results?.length <= 0
|
|
242
|
+
? undefined
|
|
243
|
+
: data?.similar?.results.map((result: any) => {
|
|
244
|
+
return {
|
|
245
|
+
id: result.id,
|
|
246
|
+
title: result.title || result.name,
|
|
247
|
+
image: `https://image.tmdb.org/t/p/original${result.poster_path}`,
|
|
248
|
+
type: type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
249
|
+
rating: result.vote_average || 0,
|
|
250
|
+
releaseDate: result.release_date || result.first_air_date,
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
info.recommendations =
|
|
255
|
+
data?.recommendations?.results?.length <= 0
|
|
256
|
+
? undefined
|
|
257
|
+
: data?.recommendations?.results.map((result: any) => {
|
|
258
|
+
return {
|
|
259
|
+
id: result.id,
|
|
260
|
+
title: result.title || result.name,
|
|
261
|
+
image: `https://image.tmdb.org/t/p/original${result.poster_path}`,
|
|
262
|
+
type: type === 'movie' ? TvType.MOVIE : TvType.TVSERIES,
|
|
263
|
+
rating: result.vote_average || 0,
|
|
264
|
+
releaseDate: result.release_date || result.first_air_date,
|
|
265
|
+
};
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const totalSeasons = (info?.totalSeasons as number) || 0;
|
|
269
|
+
if (type === 'tv' && totalSeasons > 0) {
|
|
270
|
+
const seasonUrl = (season: string) => `${this.apiUrl}/tv/${mediaId}/season/${season}?api_key=${this.apiKey}`;
|
|
271
|
+
|
|
272
|
+
info.seasons = [];
|
|
273
|
+
const seasons = info.seasons as any[];
|
|
274
|
+
|
|
275
|
+
const providerEpisodes = InfoFromProvider?.episodes as any[];
|
|
276
|
+
|
|
277
|
+
if (providerEpisodes?.length < 1) return info;
|
|
278
|
+
|
|
279
|
+
info.nextAiringEpisode = data?.next_episode_to_air
|
|
280
|
+
? {
|
|
281
|
+
season: data.next_episode_to_air?.season_number || undefined,
|
|
282
|
+
episode: data.next_episode_to_air?.episode_number || undefined,
|
|
283
|
+
releaseDate: data.next_episode_to_air?.air_date || undefined,
|
|
284
|
+
title: data.next_episode_to_air?.name || undefined,
|
|
285
|
+
description: data.next_episode_to_air?.overview || undefined,
|
|
286
|
+
runtime: data.next_episode_to_air?.runtime || undefined,
|
|
287
|
+
}
|
|
288
|
+
: undefined;
|
|
289
|
+
|
|
290
|
+
for (let i = 1; i <= totalSeasons; i++) {
|
|
291
|
+
const { data: seasonData } = await axios.get(seasonUrl(i.toString()));
|
|
292
|
+
|
|
293
|
+
//find season in each episode (providerEpisodes)
|
|
294
|
+
const seasonEpisodes = providerEpisodes?.filter((episode) => episode.season === i);
|
|
295
|
+
const episodes =
|
|
296
|
+
seasonData?.episodes?.length <= 0
|
|
297
|
+
? undefined
|
|
298
|
+
: seasonData?.episodes.map((episode: any): IMovieEpisode => {
|
|
299
|
+
//find episode in each season (seasonEpisodes)
|
|
300
|
+
const episodeFromProvider = seasonEpisodes?.find((ep) => ep.number === episode.episode_number);
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
id: episodeFromProvider?.id,
|
|
304
|
+
uniqueId: `${mediaId}-${type}-s${episode.season_number}-e${episode.episode_number}`,
|
|
305
|
+
title: episode.name,
|
|
306
|
+
episode: episode.episode_number,
|
|
307
|
+
season: episode.season_number,
|
|
308
|
+
releaseDate: episode.air_date,
|
|
309
|
+
description: episode.overview,
|
|
310
|
+
url: episodeFromProvider?.url || undefined,
|
|
311
|
+
image: !episode?.still_path
|
|
312
|
+
? undefined
|
|
313
|
+
: {
|
|
314
|
+
mobile: `https://image.tmdb.org/t/p/w300${episode.still_path}`,
|
|
315
|
+
hd: `https://image.tmdb.org/t/p/w780${episode.still_path}`,
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
seasons.push({
|
|
321
|
+
season: i,
|
|
322
|
+
image: !seasonData?.poster_path
|
|
323
|
+
? undefined
|
|
324
|
+
: {
|
|
325
|
+
mobile: `https://image.tmdb.org/t/p/w300${seasonData.poster_path}`,
|
|
326
|
+
hd: `https://image.tmdb.org/t/p/w780${seasonData.poster_path}`,
|
|
327
|
+
},
|
|
328
|
+
episodes,
|
|
329
|
+
isReleased: seasonData?.episodes[0]?.air_date > new Date().toISOString() ? false : true,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
info.seasons = [];
|
|
334
|
+
info.seasons.push({
|
|
335
|
+
season: 1,
|
|
336
|
+
image: !data?.poster_path
|
|
337
|
+
? undefined
|
|
338
|
+
: {
|
|
339
|
+
mobile: `https://image.tmdb.org/t/p/w300${data.backdrop_path}`,
|
|
340
|
+
hd: `https://image.tmdb.org/t/p/w780${data.backdrop_path}`,
|
|
341
|
+
},
|
|
342
|
+
episodes: [
|
|
343
|
+
{
|
|
344
|
+
id: InfoFromProvider?.episodes![0]?.id!,
|
|
345
|
+
uniqueId: `${mediaId}-${type}-s1-e1`,
|
|
346
|
+
title: data.title || data.original_title,
|
|
347
|
+
episode: 1,
|
|
348
|
+
season: 1,
|
|
349
|
+
releaseDate: data.release_date,
|
|
350
|
+
description: data.overview,
|
|
351
|
+
url: InfoFromProvider?.episodes![0]?.url,
|
|
352
|
+
image: !data?.backdrop_path
|
|
353
|
+
? undefined
|
|
354
|
+
: {
|
|
355
|
+
mobile: `https://image.tmdb.org/t/p/w300${data.backdrop_path}`,
|
|
356
|
+
hd: `https://image.tmdb.org/t/p/w780${data.backdrop_path}`,
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
} catch (err) {
|
|
363
|
+
//console.log(err);
|
|
364
|
+
throw new Error((err as Error).message);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return info;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Find the id of a media from its title. and extra data. (year, totalSeasons, totalEpisodes)
|
|
372
|
+
* @param title
|
|
373
|
+
* @param extraData
|
|
374
|
+
* @returns id of the media
|
|
375
|
+
*/
|
|
376
|
+
private findIdFromTitle = async (
|
|
377
|
+
title: string,
|
|
378
|
+
extraData: {
|
|
379
|
+
type: TvType;
|
|
380
|
+
year?: number;
|
|
381
|
+
totalSeasons?: number;
|
|
382
|
+
totalEpisodes?: number;
|
|
383
|
+
[key: string]: any;
|
|
384
|
+
}
|
|
385
|
+
): Promise<string | undefined> => {
|
|
386
|
+
//clean title
|
|
387
|
+
title = title.replace(/[^a-zA-Z0-9 ]/g, '').toLowerCase();
|
|
388
|
+
|
|
389
|
+
const findMedia = (await this.provider.search(title)) as ISearch<IAnimeResult>;
|
|
390
|
+
if (findMedia.results.length === 0) return '';
|
|
391
|
+
|
|
392
|
+
// console.log(findMedia.results);
|
|
393
|
+
// console.log(extraData);
|
|
394
|
+
|
|
395
|
+
// Sort the retrieved info for more accurate results.
|
|
396
|
+
findMedia.results.sort((a, b) => {
|
|
397
|
+
const targetTitle = title;
|
|
398
|
+
|
|
399
|
+
let firstTitle: string;
|
|
400
|
+
let secondTitle: string;
|
|
401
|
+
|
|
402
|
+
if (typeof a.title === 'string') firstTitle = a?.title as string;
|
|
403
|
+
else firstTitle = (a?.title as string) ?? '';
|
|
404
|
+
|
|
405
|
+
if (typeof b.title === 'string') secondTitle = b.title as string;
|
|
406
|
+
else secondTitle = (b?.title as string) ?? '';
|
|
407
|
+
|
|
408
|
+
const firstRating = calculateStringSimilarity(targetTitle, firstTitle.toLowerCase());
|
|
409
|
+
const secondRating = calculateStringSimilarity(targetTitle, secondTitle.toLowerCase());
|
|
410
|
+
|
|
411
|
+
// Sort in descending order
|
|
412
|
+
return secondRating - firstRating;
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
//remove results that dont match the type
|
|
416
|
+
findMedia.results = findMedia.results.filter((result) => {
|
|
417
|
+
if (extraData.type === TvType.MOVIE) return (result.type as string) === TvType.MOVIE;
|
|
418
|
+
else if (extraData.type === TvType.TVSERIES) return (result.type as string) === TvType.TVSERIES;
|
|
419
|
+
else return result;
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
// if extraData contains a year, filter out the results that don't match the year
|
|
423
|
+
if (extraData && extraData.year) {
|
|
424
|
+
findMedia.results = findMedia.results.filter((result) => {
|
|
425
|
+
return String(result.releaseDate).split('-')[0]?.trim() === String(extraData.year).trim();
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// console.log({ test1: findMedia.results });
|
|
430
|
+
|
|
431
|
+
// Check if the result contains the total number of seasons and compare it to the extraData.
|
|
432
|
+
// Allow for a range of ±2 seasons and ensure that the seasons value is a number.
|
|
433
|
+
if (extraData && extraData.totalSeasons && extraData.type === TvType.TVSERIES) {
|
|
434
|
+
findMedia.results = findMedia.results.filter((result) => {
|
|
435
|
+
const totalSeasons = (result.seasons as number) || 0;
|
|
436
|
+
const extraDataSeasons = (extraData.totalSeasons as number) || 0;
|
|
437
|
+
return totalSeasons >= extraDataSeasons - 2 && totalSeasons <= extraDataSeasons + 2;
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// console.log(findMedia.results);
|
|
442
|
+
|
|
443
|
+
return findMedia?.results[0]?.id || undefined;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* @param id media id (anime or movie/tv)
|
|
448
|
+
* @param args optional arguments
|
|
449
|
+
*/
|
|
450
|
+
override fetchEpisodeSources = async (id: string, ...args: any): Promise<ISource> => {
|
|
451
|
+
return this.provider.fetchEpisodeSources(id, ...args);
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* @param episodeId episode id
|
|
456
|
+
* @param args optional arguments
|
|
457
|
+
**/
|
|
458
|
+
override fetchEpisodeServers = async (episodeId: string, ...args: any): Promise<IEpisodeServer[]> => {
|
|
459
|
+
return this.provider.fetchEpisodeServers(episodeId, ...args);
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// (async () => {
|
|
464
|
+
// const tmdb = new TMDB();
|
|
465
|
+
// const search = await tmdb.search('the flash');
|
|
466
|
+
// const info = await tmdb.fetchMediaInfo(search.results[0].id, search.results![0].type as string);
|
|
467
|
+
// // console.log(info);
|
|
468
|
+
// })();
|
|
469
|
+
|
|
470
|
+
export default TMDB;
|