Wednesday, May 18, 2011

Keep Apple trailers with you!

If you're like me and love watching trailers over and over especially in HD, it's frustrating to watch them online at Apple trailers.  You would want to use a Download manager but what better than wget?!

And it's not that easy when you are a mouse-hater! Yes I know how frustrating it is to reach for the mouse/trackpad when you love the keyboard! So here's a shell script I made to ease it! (You'll need to have wget installed though)

It's not 100% perfect. I've still got more options to add and make it better. But for now...

(I'll be adding explanation soon...)
Credits for whoever wrote that Regex for the url!

An eg:  Enjoy an awesome Harry potter trailer here!
atget http://trailers.apple.com/movies/wb/harrypotterandthedeathlyhallowspart2/harrypotterhallows2-tlr1_720p.mov



#!/bin/bash
# atget - download trailers from Apple trailers


# Usage if no parameters given
if [ $# -eq 0 ]; then
  echo "     Download Trailers from Apple iTunes website"
  echo "     usage: atget [-c] "
  echo "     where "
  echo "            -c    Resume incomplete download" 
  exit
fi


#Should resume download with wget?
wgetc=


if [ "$1" = "-c" ]; then
  oldurl=$2 
  wgetc="-c"
else
  oldurl=$1


  filename=$(basename $oldurl)
  save_location=$HOME/Movies/$filename
  if [ -f $save_location ]; then
  echo -n "File exists with same name already! Overwrite (o) / Resume (r)? "
  read result
wgetc="-c"
  if [ "$result" = "o" ] || [ "$result" = "O" ]; then
wgetc=
fi
# exit
  fi
fi


# Prepend 'h' before resolution to create a valid url
newurl=$(echo $oldurl | sed 's/_\([0-9]*[0-9][0-9][0-9]\)p.mov/_h\1p.mov/g')


filename=$(basename $oldurl)
save_location=$HOME/Movies/$filename


# Download trailer and save to Movies folder of the user
wget $wgetc -U QuickTime "$newurl" -O $save_location