Advertisement
Guest User

display arte+7 mp4 links script

a guest
Jun 16th, 2014
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.08 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # function to convert byte counts into something readable
  4. human_size() {
  5.     awk -v sum="$1" \
  6.         'BEGIN {
  7.           hum[1024^3]="Gb";
  8.           hum[1024^2]="Mb";
  9.           hum[1024]="Kb";
  10.           for (x=1024^3; x>=1024; x/=1024) {
  11.             if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; }
  12.           }
  13.           if (sum<1024) print "1kb";
  14.         }'
  15. }
  16.  
  17. debug() {
  18.  
  19.     local arg
  20.     local line
  21.     [ -n "$debug" ] && for arg in "$@"
  22.     do
  23.         echo "$arg" | while read line
  24.         do
  25.             echo "DEBUG: $line"
  26.         done
  27.     done
  28.     [ -n "$debug" ] && echo
  29. }
  30.  
  31. # the user agents curl should pretend to be:
  32. # - regular firefox client for download page
  33. # - smart tv client for the hbbtv stuff
  34. dl_agent="Mozilla/5.0 (Windows NT 6.1; rv:27.3) Gecko/20130101 Firefox/27.3"
  35. 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"
  36. # curl options - verbose (-v) or silent (-s)
  37. curlopts="-s"
  38.  
  39. # see if -d was given as first param
  40. [ "$1" = "-d" ] && {
  41.     debug=1;
  42.     shift;
  43. }
  44.  
  45. # memorize download link that was given on cmd line
  46. link="${1%%\?*}" # remove trailing ? paramters
  47. debug "Downloading:" "$link"
  48.  
  49. # sanity check
  50. [ -n "$link" ] || { echo "Missing url parameter."; exit 1; }
  51.  
  52. # extract json file url(s) from download link page
  53. url=`curl "$curlopts" -A "$dl_agent" "$link" | grep -m1 -o "http://.*PLUS7.*\.json"`
  54. debug "JSON url:" "$url"
  55.  
  56. # quit if we got no json file url at all
  57. [ -n "$url" ] || { echo "Empty json url."; exit 1; }
  58.  
  59. # remove 'player/' string from json url
  60. url=${url/player\//}
  61.  
  62. # extract video urls from json file
  63. urls=`curl "$curlopts" -A "$tv_agent" "$url" | tr "\"" "\n" | grep -o "http://[^\"]*HBBTV[^\"]*\.mp4"`
  64. debug "Video urls:" "$urls"
  65.  
  66. # get file sizes for each video url and print result
  67. for u in $urls
  68. do
  69.     length=`curl "$curlopts" -A "$tv_agent" -I $u | sed -n "/Content-Length:/ {s/Content-Length: *//;p;}"`
  70.     size=`human_size $length`
  71.     printf "%10s | %s\n" "$size" "$u"
  72. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement