-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
63 lines (52 loc) · 2.29 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
$tmdbApiKey = '1154c19df6e9cd079d723182248a57c3';
$movieDescription = urlencode($_GET['filmInput']);
$apiUrl = "https://api.themoviedb.org/3/search/movie?api_key={$tmdbApiKey}&query={$movieDescription}&language=ru-RU";
$response = file_get_contents($apiUrl);
$movieData = json_decode($response, true);
if (!$movieData || !isset($movieData['results'][0])) {
$result = array(
'title' => 'Фильм не найден',
'year' => '',
'director' => 'Информация отсутствует',
'imdbLink' => '',
'poster' => '',
'synopsis' => '',
'exFsLink' => '',
'rezkaLink' => '',
'kinopoiskLink' => '',
);
} else {
$firstResult = $movieData['results'][0];
// Получаем информацию о режиссере
$director = getDirector($firstResult['id']);
$result = array(
'title' => $firstResult['title'],
'year' => $firstResult['release_date'] ? date('Y', strtotime($firstResult['release_date'])) : '',
'director' => $director,
'imdbLink' => $firstResult['external_ids']['imdb_id'] ? "https://www.imdb.com/title/{$firstResult['external_ids']['imdb_id']}" : '',
'poster' => $firstResult['poster_path'] ? "https://image.tmdb.org/t/p/w500{$firstResult['poster_path']}" : '',
'synopsis' => $firstResult['overview'],
'exFsLink' => '',
'rezkaLink' => '',
'kinopoiskLink' => '', // Требуется дополнительная информация о фильме
);
}
header('Content-Type: application/json');
echo json_encode($result);
// Функция для получения информации о режиссере
function getDirector($movieId) {
global $tmdbApiKey;
$creditsApiUrl = "https://api.themoviedb.org/3/movie/{$movieId}/credits?api_key={$tmdbApiKey}";
$creditsResponse = file_get_contents($creditsApiUrl);
$creditsData = json_decode($creditsResponse, true);
if (isset($creditsData['crew'])) {
foreach ($creditsData['crew'] as $crewMember) {
if ($crewMember['job'] === 'Director') {
return $crewMember['name'];
}
}
}
return 'Информация отсутствует';
}
?>