[FFmpeg-devel] [PATCH 1/3] web: move RSS generation to a seperate shell script

Stefano Sabatini stefasab at gmail.com
Tue Nov 26 10:24:13 CET 2013


On date Monday 2013-11-25 14:25:05 -0800, Timothy Gu encoded:
> Easier to read.
> 
> Signed-off-by: Timothy Gu <timothygu99 at gmail.com>
> ---
>  Makefile   | 20 +++-----------------
>  rss-gen.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 62 insertions(+), 17 deletions(-)
>  create mode 100755 rss-gen.sh
> 
> diff --git a/Makefile b/Makefile
> index db2ac28..36e9818 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -18,22 +18,8 @@ htdocs/%.html: src/% src/%_title $(PAGE_DEPS)
>  	src/template_footer > $@
>  
>  htdocs/main.rss: htdocs/index.html
> -	echo '<?xml version="1.0" encoding="UTF-8" ?>' > $@
> -	echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' >> $@
> -	echo '<channel>' >> $@
> -	echo '    <title>FFmpeg RSS</title>' >> $@
> -	echo '    <link>http://ffmpeg.org</link>' >> $@
> -	echo '    <description>FFmpeg RSS</description>' >> $@
> -	echo '    <atom:link href="http://ffmpeg.org/main.rss" rel="self" type="application/rss+xml" />' >> $@
> -	grep '<a *id=".*" *></a><h3>.*20..,.*</h3>' $< | sed 'sX<a *id="\(.*\)" *> *</a> *<h3>\(.*20..\), *\(.*\)</h3>X\
> -    <item>\
> -        <title>\2, \3</title>\
> -        <link>http://ffmpeg.org/index.html#\1</link>\
> -        <guid>http://ffmpeg.org/index.html#\1</guid>\
> -    </item>\
> -X' >> $@
> -	echo '</channel>' >> $@
> -	echo '</rss>' >> $@
> -
> +	./rss-gen.sh start $@
> +	$(foreach html, $^, ./rss-gen.sh middle $@ $(html);)
> +	./rss-gen.sh end   $@
>  
>  .PHONY: all clean
> diff --git a/rss-gen.sh b/rss-gen.sh
> new file mode 100755
> index 0000000..a2edb07
> --- /dev/null
> +++ b/rss-gen.sh
> @@ -0,0 +1,59 @@
> +#!/bin/sh
> +
> +die() {
> +    cat <<EOT >&2
> +Usage: $0 <mode> <htdocs/output.rss> [<input.html>]
> +
> +This utility parses & converts generated FFmpeg news HTML page into RSS format.
> +"mode" can be begin, middle, or end. If mode is middle, then input HTML is
> +required.
> +EOT
> +    exit 1
> +}
> +
> +# Sanity checks and parsing command line
> +
> +MODE=$1
> +RSS=$2
> +HTML=$3
> +
> +HTML_NODIR=${HTML##*/}
> +
> +if test $# -lt 2; then
> +    echo 'Too few arguments' >&2
> +    die
> +elif test $# -gt 3; then
> +    echo 'Too many arguments' >&2
> +    die
> +elif test $MODE = "middle" && test $# -ne 3; then
> +    echo 'No HTML specified' >&2
> +    die
> +fi
> +
> +if test $MODE = "start"; then
> +    cat << EOT > $RSS
> +<?xml version="1.0" encoding="UTF-8" ?>
> +<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
> +<channel>
> +    <title>FFmpeg RSS</title>
> +    <link>http://ffmpeg.org</link>
> +    <description>FFmpeg RSS</description>
> +    <atom:link href="http://ffmpeg.org/main.rss" rel="self" type="application/rss+xml" />
> +EOT
> +elif test $MODE = "middle"; then

> +    grep '<a *id=".*" *></a><h3>.*20..,.*</h3>' $HTML | sed 'sX<a *id="\(.*\)" *> *</a> *<h3>\(.*20..\), *\(.*\)</h3>X\

Note: "X" is a weird choice and will fail in case we add an "X" in the
quoted text.

> +    <item>\
> +        <title>\2, \3</title>\
> +        <link>http://ffmpeg.org/'$HTML_NODIR'#\1</link>\
> +        <guid>http://ffmpeg.org/'$HTML_NODIR'#\1</guid>\
> +    </item>\
> +X' >> $RSS
> +elif test $MODE = "end"; then
> +    cat << EOT >> $RSS
> +</channel>
> +</rss>
> +EOT
> +else
> +    echo 'Unknown mode' >&2
> +    die
> +fi

LGTM.
-- 
FFmpeg = Fanciful and Freak Minimal Patchable Esoteric Glue


More information about the ffmpeg-devel mailing list