Batch embed video files to html files (with Automator?)

applescriptautomatorscript

Can the following be done with Automator, or any other tool/script on macOS?

  • I have multiple video files with various file names (always .mp4).
  • All video files must be embeded in to separate HTML documents.
  • The HTML-documents should have the same file name as the video file.
  • Both files should be placed together in a zip file.
  • The zip file should have the same name as both the video and the HTML file.

So, if I have the file video-to-html.mp4, I would like to end up with a zip file containing two files:

video-to-html/video-to-html.html
video-to-html/video-to-html.mp4

The contents of the HTML file would look like:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Lorem ipsum</title>
</head>
<body>
<video autoplay controls>
<source src="video-to-html.mp4" type="video/mp4">
</video>
</body>
</html>

I am not a developer, so I do not understand a lot of coding.

Best Answer

You can accomplish this easily with a short shell script:

#!/bin/bash

for v do
    base=${v%%.mp4}
    cat >>"${base}.html" <<EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Lorem ipsum</title>
</head>
<body>
<video autoplay controls>
<source src="$v" type="video/mp4">
</video>
</body>
</html>
EOF

    rm -f "${base}.zip"
    zip "${base}.zip" "${base}.html" "$v"
done

Save it as a shell script in a convenient place, open Terminal, run chmod +x name-of-script and execute as ./name-of-script *.mp4