Media RSS (MRSS) generator script

Home / Uncategorized / Media RSS (MRSS) generator script

I came across a DOS batch file that generates the necessary xml manifest for Video files on BrightSign’s Developer Resources and Utilities page. Since I’m serving my video content to our BrightSign infrastructure from a LAMP stack I ended up rewriting their bat file as a shell script. This enables me to host the shell script in a local directory (/usr/local/bin) and run it from cron every 5 minutes against a folder full of mp4 files and have the MRSS manifest written to this folder as well. Then all that needs to be done is to point the BrightSign MRSS widget at the URL for the xml file (http://server-FQDN.com/VideoMRSS.xml). The crontab entry looks like:

*/5 * * * *   /usr/local/bin/VideoMRSS.sh /var/vhosts/jrnsignage/ >/var/vhosts/jrnsignage/VideoMRSS.xml

The script itself is pretty simple. I’ve tried to keep it almost as a exact copy of the dos batch file:


#!/bin/bash
# This script requires 1 argument. Argument 1 is the path to the folder containing the mp4 media files.
# Change this to the BaseURL of the site you'll be serving the XML file from. Omit the last forward slash.
baseurl=http://Server-FQDN.com
# You can change this to any number of minutes
refreshmin=5
guidnum=$(( RANDOM % 1000 ))
year=$(date +%Y)
month=$(date +%m)
day=$(date +%a)
hour=$(date +%H)
min=$(date +%M)
sec=$(date +%S)
header1="<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
header2="<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss/\">"
header3="<channel>"
header4="  <title>Batch Custom Video MRSS template for BrightSign Players</title>"
header5="  <link>$baseurl/VideoMRSS.xml</link>"
header6="  <generator>Video MRSS Generation Batch File</generator>"
header7="  <ttl>$refreshmin</ttl>"
footer1="</channel>"
footer2="</rss>"
echo $header1
echo $header2
echo $header3
echo $header4
echo $header5
echo $header6
echo $header7
find $1 -type f -name "*.mp4" -print |while read FULLFILENAME
do
   FILESIZE=$(stat -c%s "$FULLFILENAME")
   FILENAME=$(basename "$FULLFILENAME")
   FNAME="${FILENAME%.*}"
   echo "<item>"
   echo "   <title></title>"
   echo "   <pubDate>$year-$month-$day"T"$hour:$min:$sec.000z</pubDate>"
   echo "   <link>$baseurl/$FILENAME</link>"
   echo "   <description>$FILENAME</description>"
   echo "   <guid isPermalink=\"false\">$FNAME$guidnum</guid>"
   echo "   <media:content url=\"$baseurl/$FILENAME\" filesize=\"$FILESIZE\" type=\"video/mp4\" medium=\"video\"/>"
   echo "</item>"
done

echo $footer1
echo $footer2

Leave a Reply