Podcast publication made easy
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.
 
 

160 lines
3.7 KiB

#!/bin/sh
exitp() {
echo "$1"
exit 1
}
usage() {
name=$(basename $0)
printf '%s\n' \
"$name init | gen | episode TITLE FILE [ID]" \
"$name init" \
': initialize the potcasse structure' \
"$name gen" \
': generate the RSS file' \
"$name episode TITLE FILE [ID]" \
': create the structure for a new episode and eventually copy file [FILE] in [ID]'
exit 0
}
init() {
test -f metadata.sh && exitp "You seem in a directory managed by potcasse"
mkdir -p episodes
cat << EOF > metadata.sh
# title of your podcst
TITLE=
# base URL of your website
# must end with a /
SITE=
# filename of the RSS file
RSSLINK=feed.xml
# language for the podcast/index.html file
LANGUAGE=en-us
#uncomment to use logo.png as a logo
#IMAGE=YES
EOF
exit 0
}
episode() {
test -f metadata.sh || exitp "The directory isn't managed by potcasse"
TITLE="$1"
test -f "$2" || exitp "File $2 doesn't exist"
AUDIOFILE="$2"
EXT=${AUDIOFILE##*.}
if [ -n "$3" ]
then
ID="$3"
else
ID="$(date +%Y%m%d%H)"
fi
DEST="episodes/${ID}"
mkdir -p "$DEST"
cat << EOF > ${DEST}/metadata.sh
TITLE="$TITLE"
PUBDATE="$(date "+%a, %d %b %Y 00:00:00 GMT")"
AUDIOFILE="${ID}.${EXT}"
EOF
cp "$AUDIOFILE" "${DEST}/${ID}.${EXT}"
}
gen() {
test -d episodes || exitp "You need to import episodes before generation"
TMPRSS=$(mktemp /tmp/potcasse.XXXXXXXXXXXXXXXXXXXXX)
TMPHTML=$(mktemp /tmp/potcasse.XXXXXXXXXXXXXXXXXXXXX)
. ./metadata.sh
mkdir -p output_html/episodes
if [ -n "$IMAGE" ]
then
test -f logo.png || exitp "You defined an IMAGE, move it to $PWD/logo.png"
cp logo.png output_html/logo.png
fi
cat <<EOF >> $TMPRSS
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>${TITLE}</title>
<description>${DESCRIPTION}</description>
<atom:link href="${SITE}${RSSLINK}" rel="self" type="application/rss+xml" />
<link>${SITE}</link>
<image>
<url>${SITE}/logo.png</url>
<title>${TITLE}</title>
<link>${SITE}</link>
</image>
<language>${LANGUAGE}</language>
EOF
cat <<EOF >> $TMPHTML
<!DOCTYPE html>
<html lang="${LANGUAGE}">
<head>
<title>${TITLE}</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Podcast episodes- ${TITLE}</h1>
<div>
<img src="logo.png" width=200 height=200 alt="logo" />
</div>
<ul>
<li><a href="${RSSLINK}">RSS feed</a> (for podcast players).</li>
</ul>
<ul>
EOF
for episode in episodes/*
do
echo "Scanning $episode"
. ${episode}/metadata.sh
SIZE=$(stat -f "%z" "${episode}/${AUDIOFILE}")
EXT=${AUDIOFILE##*.}
rsync -a "${episode}/${AUDIOFILE}" output_html/episodes/
cat <<EOF >> $TMPRSS
<item>
<title>$TITLE</title>
<description></description>
<pubDate>${PUBDATE}</pubDate>
<guid>${SITE}/episodes/${AUDIOFILE}</guid>
<enclosure url="${SITE}/episodes/${AUDIOFILE}" length="${SIZE}" type="audio/${EXT}" />
</item>
EOF
cat <<EOF >> $TMPHTML
<li>${PUBDATE} - <a href="episodes/${AUDIOFILE}">${TITLE}</a></li>
EOF
done
cat <<EOF >> $TMPRSS
</channel>
</rss>
EOF
cat <<EOF >> $TMPHTML
</ul>
</body>
</html>
EOF
install -m 644 "$TMPRSS" output_html/${RSSLINK}
install -m 644 "$TMPHTML" output_html/index.html
rm "$TMPRSS" "$TMPHTML"
}
case "$1" in
'') usage;;
help) usage;;
init) init ;;
gen) gen ;;
episode) [ -n "$2" ] && episode "$2" "$3" "$4" ;;
esac