Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as Bash by registered user uwe ( 13 years ago )
#!/bin/bash

# config
savepath="/Users/uwe/Movies/AppleTrailers"
donepath="$savepath/done"

log="$savepath/.appletrailer.log"

trailerurl="http://trailers.apple.com/trailers/home/xml/current_720p.xml"

useragent="QuickTime/7.6.2 (qtver=7.6.2;os=Windows NT 5.1Service Pack 3)"

if [ -n "$log" ]; then
    echo "$(date +%F-%T) start" >> $log
fi

# convert xml to something readable ... at least a bit readable
curl -s "$trailerurl" | xml fo - | egrep '<title>|<postdate>|<large filesize' > /tmp/$$

down=0

while read l; do
    case ${l:1:1} in
# <title>
        t)  t="$(echo "$l" | sed 's,<title>,,;s,</title>,,' | tr -d "/'")"
            ;;
# <postdate>
        p)  d="$(echo "$l" | sed 's,<postdate>,,;s,</postdate>,,')"
            ;;
# <preview><large filesize=...
        l)  # url
            url="$(echo "$l" | sed 's,<large[^>]*>,,;s,</large>,,')"
            # filename
            fn="${url/*\\/}"
            # savename (file will be written as this name)
            sn="$d $t -- $fn"
            # check if file exists
            if [ ! -f "$savepath/$sn" -a ! -f "$donepath/$sn" ]; then
                if [ -n "$log" ]; then
                    echo "$(date +%F-%T) get $t -- $fn" >> $log
                fi
                curl -s -A "$useragent" -o "$savepath/$sn" "$url"
                if [ $? -ne 0 ]; then
                    if [ -n "$log" ]; then
                        echo "$(date +%F-%T) nok   $t -- $fn" >> $log
                    fi
                    rm -f "$savepath/$sn"
                else
                    if [ -n "$log" ]; then
                        echo "$(date +%F-%T) ok    $t -- $fn" >> $log
                        (( down++ ))
                    fi
                fi
            fi
            ;;
    esac
done < /tmp/$$

rm -f /tmp/$$

# if something was downloaded, restart the dlna (force)
if [ $down -ne 0 ]; then
    /Users/uwe/scripts/update-dlna -f
fi

if [ -n "$log" ]; then
    echo "$(date +%F-%T) stop (downloaded $down)" >> $log
fi

 

Revise this Paste

Your Name: Code Language: