141 lines
3.6 KiB
Bash
Executable File
141 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
MP4_FILENAME="$1"
|
|
if [ "${MP4_FILENAME}" == "" ]
|
|
then
|
|
echo "MP4 filename needed for argument 1" >&2
|
|
exit 1
|
|
fi
|
|
|
|
DESCRIPTION="$2"
|
|
if [ "${DESCRIPTION}" == "" ]
|
|
then
|
|
echo "Description needed for argument 2" >&2
|
|
fi
|
|
|
|
source .env
|
|
|
|
function escape() {
|
|
local s
|
|
s=${1//&/&}
|
|
s=${s//</<}
|
|
s=${s//>/>}
|
|
s=${s//'"'/"}
|
|
printf -- %s "$s"
|
|
}
|
|
|
|
function generate_xml() {
|
|
# .whatever
|
|
EXT="$1"
|
|
|
|
cat << EOF
|
|
<?xml version="1.0" ?>
|
|
<rss version="2.0">
|
|
<channel>
|
|
<title>${PODCAST_NAME}</title>
|
|
<link>${PODCAST_WEBROOT}</link>
|
|
<description>${PODCAST_DESCRIPTION}</description>
|
|
<image>
|
|
<url>${PODCAST_WEBROOT}${IMAGE}</url>
|
|
</image>
|
|
EOF
|
|
|
|
ls -1t "${OUT_DIR}"/*${EXT} | while read LONG_FNAME
|
|
do
|
|
FILE=$(basename "${LONG_FNAME}" "${EXT}")
|
|
FILE_URL="${PODCAST_WEBROOT}${FILE}${EXT}"
|
|
TITLE=$(escape "$(exiftool -b -title "${LONG_FNAME}")")
|
|
DESCRIPTION=$(escape "$(exiftool -b -description "${LONG_FNAME}")")
|
|
PUB_DATE=$(LC_ALL=C date -r "${LONG_FNAME}" "+%a, %d %b %Y %H:%M:%S %z")
|
|
|
|
cat << EOF
|
|
<item>
|
|
<title>${TITLE}</title>
|
|
<link>${FILE_URL}</link>
|
|
<description>${DESCRIPTION}</description>
|
|
<pubDate>${PUB_DATE}</pubDate>
|
|
</item>
|
|
EOF
|
|
done
|
|
|
|
echo "</channel></rss>"
|
|
}
|
|
|
|
function generate_html() {
|
|
ESCAPED_PODCAST_NAME=$(escape "${PODCAST_NAME}")
|
|
ESCAPED_PODCAST_DESCRIPTION=$(escape "${PODCAST_DESCRIPTION}")
|
|
|
|
cat << EOF
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>${ESCAPED_PODCAST_NAME}</title>
|
|
<link rel="alternate" type="application/rss+xml" title="Audio Podcast" href="/mp3.rss.xml"/>
|
|
<link rel="alternate" type="application/rss+xml" title="Video Podcast" href="/mp4.rss.xml"/>
|
|
</head>
|
|
<body>
|
|
<h1>${ESCAPED_PODCAST_NAME}</h1>
|
|
<p>
|
|
${ESCAPED_PODCAST_DESCRIPTION}
|
|
</p>
|
|
<ul>
|
|
<li><a href="/mp3.rss.xml">Direct link to audio podcast feed</a></li>
|
|
<li><a href="/mp4.rss.xml">Direct link to video podcast feed</a></li>
|
|
</ul>
|
|
EOF
|
|
|
|
ls -1t "${OUT_DIR}"/*.mp4 | while read LONG_FNAME
|
|
do
|
|
MP4_FILE=$(basename "${LONG_FNAME}")
|
|
MP3_FILE=$(basename "${MP4_FILE}" .mp4).mp3
|
|
TITLE=$(escape "$(exiftool -b -title "${LONG_FNAME}")")
|
|
DESCRIPTION=$(escape "$(exiftool -b -description "${LONG_FNAME}")")
|
|
PUB_DATE=$(LC_ALL=C date -r "${LONG_FNAME}" "+%a, %d %b %Y %H:%M:%S %z")
|
|
|
|
cat << EOF
|
|
<h2>${TITLE}</h2>
|
|
<div class="rss-item">
|
|
<p class="item-description">${DESCRIPTION}</p>
|
|
<ul class="item-files">
|
|
<li>
|
|
<a href="/${MP3_FILE}" target="_blank">Audio</a>
|
|
</li>
|
|
<li>
|
|
<a href="/${MP4_FILE}" target="_blank">Video</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
EOF
|
|
done
|
|
|
|
echo "</body></html>"
|
|
}
|
|
|
|
OUT_MP4_FILENAME="${OUT_DIR}/$(basename "${MP4_FILENAME}")"
|
|
MP3_FILENAME="${OUT_DIR}/$(basename "${MP4_FILENAME}" .mp4).mp3"
|
|
EPISODE=$(basename "${MP4_FILENAME}" .mp4 | egrep -o '[[:digit:]]+' | head -n1)
|
|
EPISODE_TITLE="${PODCAST_NAME} Episode ${EPISODE}"
|
|
|
|
echo "Copying mp4."
|
|
ffmpeg -hide_banner -loglevel error -y -i "${MP4_FILENAME}" \
|
|
-metadata title="${EPISODE_TITLE}" \
|
|
-metadata author="${PODCAST_AUTHOR}" \
|
|
-metadata description="${DESCRIPTION}" \
|
|
-c copy \
|
|
"${OUT_MP4_FILENAME}"
|
|
|
|
echo "Converting to mp3."
|
|
ffmpeg -hide_banner -loglevel error -y -i "${MP4_FILENAME}" \
|
|
-metadata title="${EPISODE_TITLE}" \
|
|
-metadata author="${PODCAST_AUTHOR}" \
|
|
-metadata description="${DESCRIPTION}" \
|
|
"${MP3_FILENAME}"
|
|
|
|
echo "Generating MP3 XML feed."
|
|
generate_xml .mp3 > "${OUT_DIR}/mp3.rss.xml"
|
|
|
|
echo "Generating MP4 XML feed."
|
|
generate_xml .mp4 > "${OUT_DIR}/mp4.rss.xml"
|
|
|
|
echo "Generating HTML."
|
|
generate_html > "${OUT_DIR}/index.html" |