بواسطة morbah |
لم تفهم نقطة معينة؟
اسأل المساعد الذكي وسيجيبك بناءً على محتوى هذا المقال.
<!-- تم تحديث الكود لدعم جلب الفيديوهات أيضًا -->
<!--DOCTYPE html-->
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>أداة إنشاء سكريبت فيديو</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
padding: 20px;
}
.container {
width: 100%;
max-width: 800px;
background-color: white;
border-radius: 10px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
padding: 20px;
box-sizing: border-box;
}
h1 {
text-align: center;
color: #333;
}
label {
display: block;
margin-top: 10px;
font-weight: bold;
}
input[type="text"],
select,
textarea {
width: 100%;
padding: 10px;
margin-top: 5px;
border: 1px solid #ddd;
border-radius: 5px;
box-sizing: border-box;
font-size: 16px;
}
button {
padding: 10px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
font-size: 16px;
}
.media-container img, .media-container iframe {
max-width: 100%;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>أداة إنشاء سكريبت فيديو</h1>
<label for="topic">موضوع الفيديو:</label>
<input type="text" id="topic" placeholder="مثال: الأهرامات المصرية">
<label for="imageCount">عدد الصور:</label>
<input type="number" id="imageCount" min="0" max="10" value="3">
<label for="videoCount">عدد الفيديوهات:</label>
<input type="number" id="videoCount" min="0" max="5" value="2">
<button id="fetchMedia">جلب الصور والفيديوهات</button>
<div class="media-container" id="media-container"></div>
</div>
<script>
const apiKey = "AIzaSyCkBBS3wY4FMHzxHF7JtSNinnLVaiajyvQ";
const searchEngineId = "c38b4d508010b4414";
const fetchMediaButton = document.getElementById("fetchMedia");
const topicInput = document.getElementById("topic");
const imageCountInput = document.getElementById("imageCount");
const videoCountInput = document.getElementById("videoCount");
const mediaContainer = document.getElementById("media-container");
async function fetchMedia(query, imageCount, videoCount) {
mediaContainer.innerHTML = "جارِ التحميل...";
const url = `https://www.googleapis.com/customsearch/v1?q=${query}&cx=${searchEngineId}&key=${apiKey}&searchType=image&num=${imageCount}`;
const videoUrl = `https://www.googleapis.com/customsearch/v1?q=${query}+video&cx=${searchEngineId}&key=${apiKey}&num=${videoCount}`;
try {
const imageResponse = await fetch(url);
const imageData = await imageResponse.json();
const videoResponse = await fetch(videoUrl);
const videoData = await videoResponse.json();
mediaContainer.innerHTML = "";
if (imageData.items) {
imageData.items.forEach(item => {
const img = document.createElement("img");
img.src = item.link;
mediaContainer.appendChild(img);
});
}
if (videoData.items) {
videoData.items.forEach(item => {
if (item.link.includes("youtube.com/watch")) {
const iframe = document.createElement("iframe");
iframe.src = item.link.replace("watch?v=", "embed/");
iframe.width = "100%";
iframe.height = "315";
mediaContainer.appendChild(iframe);
}
});
}
} catch (error) {
console.error("حدث خطأ أثناء جلب الصور والفيديوهات", error);
mediaContainer.innerHTML = "حدث خطأ. حاول مرة أخرى.";
}
}
fetchMediaButton.addEventListener("click", () => {
const query = topicInput.value;
const imageCount = imageCountInput.value;
const videoCount = videoCountInput.value;
if (!query) {
alert("الرجاء إدخال موضوع البحث");
return;
}
fetchMedia(query, imageCount, videoCount);
});
</script>
</body>
</html>
الكاتب : morbah
انا مهتم بمجال التقنية والربح من الانترنت واتطلع لنشر المزيد من المقالات التي تفيدكم
تعليقات
إرسال تعليق