Files
ytdlp-site/templates/video.html
2024-09-20 05:33:32 -06:00

130 lines
3.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.original.Title}}</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
box-sizing: border-box;
}
h1 {
text-align: center;
}
.video-container {
max-width: 600px;
margin: 0 auto;
}
video {
width: 100%;
max-width: 600px;
display: block;
margin: 0 auto;
}
@media (max-width: 600px) {
.video-container {
max-width: 100%;
}
video {
max-width: 100%;
}
}
</style>
</head>
<body>
<h1>{{.original.Title}}</h1>
{{range .videos}}
<h2>{{.Source}} {{.Width}} x {{.Height}} @ {{.FPS}}</h2>
<div class="video-container">
<video controls playsinline preload="none">
<source src="/temp/{{.Token}}" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
<div class="video-download">
<a href="/data/{{.Filename}}" download="{{.DownloadFilename}}">Download ({{.Size}}, {{.StreamRate}})</a>
</div>
{{end}}
{{range .audios}}
<h2>{{.Kbps}}</h2>
<div class="audio-container">
<audio controls playsinline preload="none">
<source src="/temp/{{.Token}}">
Your browser does not support the audio tag.
</audio>
</div>
<div class="audio-download">
<a href="/data/{{.Filename}}" download="{{.DownloadFilename}}">Download ({{.Size}}, {{.StreamRate}})</a>
</div>
{{end}}
<div class="footer">
<div class="build-id">
Build ID: <a href="https://github.com/cwpearson/ytdlp-site/compare/{{.build_id}}..master">{{.build_id}}</a>
</div>
</div>
<script>
// Get all video and audio elements
const mediaElements = document.querySelectorAll('video, audio');
// Generate a unique key for this page
const pageKey = `mediaProgress_${window.location.pathname}`;
// Function to save the current time of the most recently played media
function saveMediaProgress(media) {
const currentProgress = parseFloat(localStorage.getItem(pageKey)) || 0;
if (media.currentTime > currentProgress) {
localStorage.setItem(pageKey, media.currentTime);
}
}
// Function to load and set the saved time for all media elements
function loadMediaProgress() {
const savedTime = localStorage.getItem(pageKey);
if (savedTime) {
mediaElements.forEach(media => {
media.currentTime = Math.min(parseFloat(savedTime), media.duration || Infinity);
});
}
}
// Set up event listeners for each media element
mediaElements.forEach(media => {
// Save progress when the media is playing
media.addEventListener('timeupdate', () => {
if (!media.paused) {
saveMediaProgress(media);
}
});
// Also save when the media is paused
media.addEventListener('pause', () => saveMediaProgress(media));
// Load the saved progress when the media is ready
media.addEventListener('loadedmetadata', loadMediaProgress);
// Clear progress when any media ends
media.addEventListener('ended', () => {
localStorage.removeItem(pageKey);
});
});
</script>
</body>
</html>