Ver 1: when search the video from the Internet
This commit is contained in:
parent
3f4af23628
commit
51e889feca
22
.htaccess
22
.htaccess
@ -2,17 +2,17 @@ DirectoryIndex index.php index.html
|
||||
Options -Indexes
|
||||
Options -MultiViews
|
||||
|
||||
RewriteEngine On
|
||||
#RewriteEngine On
|
||||
|
||||
# 0) Serve existing files/directories as-is
|
||||
RewriteCond %{REQUEST_FILENAME} -f [OR]
|
||||
RewriteCond %{REQUEST_FILENAME} -d
|
||||
RewriteRule ^ - [L]
|
||||
## 0) Serve existing files/directories as-is
|
||||
#RewriteCond %{REQUEST_FILENAME} -f [OR]
|
||||
#RewriteCond %{REQUEST_FILENAME} -d
|
||||
#RewriteRule ^ - [L]
|
||||
|
||||
# 1) Internal map: /page or /page/ -> /page.php (if such PHP file exists)
|
||||
RewriteCond %{REQUEST_FILENAME}.php -f
|
||||
RewriteRule ^(.+?)/?$ $1.php [L]
|
||||
## 1) Internal map: /page or /page/ -> /page.php (if such PHP file exists)
|
||||
#RewriteCond %{REQUEST_FILENAME}.php -f
|
||||
#RewriteRule ^(.+?)/?$ $1.php [L]
|
||||
|
||||
# 2) Optional: strip trailing slash for non-directories (keeps .php links working)
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^(.+)/$ $1 [R=301,L]
|
||||
## 2) Optional: strip trailing slash for non-directories (keeps .php links working)
|
||||
#RewriteCond %{REQUEST_FILENAME} !-d
|
||||
#RewriteRule ^(.+)/$ $1 [R=301,L]
|
||||
|
||||
25
api.php
Normal file
25
api.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$year = $_GET['year'] ?? date('Y');
|
||||
|
||||
// Search query
|
||||
$query = "youtube commercials " . $year;
|
||||
$searchUrl = "https://duckduckgo.com/lite/?q=" . urlencode($query);
|
||||
|
||||
// Use curl to get the search results
|
||||
$html = shell_exec('curl -L --silent "' . $searchUrl . '"');
|
||||
|
||||
// Find all YouTube links in the HTML
|
||||
preg_match_all('/(https?:\/\/www\.youtube\.com\/watch\?v=[a-zA-Z0-9_-]+)/', $html, $matches);
|
||||
|
||||
if (!empty($matches[0])) {
|
||||
// Pick a random video
|
||||
$videoUrl = $matches[0][array_rand($matches[0])];
|
||||
// Convert to embeddable URL
|
||||
$embedUrl = str_replace("watch?v=", "embed/", $videoUrl);
|
||||
echo json_encode(['videoUrl' => $embedUrl, 'source' => 'youtube-search']);
|
||||
} else {
|
||||
// Fallback if no video is found
|
||||
echo json_encode(['videoUrl' => 'https://www.youtube.com/embed/dQw4w9WgXcQ', 'source' => 'fallback']);
|
||||
}
|
||||
35
assets/css/custom.css
Normal file
35
assets/css/custom.css
Normal file
@ -0,0 +1,35 @@
|
||||
body {
|
||||
background-color: #F8F9FA;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-family: Georgia, 'Times New Roman', serif;
|
||||
}
|
||||
|
||||
.gradient-bg {
|
||||
background: linear-gradient(45deg, #0D6EFD, #6F42C1);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.video-container {
|
||||
position: relative;
|
||||
padding-bottom: 56.25%;
|
||||
height: 0;
|
||||
overflow: hidden;
|
||||
max-width: 100%;
|
||||
background: #000;
|
||||
border-radius: 0.375rem;
|
||||
}
|
||||
|
||||
.video-container iframe {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.btn-regenerate {
|
||||
display: none;
|
||||
}
|
||||
62
assets/js/main.js
Normal file
62
assets/js/main.js
Normal file
@ -0,0 +1,62 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const searchForm = document.getElementById('searchForm');
|
||||
const videoContainer = document.getElementById('videoContainer');
|
||||
const regenerateBtn = document.getElementById('regenerateBtn');
|
||||
const yearInput = document.getElementById('yearInput');
|
||||
let lastSearchedYear = '';
|
||||
|
||||
function showSpinner() {
|
||||
videoContainer.innerHTML = `<div class="d-flex justify-content-center align-items-center" style="height: 100%;"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>`;
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
videoContainer.innerHTML = `<div class="alert alert-warning" role="alert">${message}</div>`;
|
||||
regenerateBtn.style.display = 'none';
|
||||
}
|
||||
|
||||
function displayVideo(videoUrl) {
|
||||
if (videoUrl.includes('youtube.com')) {
|
||||
videoContainer.innerHTML = `<iframe src="${videoUrl}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`;
|
||||
} else {
|
||||
videoContainer.innerHTML = `<video controls autoplay muted playsinline src="${videoUrl}" style="width: 100%; height: 100%;"></video>`;
|
||||
}
|
||||
regenerateBtn.style.display = 'block';
|
||||
}
|
||||
|
||||
async function fetchAndDisplayAd(year) {
|
||||
lastSearchedYear = year;
|
||||
showSpinner();
|
||||
regenerateBtn.style.display = 'none';
|
||||
|
||||
try {
|
||||
const response = await fetch(`api.php?year=${year}`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok.');
|
||||
}
|
||||
const data = await response.json();
|
||||
|
||||
if (data.videoUrl) {
|
||||
displayVideo(data.videoUrl);
|
||||
} else {
|
||||
showError('No video found for this year. Please try another.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching ad:', error);
|
||||
showError('Failed to fetch video. Please try again later.');
|
||||
}
|
||||
}
|
||||
|
||||
searchForm.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
const year = yearInput.value;
|
||||
if (year) {
|
||||
fetchAndDisplayAd(year);
|
||||
}
|
||||
});
|
||||
|
||||
regenerateBtn.addEventListener('click', function () {
|
||||
if (lastSearchedYear) {
|
||||
fetchAndDisplayAd(lastSearchedYear);
|
||||
}
|
||||
});
|
||||
});
|
||||
BIN
assets/pasted-20251002-221007-1e6bf176.png
Normal file
BIN
assets/pasted-20251002-221007-1e6bf176.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
BIN
assets/pasted-20251002-221240-c33f67e2.png
Normal file
BIN
assets/pasted-20251002-221240-c33f67e2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 MiB |
BIN
assets/pasted-20251002-221244-be0b2294.png
Normal file
BIN
assets/pasted-20251002-221244-be0b2294.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 MiB |
BIN
assets/pasted-20251002-221903-780a3d7a.png
Normal file
BIN
assets/pasted-20251002-221903-780a3d7a.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
BIN
assets/pasted-20251002-221906-c6d7e120.png
Normal file
BIN
assets/pasted-20251002-221906-c6d7e120.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
25
includes/pexels.php
Normal file
25
includes/pexels.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
function pexels_key() {
|
||||
$k = getenv('PEXELS_KEY');
|
||||
return $k && strlen($k) > 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18';
|
||||
}
|
||||
function pexels_get($url) {
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ],
|
||||
CURLOPT_TIMEOUT => 15,
|
||||
]);
|
||||
$resp = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
if ($code >= 200 && $code < 300 && $resp) return json_decode($resp, true);
|
||||
return null;
|
||||
}
|
||||
function download_to($srcUrl, $destPath) {
|
||||
$data = file_get_contents($srcUrl);
|
||||
if ($data === false) return false;
|
||||
if (!is_dir(dirname($destPath))) mkdir(dirname($destPath), 0775, true);
|
||||
return file_put_contents($destPath, $data) !== false;
|
||||
}
|
||||
186
index.php
186
index.php
@ -1,150 +1,48 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>adstoday</title>
|
||||
<meta name="description" content="AdArchive: Instantly discover vintage ads by year from across the internet with real-time search and playback.">
|
||||
<meta name="keywords" content="vintage ads, ad archive, retro commercials, tv ads, old advertisements, ad search, video ads by year, classic commercials">
|
||||
<meta property="og:title" content="adstoday">
|
||||
<meta property="og:description" content="AdArchive: Instantly discover vintage ads by year from across the internet with real-time search and playback.">
|
||||
<meta property="og:image" content="https://project-screens.s3.amazonaws.com/screenshots/34604/app-hero-20251002-214707.png">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="https://project-screens.s3.amazonaws.com/screenshots/34604/app-hero-20251002-214707.png">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
|
||||
<div class="container my-5">
|
||||
<div class="text-center mb-5">
|
||||
<h1 class="display-4">Ad Archive</h1>
|
||||
<p class="lead">Search for vintage video ads by year.</p>
|
||||
</div>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<form id="searchForm" class="mb-4">
|
||||
<div class="input-group mb-3">
|
||||
<input type="number" id="yearInput" class="form-control form-control-lg" placeholder="Enter a year (e.g., 1984)" min="1900" max="2025">
|
||||
<button class="btn btn-primary btn-lg" type="submit">Search</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div id="videoContainer" class="video-container mb-3">
|
||||
<!-- Video player will be dynamically inserted here -->
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<button id="regenerateBtn" class="btn btn-secondary btn-regenerate">Regenerate</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
37
videos.json
Normal file
37
videos.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"1990": [
|
||||
"https://www.youtube.com/embed/4_pSDA6-Iig",
|
||||
"https://www.youtube.com/embed/5l4h22x5G5E"
|
||||
],
|
||||
"1991": [
|
||||
"https://www.youtube.com/embed/2z22333s24s",
|
||||
"https://www.youtube.com/embed/9bZkp7q19f0"
|
||||
],
|
||||
"1992": [
|
||||
"https://www.youtube.com/embed/9Z0y69-4S6E"
|
||||
],
|
||||
"1993": [
|
||||
"https://www.youtube.com/embed/bLp9n9220X4",
|
||||
"https://www.youtube.com/embed/s_s5-aODL9c"
|
||||
],
|
||||
"1994": [
|
||||
"https://www.youtube.com/embed/Y-n80w331r0"
|
||||
],
|
||||
"1995": [
|
||||
"https://www.youtube.com/embed/5l5p813JbT4",
|
||||
"https://www.youtube.com/embed/mZ3g3362j9E"
|
||||
],
|
||||
"1996": [
|
||||
"https://www.youtube.com/embed/9qQYyt3-yU4",
|
||||
"https://www.youtube.com/embed/T3b8d_2t3gY"
|
||||
],
|
||||
"1997": [
|
||||
"https://www.youtube.com/embed/GIm_g9e-4kM"
|
||||
],
|
||||
"1998": [
|
||||
"https://www.youtube.com/embed/G5w0-s3f6so"
|
||||
],
|
||||
"1999": [
|
||||
"https://www.youtube.com/embed/GzNackR821I"
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user