Skip to content

Instantly share code, notes, and snippets.

@shivprasad
Created February 3, 2013 11:57
Show Gist options
  • Save shivprasad/4701503 to your computer and use it in GitHub Desktop.
Save shivprasad/4701503 to your computer and use it in GitHub Desktop.
Shell script to download trailers from http://hd-trailers.net. This script will download 480p trailers from Yahoo,Movifone and Apple. I started out from this script: http://majjix.com/2008/10/13/luke/automatically-downloading-quicktime-trailers-and-posters
#!/bin/bash
GETHD=1
GETPOSTER=1
KEEPDAYS="1365"
SAVEROOT="/media/Nexon/Trailers"
SAVEPATH="/media/Nexon/Trailers/hd-trailer."
DLDBPATH="/home/pi/"
FEEDS="http://feeds.hd-trailers.net/hd-trailers?format=xml"
if [[ $EUID -ne 1000 ]]; then
echo "This script must be run as pi" 1>&2
exit 1
fi
umask 0002
for FEEDURL in $FEEDS; do
TRAILERS=`xmlstarlet sel --net -D -T -t -m "/rss/channel/item"\
-v "guid" -o ";"\
-v "feedburner:origEnclosureLink" -o ";"\
-v "source"\
-n $FEEDURL`
# for i in {1..10} ;do
for MOVIE in $TRAILERS; do
MOVIEID=`echo $MOVIE | awk 'BEGIN { FS = ";" } ; { print $1 }'`
URL=`echo $MOVIE | awk 'BEGIN { FS = ";" } ; { print $2 }'`
SOURCE=`echo $MOVIE | awk 'BEGIN { FS = ";" } ; { print $3 }'`
YAHOO="Yahoo!"
MOVIEFONE="Moviefone"
APPLE="Apple"
#echo "Source -> $SOURCE"
#echo "URL -> $URL"
if [ "$SOURCE" = "$YAHOO" ]; then
ID=`echo $URL | awk 'BEGIN { FS = "&" } ; { print $1 }' | awk 'BEGIN { FS = "=" } ; { print $2 }'`
DATAURL="http://video.query.yahoo.com/v1/public/yql?q=SELECT%20%2A%20FROM%20yahoo.media.video.streams%20WHERE%20id%3D%27$ID%27%20AND%20format%3D%27mp4%27%20AND%20protocol%3D%27http%27%20AND%20plrs%3D%27sdwpWXbKKUIgNzVhXSce__%27%20AND%20region%3D%27US%27&env=prod"
TRAILERDATA=`xmlstarlet sel --net -D -T -t -m "/query/results/mediaObj/streams"\
-v "width" -o ";"\
-v "host" -o ";"\
-v "path"\
-n $DATAURL`
for TRAILER in $TRAILERDATA; do
WIDTH=`echo $TRAILER | awk 'BEGIN { FS = ";" } ; { print $1 }'`
WIDTH=${WIDTH%\.0}
FILEHOST=`echo $TRAILER | awk 'BEGIN { FS = ";" } ; { print $2 }'`
FILEPATH=`echo $TRAILER | awk 'BEGIN { FS = ";" } ; { print $3 }'`
PREVIEWFILE480p=`echo $FILEPATH |sed 's/.*\///' | awk 'BEGIN { FS = "?" } ; { print $1 }'`
if ! grep -q "###$MOVIEID.PREVIEW### ###$PREVIEWFILE480p###" $DLDBPATH.hd-trailers.db; then
if [ $WIDTH -eq 852 ]; then
wget -c -O $SAVEPATH$PREVIEWFILE480p "$FILEHOST$FILEPATH"
if [ $? -eq 0 ]; then
echo "###$MOVIEID.PREVIEW### ###$PREVIEWFILE480p###" >> $DLDBPATH.hd-trailers.db
else
echo "##### ID:$MOVIEID NAME:$PREVIEWFILE480p FAILED -- RETRY NEXT RUN"
fi
fi
else
echo "##### ID:$MOVIEID NAME:$PREVIEWFILE480p MARKED DONE"
fi
done
fi
if [ "$SOURCE" = "$MOVIEFONE" ]; then
PREVIEWFILE480p=`echo $URL |sed 's/.*\///'`
if ! grep -q "###$MOVIEID.PREVIEW### ###$PREVIEWFILE480p###" $DLDBPATH.hd-trailers.db; then
wget -c -O $SAVEPATH$PREVIEWFILE480p "$URL"
if [ $? -eq 0 ]; then
echo "###$MOVIEID.PREVIEW### ###$PREVIEWFILE480p###" >> $DLDBPATH.hd-trailers.db
else
echo "##### ID:$MOVIEID NAME:$PREVIEWFILE480p FAILED -- RETRY NEXT RUN"
fi
else
echo "##### ID:$MOVIEID NAME:$PREVIEWFILE480p MARKED DONE"
fi
fi
if [ "$SOURCE" = "$APPLE" ]; then
PREVIEWFILE480p=`echo $URL |sed 's/.*\///'`
if ! grep -q "###$MOVIEID.PREVIEW### ###$PREVIEWFILE480p###" $DLDBPATH.hd-trailers.db; then
wget -U "QuickTime/7.6.2" -c -O $SAVEPATH$PREVIEWFILE480p "$URL"
if [ $? -eq 0 ]; then
echo "###$MOVIEID.PREVIEW### ###$PREVIEWFILE480p###" >> $DLDBPATH.hd-trailers.db
else
echo "##### ID:$MOVIEID NAME:$PREVIEWFILE480p FAILED -- RETRY NEXT RUN"
fi
else
echo "##### ID:$MOVIEID NAME:$PREVIEWFILE480p MARKED DONE"
fi
fi
done
# done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment