diff --git a/drivel.go b/drivel.go index 708e97d..e8eb5b2 100644 --- a/drivel.go +++ b/drivel.go @@ -13,6 +13,7 @@ import ( "path/filepath" "strconv" "strings" + "time" ) const ( @@ -54,11 +55,15 @@ func (r Response) Error() string { } func InitRequest(mediaType string, totalBytes int) url.Values { - return map[string][]string{ + r := map[string][]string{ "command": {"INIT"}, "media_type": {mediaType}, "total_bytes": {strconv.Itoa(totalBytes)}, } + if mediaType == "video/mp4" { + r["media_category"] = []string{"tweet_video"} + } + return r } type InitResponse struct { @@ -85,6 +90,12 @@ func FinalizeRequest(mediaID string) url.Values { type FinalizeResponse struct { Error string Media_id_string string + Processing_info ProcessingInfo +} + +type ProcessingInfo struct { + State string + Check_after_secs int64 } func UpdateStatusRequest(status string, mediaIDs []ObjectID, previousStatusID ObjectID) url.Values { @@ -176,6 +187,12 @@ func uploadFile(client *http.Client, file string) ObjectID { json.Unmarshal(body, &finalizeResponse) if id := ObjectID(finalizeResponse.Media_id_string); id != "" { fmt.Println("==> Uploaded " + file + " with id " + string(id)) + procInfo := finalizeResponse.Processing_info + if procInfo != (ProcessingInfo{}) && procInfo.Check_after_secs != 0 { + wait := procInfo.Check_after_secs * 2 + fmt.Println("Need to wait", wait, "seconds") + time.Sleep(time.Duration(wait) * time.Second) + } return id } }