Skip to content

Instantly share code, notes, and snippets.

@chaeplin
Forked from brndnblck/video_upload.sh
Created April 24, 2016 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaeplin/3c7409ed80acbdedd7a823eb142238d7 to your computer and use it in GitHub Desktop.
Save chaeplin/3c7409ed80acbdedd7a823eb142238d7 to your computer and use it in GitHub Desktop.
Script for Resumable Media Uploads to Twitter
function video-upload() {
if [ $# -lt 1 ]; then
echo "[ERROR] Missing required file name."
else
FILESIZE=$(wc -c "$1" | awk '{print $1}')
printf "[START] Uploading $FILESIZE bytes.\n"
MEDIAID=$(twurl /1.1/media/upload.json -H upload.twitter.com -d "command=INIT&media_category=amplify_video&media_type=video/mp4&total_bytes=$FILESIZE" | jq .media_id_string | sed 's/\"//g')
INDEX=0
split -b 5m $1 twitter-video-
for FILE in twitter-video-*; do
echo "[INFO] Uploading segment $INDEX ($FILE)..."
twurl "/1.1/media/upload.json" -H upload.twitter.com -d "command=APPEND&segment_index=$INDEX&media_id=$MEDIAID" --file-field "media" --file "$FILE"
INDEX=$((INDEX + 1))
done
rm twitter-video-*
twurl "/1.1/media/upload.json" -H upload.twitter.com -d "command=FINALIZE&media_id=$MEDIAID" && printf "\n"
printf "[DONE] $MEDIAID"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment