instance1 / templates /index.html
ChandimaPrabath's picture
init player
f0de3f7
raw
history blame
4.19 kB
<!DOCTYPE html>
<html>
<head>
<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"></div>
</div>
<div class="section" id="tv">
<h2>TV Shows</h2>
<div class="grid" id="tv-grid"></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 fetchMetadata(title) {
try {
const response = await fetch(`/get_metadata?title=${encodeURIComponent(title)}`);
if (response.ok) {
const data = await response.json();
if (data.data && data.data.length > 0) {
const thumbnailUrl = data.data[0].thumbnail;
return thumbnailUrl;
}
}
} catch (error) {
console.error('Metadata fetch error:', error);
}
return null;
}
function createCard(item, mediaType) {
const card = document.createElement('div');
card.className = 'card';
const title = item.path.split('/').pop();
card.innerHTML = `
<img src="https://via.placeholder.com/340x500.png" alt="${title}">
<h3>${title}</h3>
<a href="/player?path=${encodeURIComponent(item.path)}&type=${mediaType}">Play</a>
`;
fetchMetadata(title).then(thumbnailUrl => {
if (thumbnailUrl !== null) {
card.querySelector('img').src = thumbnailUrl;
}
});
return card;
}
async function populateGrid(endpoint, gridId, mediaType) {
const grid = document.getElementById(gridId);
const data = await fetchData(endpoint);
data.forEach(item => {
grid.appendChild(createCard(item, mediaType));
});
}
populateGrid('/films', 'films-grid', 'movie');
populateGrid('/tv', 'tv-grid', 'series');
</script>
</body>
</html>