Scripts for generating a personal video-streaming site from DASH-format videos
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

70 lines
1.6 KiB

#!/usr/bin/env ruby
# Change references to external files to point to our CDN.
require "nokogiri"
if ARGV.size < 2
puts "Usage: cdn-links <folder with HTML files> <CDN root>"
exit 1
end
folder = ARGV.shift
$cdn_root = ARGV.shift
def fix_url(url, rel_path)
# If it's a path relative to root, do that right
if url.start_with?("/")
return File.join($cdn_root, url)
end
# Relative to current path
File.join($cdn_root, rel_path, url)
end
def process_html(filename, rel_path)
doc = File.open(filename) { |f| Nokogiri.HTML(f) }
# PNG files show up as:
# - the src attribute on img tags
# - the poster attribute on video tags
# MPD files show up as:
# - the data-manifest attribute on video tags
doc
.css("img")
.each do |img|
if img["src"] && img["src"].end_with?(".png")
img["src"] = fix_url(img["src"], rel_path)
end
end
doc
.css("video")
.each do |video|
if video["poster"] && video["poster"].end_with?(".png")
video["poster"] = fix_url(video["poster"], rel_path)
end
if video["data-manifest"] && video["data-manifest"].end_with?(".mpd")
video["data-manifest"] = fix_url(video["data-manifest"], rel_path)
end
end
File.open(filename, "w") { |f| f.write(doc.to_html) }
end
def process_directory(dir, rel_path)
Dir.foreach(dir) do |filename|
next if filename.start_with?(".")
if File.directory?(File.join(dir, filename))
process_directory(File.join(dir, filename), File.join(rel_path, filename))
next
end
if filename.end_with?(".html")
process_html(File.join(dir, filename), rel_path)
next
end
end
end
process_directory(folder, "")