Last active
September 14, 2017 15:58
-
-
Save brndnblck/bb3feaff9f0a2cad2d74 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 | |
} |
Moved to wc -c
instead of stat
. Thanks @TonyNa!
Note that media_category=amplify_video
is only valid for promoted video with an Ads account. media_category=tweet_video
should be used in the majority of media upload use cases.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@brandonblack awesome. thanks )