summaryrefslogtreecommitdiff
path: root/videos.rb
diff options
context:
space:
mode:
Diffstat (limited to 'videos.rb')
-rwxr-xr-xvideos.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/videos.rb b/videos.rb
new file mode 100755
index 0000000..d4f68a7
--- /dev/null
+++ b/videos.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+
+require_relative 'lib'
+
+videos = Dir[File.join(MEDIA_DIR, 'videos', '*')].sort.reverse
+html = File.read(File.join(SNIPPETS, 'head.html'))
+html += nav 'videos'
+videos.each_with_index do |dir, _i|
+ date = File.basename(dir).split('_')[0]
+ html += "<div class='post' id='#{date}'>"
+ title = File.basename(dir).split('_')[1..-1].join(' ')
+ html += "<h1>#{title}</h1>"
+ txt = File.read(File.join(dir, 'README'))
+ txt = txt.gsub(/(http\S*)/, '<a href="\1">\1</a>')
+ lines = txt.split("\n")
+ html += lines.shift + '<p>'
+
+ mp4 = File.join(MEDIA_URL, 'videos', File.basename(dir), title.gsub(' ', '_') + '.mp4')
+ webm = File.join(MEDIA_URL, 'videos', File.basename(dir), title.gsub(' ', '_') + '.webm')
+ poster = File.join(MEDIA_URL, 'videos', File.basename(dir), title.gsub(' ', '_') + '.webp')
+ w, h = `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 #{webm}`.chomp.split(',')
+
+ html += "<video controls preload='none' width='#{w}' height='#{h}' poster='#{poster}'>
+ <source src='#{webm}' type='video/webm'>
+ <source src='#{mp4}' type='video/mp4'>
+ <a href=#{mp4}>#{mp4}</a>
+ </video><p>
+ "
+ html += lines.join('<br>')
+ html += '</div>'
+end
+html += '<p>&nbsp;&copy; pdp8 <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>'
+html += File.read(File.join(SNIPPETS, 'tail.html'))
+print_html 'videos', html