#!/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//'"'/"} printf -- %s "$s" } function generate_xml() { # .whatever EXT="$1" cat << EOF ${PODCAST_NAME} ${PODCAST_WEBROOT} ${PODCAST_DESCRIPTION} ${PODCAST_WEBROOT}${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 ${TITLE} ${FILE_URL} ${DESCRIPTION} ${PUB_DATE} EOF done echo "" } function generate_html() { ESCAPED_PODCAST_NAME=$(escape "${PODCAST_NAME}") ESCAPED_PODCAST_DESCRIPTION=$(escape "${PODCAST_DESCRIPTION}") cat << EOF ${ESCAPED_PODCAST_NAME}

${ESCAPED_PODCAST_NAME}

${ESCAPED_PODCAST_DESCRIPTION}

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

${TITLE}

${DESCRIPTION}

EOF done echo "" } 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"