-
-
Save chaeplin/3c7409ed80acbdedd7a823eb142238d7 to your computer and use it in GitHub Desktop.
Script for Resumable Media Uploads to Twitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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