{{- $cache := "" -}} {{- $source := "" -}} {{- $timestamp := "" -}} {{- $caption := .Caption -}} {{- $remote := .Remote -}} {{- $public := print "public/" .Source -}} {{- $immutable := print (.RelURL | humanize | urlize) "-" (.Source | sha256 | truncate 8 "") -}} {{- $extension := path.Ext .Source -}} {{- $fileCache := print $.Author "/media/" $immutable $extension -}} {{- $notCached := not (fileExists (path.Join "public/" $fileCache)) -}} {{- if .Start -}} {{- $timestamp = print "#t=" .Start -}} {{- end -}} {{- if .End -}} {{- $timestamp = print "#t=," .End -}} {{- end -}} {{- if and .Start .End -}} {{- $timestamp = print "#t=" .Start "," .End -}} {{- end -}} {{- if $notCached -}} {{- with $remote := resources.GetRemote .Source -}} {{- with .Err -}} {{- warnf "Video fetch %s" . -}} {{- if not (fileExists $public) -}} {{- $caption = "No local video data found for source" -}} {{- end -}} {{- else -}} {{- $cache = . | resources.Copy $fileCache -}} {{- $cache = $cache.Permalink -}} {{- end -}} {{- else -}} {{- $caption = "No remote video data found for source" -}} {{- end -}} {{- else -}} {{- with $cache = resources.Get (path.Join "public/" $fileCache) -}} {{- $cache = $cache.Content | resources.FromString $fileCache -}} {{- $cache = $cache.Permalink -}} {{- end -}} {{- end -}} {{- $source = $cache -}} {{- if .Remote -}} {{- $source = .Source -}} {{- end -}}