-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
58 lines (46 loc) · 1.7 KB
/
Copy pathindex.php
File metadata and controls
58 lines (46 loc) · 1.7 KB
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
<?php
function getYouTubeVideos($apiKey, $searchQuery, $numVideos) {
$url = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults={$numVideos}&q=" . urlencode($searchQuery) . "&key=" . $apiKey;
$response = file_get_contents($url);
$responseData = json_decode($response, true);
$videoIds = [];
if (!empty($responseData['items'])) {
foreach ($responseData['items'] as $item) {
$videoId = $item['id']['videoId'];
$videoIds[] = $videoId;
}
}
return $videoIds;
}
$apiKey = file_get_contents("keyApiYoutube.txt");
$searchQuery = '';
$numVideos = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$searchQuery = $_POST['searchQuery'];
$numVideos = $_POST['numVideos'];
$videoIds = getYouTubeVideos($apiKey, $searchQuery, $numVideos);
if (!empty($videoIds)) {
$videoIdsString = implode("\n", $videoIds);
file_put_contents('ids.txt', $videoIdsString);
echo "Идентификаторы видео сохранены в файле ids.txt";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Поиск видео на YouTube</title>
</head>
<body>
<h1>Поиск видео на YouTube</h1>
<form method="POST" action="index.php">
<label for="searchQuery">Запрос:</label>
<input type="text" name="searchQuery" id="searchQuery" value="<?php echo $searchQuery; ?>" required>
<br>
<label for="numVideos">Количество видео:</label>
<input type="number" name="numVideos" id="numVideos" min="1" max="10" value="<?php echo $numVideos; ?>" required>
<br>
<input type="submit" value="Отправить">
</form>
</body>
</html>