Created
January 29, 2014 03:55
-
-
Save jershmagersh/8681562 to your computer and use it in GitHub Desktop.
Ruby file for generating HTML jwplayer mp4 uploaded files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
$UPLOAD_DIR = "/var/www/uploads" | |
$HOME = "/var/www" | |
files = Dir.entries $UPLOAD_DIR | |
files.each do |file| | |
if file.to_s.include? ".mp4" | |
html_file_name = "#{file[0,file.length-4]}.html" | |
if !File.exists? "#{$HOME}/#{html_file_name}" | |
puts "Generating: #{html_file_name}" | |
page_content = %{ | |
<html> | |
<script type="text/javascript" src="jwplayer/jwplayer.js"></script> | |
<div id="myElement">Loading the player...</div> | |
<script type="text/javascript"> | |
jwplayer("myElement").setup({ | |
file: "/uploads/#{file.to_s}", | |
}); | |
</script> | |
</html> | |
} | |
html_file = File.new("#{$HOME}/#{html_file_name}", "w") | |
html_file.write(page_content) | |
html_file.close | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment