instance2 / templates /index.html
ChandimaPrabath's picture
patch
4e15391
raw
history blame
4.79 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Media Library</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #141414;
color: #fff;
margin: 0;
padding: 0;
}
.header {
background-color: #000;
padding: 20px;
text-align: center;
}
.header h1 {
margin: 0;
font-size: 24px;
}
.content {
padding: 20px;
}
.section {
margin-bottom: 40px;
}
.section h2 {
margin-bottom: 20px;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 20px;
}
.card {
background-color: #333;
border-radius: 10px;
overflow: hidden;
text-align: center;
transition: transform 0.2s;
}
.card:hover {
transform: scale(1.05);
}
.card img {
width: 100%;
height: 300px;
object-fit: cover;
}
.card h3 {
margin: 0;
padding: 10px;
font-size: 18px;
}
.card p {
margin: 0;
padding: 10px;
}
.card a {
display: block;
padding: 10px;
color: #fff;
background-color: #e50914;
text-decoration: none;
border-radius: 0 0 10px 10px;
}
.card a:hover {
background-color: #f40612;
}
</style>
</head>
<body>
<div class="header">
<h1>Media Library</h1>
</div>
<div class="content">
<div class="section" id="films">
<h2>Films</h2>
<div class="grid" id="films-grid">
<!-- Film cards will be inserted here -->
</div>
</div>
<div class="section" id="tv">
<h2>TV Shows</h2>
<div class="grid" id="tv-grid">
<!-- TV show cards will be inserted here -->
</div>
</div>
</div>
<script>
async function fetchData(endpoint) {
try {
const response = await fetch(endpoint);
if (!response.ok) {
throw new Error('Network response was not ok');
}
return await response.json();
} catch (error) {
console.error('Fetch error:', error);
return [];
}
}
async function fetchImage(title) {
try {
const response = await fetch(`/get_image?title=${encodeURIComponent(title)}`);
if (response.ok) {
return response.url;
} else {
console.error('Image fetch error:', response.statusText);
return `https://via.placeholder.com/200x300?text=${title}`;
}
} catch (error) {
console.error('Image fetch error:', error);
return `https://via.placeholder.com/200x300?text=${title}`;
}
}
async function createCard(item) {
const card = document.createElement('div');
card.className = 'card';
const title = item.path.split('/').pop();
const img = document.createElement('img');
img.src = await fetchImage(title);
card.appendChild(img);
const titleElement = document.createElement('h3');
titleElement.textContent = title;
card.appendChild(titleElement);
if (item.contents) {
const p = document.createElement('p');
p.textContent = `Contains ${item.contents.length} items`;
card.appendChild(p);
} else {
const link = document.createElement('a');
link.href = `/play/${encodeURIComponent(item.path)}`;
link.textContent = 'Play';
card.appendChild(link);
}
return card;
}
async function loadSection(endpoint, containerId) {
const data = await fetchData(endpoint);
const container = document.getElementById(containerId);
container.innerHTML = ''; // Clear previous content
for (const item of data) {
container.appendChild(await createCard(item));
}
}
document.addEventListener('DOMContentLoaded', () => {
loadSection('/films', 'films-grid');
loadSection('/tv', 'tv-grid');
});
</script>