Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # function to convert byte counts into something readable
- human_size() {
- awk -v sum="$1" \
- 'BEGIN {
- hum[1024^3]="Gb";
- hum[1024^2]="Mb";
- hum[1024]="Kb";
- for (x=1024^3; x>=1024; x/=1024) {
- if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; }
- }
- if (sum<1024) print "1kb";
- }'
- }
- debug() {
- local arg
- local line
- [ -n "$debug" ] && for arg in "$@"
- do
- echo "$arg" | while read line
- do
- echo "DEBUG: $line"
- done
- done
- [ -n "$debug" ] && echo
- }
- # the user agents curl should pretend to be:
- # - regular firefox client for download page
- # - smart tv client for the hbbtv stuff
- dl_agent="Mozilla/5.0 (Windows NT 6.1; rv:27.3) Gecko/20130101 Firefox/27.3"
- tv_agent="Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Large Screen Safari/533.4 GoogleTV/b51795"
- # curl options - verbose (-v) or silent (-s)
- curlopts="-s"
- # see if -d was given as first param
- [ "$1" = "-d" ] && {
- debug=1;
- shift;
- }
- # memorize download link that was given on cmd line
- link="${1%%\?*}" # remove trailing ? paramters
- debug "Downloading:" "$link"
- # sanity check
- [ -n "$link" ] || { echo "Missing url parameter."; exit 1; }
- # extract json file url(s) from download link page
- url=`curl "$curlopts" -A "$dl_agent" "$link" | grep -m1 -o "http://.*PLUS7.*\.json"`
- debug "JSON url:" "$url"
- # quit if we got no json file url at all
- [ -n "$url" ] || { echo "Empty json url."; exit 1; }
- # remove 'player/' string from json url
- url=${url/player\//}
- # extract video urls from json file
- urls=`curl "$curlopts" -A "$tv_agent" "$url" | tr "\"" "\n" | grep -o "http://[^\"]*HBBTV[^\"]*\.mp4"`
- debug "Video urls:" "$urls"
- # get file sizes for each video url and print result
- for u in $urls
- do
- length=`curl "$curlopts" -A "$tv_agent" -I $u | sed -n "/Content-Length:/ {s/Content-Length: *//;p;}"`
- size=`human_size $length`
- printf "%10s | %s\n" "$size" "$u"
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement