-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from Praneeth-2602/master
Solves issue#289
- Loading branch information
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# YouTube Video Search | ||
|
||
This project is a simple website that allows users to search for YouTube videos. It utilizes the YouTube Data API to fetch and display search results. | ||
|
||
## Features | ||
|
||
- Search for YouTube videos by entering keywords | ||
- Display search results with video thumbnails, titles, and descriptions | ||
- Click on a video to watch it directly on YouTube | ||
|
||
## Installation | ||
|
||
1. Clone the repository: `git clone https://github.com/your-username/your-repo.git` | ||
2. Navigate to the project directory: `cd your-repo` | ||
3. Install dependencies: `npm install` | ||
|
||
## Usage | ||
|
||
1. Obtain a YouTube Data API key from the [Google Developers Console](https://console.developers.google.com/) | ||
2. Modify the `script.js` file and replace `YOUR_API_KEY` with your actual API key. | ||
3. Run the html file. | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! If you have any suggestions or improvements, please create a pull request. | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT License](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>YouTube Video Search</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>YouTube Video Search</h1> | ||
<input type="text" id="search-input" placeholder="Search for videos..."> | ||
<button id="search-button">Search</button> | ||
<div id="video-results"></div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
document.getElementById('search-button').addEventListener('click', function() { | ||
const query = document.getElementById('search-input').value; | ||
searchYouTube(query); | ||
}); | ||
|
||
function searchYouTube(query) { | ||
const apiKey = 'YOUR_API_KEY'; | ||
const url = `https://www.googleapis.com/youtube/v3/search?part=snippet&q=${encodeURIComponent(query)}&key=${apiKey}&maxResults=10&type=video`; | ||
|
||
fetch(url) | ||
.then(response => response.json()) | ||
.then(data => { | ||
const videoResults = document.getElementById('video-results'); | ||
videoResults.innerHTML = ''; | ||
|
||
data.items.forEach(item => { | ||
// Check if video is unavailable | ||
if (item.snippet.title === 'Private video' || item.snippet.title === 'Deleted video') { | ||
return; // Skip this video | ||
} | ||
|
||
const videoId = item.id.videoId; | ||
const videoTitle = item.snippet.title; | ||
|
||
const videoItem = document.createElement('div'); | ||
videoItem.classList.add('video-item'); | ||
|
||
const videoTitleLink = document.createElement('a'); | ||
videoTitleLink.href = `https://www.youtube.com/watch?v=${videoId}`; | ||
videoTitleLink.target = '_blank'; | ||
videoTitleLink.textContent = videoTitle; | ||
videoTitleLink.classList.add('video-title'); | ||
|
||
const videoFrame = document.createElement('iframe'); | ||
videoFrame.src = `https://www.youtube.com/embed/${videoId}`; | ||
videoFrame.width = '100%'; | ||
videoFrame.height = '360'; | ||
videoFrame.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture'; | ||
videoFrame.allowFullscreen = true; | ||
|
||
videoItem.appendChild(videoTitleLink); | ||
videoItem.appendChild(videoFrame); | ||
videoResults.appendChild(videoItem); | ||
}); | ||
}) | ||
.catch(error => console.error('Error fetching YouTube API:', error)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f4; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.container { | ||
width: 80%; | ||
margin: 50px auto; | ||
text-align: center; | ||
} | ||
|
||
#search-input { | ||
width: 60%; | ||
padding: 10px; | ||
font-size: 16px; | ||
} | ||
|
||
#search-button { | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
} | ||
|
||
#video-results { | ||
margin-top: 20px; | ||
display: grid; | ||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); | ||
grid-gap: 20px; | ||
} | ||
|
||
.video-item { | ||
background: #fff; | ||
padding: 20px; | ||
border-radius: 5px; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); | ||
margin-bottom: 20px; | ||
} | ||
|
||
.video-title { | ||
font-size: 18px; | ||
color: #333; | ||
text-decoration: none; | ||
} |