upload_with_curl.sh 586 B

1234567891011121314151617
  1. #!/bin/bash
  2. #
  3. # Upload videos to youtube using youtube-upload and curl.
  4. #
  5. # $ youtube-upload --get-upload-form-info ... | upload_with_curl.sh [CURL_OPTIONS]
  6. #
  7. set -e
  8. debug() { echo "$@" >&2; }
  9. while { read FILE; read TOKEN; read POST_URL; }; do
  10. URL="$POST_URL?nexturl=http://code.google.com/p/youtube-upload"
  11. VIDEO_ID=$(curl --include -F "token=$TOKEN" -F "file=@$FILE" "$@" "$URL" |
  12. grep -m1 "^Location: " | grep -o "id=[^&]\+" | cut -d"=" -f2-)
  13. test "$VIDEO_ID" || { debug "Error uploading"; exit 1; }
  14. echo "http://www.youtube.com/watch?v=$VIDEO_ID"
  15. done