Add GPS map generation and display on index and new pages
This commit is contained in:
parent
0fd6d43adb
commit
d640491e16
4 changed files with 626 additions and 11 deletions
23
index.php
23
index.php
|
|
@ -17,13 +17,11 @@ function hidden_video_outputs($config){
|
|||
function video_metadata($path){
|
||||
$base = pathinfo($path, PATHINFO_FILENAME);
|
||||
$meta = ['title' => nice_title($base), 'date' => date('Y-m-d', filemtime($path)), 'sort_date' => date('Y-m-d', filemtime($path)), 'location' => '', 'description' => ''];
|
||||
|
||||
if (preg_match('/^(\d{4})(\d{2})(\d{2})[_-](.+)$/', $base, $m)) {
|
||||
$meta['date'] = "$m[1]-$m[2]-$m[3]";
|
||||
$meta['sort_date'] = "$m[1]-$m[2]-$m[3]";
|
||||
$meta['title'] = nice_title($m[4]);
|
||||
}
|
||||
|
||||
foreach ([dirname($path).'/'.$base.'.txt', dirname($path).'/'.$base.'.data.txt'] as $sidecar) {
|
||||
if (!is_file($sidecar)) continue;
|
||||
foreach (file($sidecar, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
|
||||
|
|
@ -33,7 +31,6 @@ function video_metadata($path){
|
|||
if (in_array($k, ['title','date','location','place','description'], true)) $meta[$k === 'place' ? 'location' : $k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$ffprobe = trim((string)shell_exec('command -v ffprobe 2>/dev/null'));
|
||||
if ($ffprobe !== '') {
|
||||
$json = shell_exec(escapeshellarg($ffprobe).' -v quiet -print_format json -show_entries format_tags '.escapeshellarg($path).' 2>/dev/null');
|
||||
|
|
@ -42,9 +39,7 @@ function video_metadata($path){
|
|||
$lower = [];
|
||||
foreach ($tags as $k => $v) $lower[strtolower($k)] = $v;
|
||||
if (!empty($lower['title'])) $meta['title'] = $lower['title'];
|
||||
if (!empty($lower['date'])) {
|
||||
$meta['date'] = $lower['date'];
|
||||
}
|
||||
if (!empty($lower['date'])) $meta['date'] = $lower['date'];
|
||||
if (!empty($lower['creation_time'])) {
|
||||
$meta['sort_date'] = substr($lower['creation_time'], 0, 10);
|
||||
if (empty($lower['date'])) $meta['date'] = $meta['sort_date'];
|
||||
|
|
@ -65,7 +60,6 @@ function load_video_cache($videos){
|
|||
$items = $cache['items'] ?? [];
|
||||
$newItems = [];
|
||||
$changed = false;
|
||||
|
||||
foreach ($videos as $path) {
|
||||
$key = basename($path);
|
||||
$mtime = filemtime($path);
|
||||
|
|
@ -77,7 +71,6 @@ function load_video_cache($videos){
|
|||
}
|
||||
$newItems[$key] = $cached;
|
||||
}
|
||||
|
||||
if (array_diff(array_keys($items), array_keys($newItems))) $changed = true;
|
||||
if ($changed) {
|
||||
file_put_contents($cacheFile, json_encode(['version' => 2, 'generated_at' => date('c'), 'items' => $newItems], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT), LOCK_EX);
|
||||
|
|
@ -85,7 +78,7 @@ function load_video_cache($videos){
|
|||
return $newItems;
|
||||
}
|
||||
$hiddenOutputs = hidden_video_outputs($config);
|
||||
$videos = array_values(array_filter(glob($config['videos_dir'].'/*.{mp4,webm,mov,m4v}', GLOB_BRACE) ?: [], fn($v)=>empty($hiddenOutputs[basename($v)]) && !preg_match('/_preview\.(mp4|webm|mov|m4v)$/i', basename($v)) && !preg_match('/_preview\.(mp4|webm|mov|m4v)$/i', basename($v))));
|
||||
$videos = array_values(array_filter(glob($config['videos_dir'].'/*.{mp4,webm,mov,m4v}', GLOB_BRACE) ?: [], fn($v)=>empty($hiddenOutputs[basename($v)]) && !preg_match('/_preview\.(mp4|webm|mov|m4v)$/i', basename($v))));
|
||||
$videoCache = load_video_cache($videos);
|
||||
usort($videos, function($a, $b) use ($videoCache) {
|
||||
$am = $videoCache[basename($a)] ?? [];
|
||||
|
|
@ -100,7 +93,17 @@ $page=max(1,(int)($_GET['page']??1)); $per=$config['items_per_page']; $total=cou
|
|||
<header class="site-header admin-header"><div class="brand-wrap"><a class="header-logo" href="index.php" aria-label="MVLog home"><img src="assets/img/moto_travel.png" alt=""></a><a class="brand" href="index.php"><h1>MVLog</h1><p>Bubulescu.Org</p></a></div><button id="push-toggle" class="push-toggle" type="button" hidden aria-label="Notifications" title="Notifications"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 22a2.7 2.7 0 0 0 2.6-2h-5.2A2.7 2.7 0 0 0 12 22Zm7-6V11a7 7 0 0 0-5-6.7V3a2 2 0 0 0-4 0v1.3A7 7 0 0 0 5 11v5l-2 2v1h18v-1l-2-2Z"/></svg></button><a class="rss-link" href="feed.php" aria-label="RSS feed" title="RSS feed"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6.2 17.8a2 2 0 1 1-4 0 2 2 0 0 1 4 0ZM2.2 8.7v3.1a10 10 0 0 1 10 10h3.1A13.1 13.1 0 0 0 2.2 8.7Zm0-5.5v3.1a15.5 15.5 0 0 1 15.5 15.5h3.1A18.6 18.6 0 0 0 2.2 3.2Z"/></svg></a></header><main>
|
||||
<section id="videos"><?php if(!$slice): ?><p>No videos yet.</p><?php endif; ?><div class="video-list">
|
||||
<?php foreach($slice as $v): $name=basename($v); $url=$config['public_videos'].'/'.rawurlencode($name); $m=$videoCache[$name]['metadata'] ?? video_metadata($v); ?>
|
||||
<article class="video-row"><time class="created-at" datetime="<?=h(date('c', filemtime($v)))?>"><?=h(date('d.m.Y H:i', filemtime($v)))?></time><video controls controlsList="nodownload" oncontextmenu="return false" preload="metadata" src="<?=h($url)?>"></video><div class="video-info"><h2><?=h($m['title'])?></h2><p class="meta"><span><?=h($m['date'])?></span><?php if($m['location']): ?><span><?=h($m['location'])?></span><?php endif; ?></p><?php if($m['description']): ?><p class="description"><?=nl2br(h($m['description']), false)?></p><?php endif; ?></div></article>
|
||||
<article class="video-row"><time class="created-at" datetime="<?=h(date('c', filemtime($v)))?>"><?=h(date('d.m.Y H:i', filemtime($v)))?></time>
|
||||
<div class="video-wrapper">
|
||||
<video controls controlsList="nodownload" oncontextmenu="return false" preload="metadata" src="<?=h($url)?>"></video>
|
||||
<?php
|
||||
$map=pathinfo($name, PATHINFO_FILENAME).".png";
|
||||
if(is_file($config["videos_dir"]."/".$map)):
|
||||
?>
|
||||
<img class="map-image" src="<?=h($config["public_videos"]."/".rawurlencode($map))?>" alt="Map">
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="video-info"><h2><?=h($m['title'])?></h2><p class="meta"><span><?=h($m['date'])?></span><?php if($m['location']): ?><span><?=h($m['location'])?></span><?php endif; ?></p><?php if($m['description']): ?><p class="description"><?=nl2br(h($m['description']), false)?></p><?php endif; ?></div></article>
|
||||
<?php endforeach; ?></div><div class="pages"><?php for($i=1;$i<=$pages;$i++): ?><a class="<?=$i===$page?'active':''?>" href="?page=<?=$i?>"><?=$i?></a><?php endfor; ?></div></section>
|
||||
</main><footer>Bubulescu.Org</footer><script>
|
||||
(function(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue