Added video player and associated routes for archived videos from YouTube

This commit is contained in:
David Ball 2024-04-15 04:25:33 -04:00
parent e352bedfd9
commit 98008527db
3 changed files with 97 additions and 0 deletions

View File

@ -35,12 +35,14 @@ app.use(express.json());
// res.send('Hello World!');
// })
console.log("Setting route for /ads.txt");
app.get('/ads.txt', (req, res) => {
res.setHeader("Content-Type", "text/plain");
res.setHeader("Cache-Control", "no-cache");
res.send(`google.com, pub-8937572456576531, DIRECT, f08c47fec0942fa0`);
});
console.log("Setting route for /robots.txt");
app.get('/robots.txt', (req, res) => {
res.setHeader("Content-Type", "text/plain");
res.setHeader("Cache-Control", "no-cache");
@ -55,10 +57,12 @@ Allow: /
});
// Search endpoints
console.log("Setting route for /search");
app.use('/search', search.router);
// app.use('/advanced-search', advancedSearch.router);
// Endpoints for all the site's pages.
console.log("Scanning for pages to create routes");
glob.globSync('pages/**/*.md', {
cwd: path.join(__dirname, '..'),
matchBase: true,
@ -71,6 +75,7 @@ glob.globSync('pages/**/*.md', {
const fullFilePath = path.join(__dirname, '..', filePath);
let paths = route.split(path.posix.sep);
paths[0] = 'public';
console.log(`Setting route for ${route}`);
app.get(route, async (req, res) => {
const fm = matter.read(fullFilePath);
const fmData = { fm: fm.data, excerpt: fm.excerpt };
@ -80,8 +85,46 @@ glob.globSync('pages/**/*.md', {
});
});
// Endpoints for all the site's YouTube videos.
console.log("Scanning for archived videos to create routes");
glob.globSync('Russell_County/Board_of_Supervisors/YouTube_Archive/**/*.info.json', {
cwd: path.join(__dirname, '..', 'public'),
matchBase: true,
follow: true,
}).forEach((filePath) => {
const expressRoutePathFromFilePath = (filePath) => {
return path.posix.sep+filePath.substring(0, filePath.lastIndexOf(path.sep)).replaceAll(path.sep, path.posix.sep);
};
const dirFromFilePath = (filePath) => {
return filePath.substring(0, filePath.lastIndexOf(path.sep));
}
const directory = dirFromFilePath(filePath);
let videoURL = glob.globSync("*.{mpg,mpeg,mp4,mkv,webm}", {
cwd: path.join(__dirname, '..', 'public', directory),
matchBase: true,
follow: true,
}).pop();
const route = encodeURI(expressRoutePathFromFilePath(filePath));
let paths = filePath.substring(0, filePath.lastIndexOf(path.sep) > 0 ? filePath.lastIndexOf(path.sep) : filePath.length-1).split(path.sep);
paths = paths.map((name, idx, aPaths) => {
let url = aPaths.slice(0, idx+1).join(path.posix.sep);
return {
name,
url,
};
});
const fullFilePath = path.join(__dirname, '..', 'public', filePath);
console.log(`Setting route for ${route}`);
app.get(route, async (req, res) => {
let info = require(fullFilePath);
const renderData = { route, filePath, fullFilePath, req, paths, directory, videoURL, info };
res.render("video-player", { h: helpers, ...renderData });
});
});
//app.get('/OCR-Encoded-PDFs/Russell-County-Web-Site_2024-02-13_19_50_Modified-With-OCR-Encoding**', rewriter.rewrite('/Web_Site_Archives/Russell_County_Web_Site-2024-02-13_19_50_Modified_With_OCR_Encoding/$1'));
console.log(`Setting route for *`);
app.get('*', async (req, res) => {
await serve(req, res, {
public: path.join(__dirname, '..', 'public'),

View File

@ -1,4 +1,5 @@
const path = require('path');
const glob = require('glob');
const fs = require('fs');
const process = require('process');
const markdownit = require('markdown-it');

53
views/video-player.ejs Normal file
View File

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title><%=h.getDirectoryTitle({directory})%></title>
<%- include('./includes/common-head.ejs') %>
</head>
<body onload="initPage()">
<%- include('./includes/top-navbar.ejs') %>
<main class="container">
<header>
<h1 class="mt-5">
<i>&nbsp;</i>
<% paths.forEach(function(value, index) { %>
<% if (h.shouldShowDirectorySeparator({index})) { %>
<span class="separator">&rsaquo; </span>
<% } %>
<% if (h.shouldShowWelcomeBanner({paths})) { %>
Welcome to <%= h.getDirectoryTitle({directory}) %>
<% } else if (h.shouldOmitLinkOnLastBreadcrumb({paths, index})) { %>
<%= h.trimSlashes({path: value.name}) %>
<% } else { %>
<a href="/<%= value.url %>">
<%= h.getDirectoryName({directory: value.name}) %>
</a>
<% } %>
<% }); %>
</h1>
</header>
<% if (typeof info !== 'undefined') {%>
<div class="row p-4 pb-0 pe-lg-0 pt-lg-5 align-items-center rounded-3 border shadow-lg">
<div class="col-lg-12 p-3 p-lg-5 pt-lg-3">
<h1 class="title"><%= (typeof info.title !== 'undefined') ? info.title : "" %> </h1>
<video class="object-fit-fill ratio ratio-16x9" src="<%-videoURL%>" controls allowfullscreen></video>
</div>
</div>
<% } %>
</main>
<%- include('./includes/bottom-navbar.ejs') %>
<!-- Bootstrap JS (optional, if you need Bootstrap JS features) -->
<script src="https://daball.me/vendor/jquery/jquery.min.js"></script>
<script src="https://daball.me/vendor/popper.js/dist/popper.min.js"></script>
<script src="https://daball.me/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="https://daball.me/vendor/jquery-easing/jquery.easing.min.js"></script>
<script src="https://daball.me/layouts/blog/js/blog.min.js"></script>
</body>
</html>