Package blue.starry.penicillin.endpoints.media

Types

Link copied to clipboard
enum MediaCategory : Enum<MediaCategory> , EnumRequestParameter

Represents media category.

Link copied to clipboard
data class MediaComponent(    val data: ByteArray,     val type: MediaType,     val category: MediaCategory)

Represents media data.

Link copied to clipboard
enum MediaType : Enum<MediaType>

Represents media type.

Functions

Link copied to clipboard
fun Media.createMetadata(    mediaId: Long,     payload: JsonObject,     vararg options: Option): EmptyApiAction

This endpoint can be used to provide additional information about the uploaded media_id. This feature is currently only supported for images and GIFs. The request flow should be:

Link copied to clipboard
fun Media.createSubtitles(payload: JsonObject, vararg options: Option): ApiRequest

Use this endpoint to associate uploaded subtitles to an uploaded video. You can associate subtitles to video before or after Tweeting. Request flow for associating subtitle to video before the video is Tweeted : 1. Upload video using the chunked upload endpoint and get the video media_id. 2. Upload subtitle using the chunked upload endpoint with media category set to “Subtitles” and get the subtitle media_id. 3. Call this endpoint to associate the subtitle to the video. 4. Create Tweet with the video media_id. Request flow for associating subtitle to video after the video is Tweeted : 1. Upload video using the chunked upload endpoint and get the video media_id. 2. Create Tweet with the video media_id. 3. Upload subtitle using the chunked upload endpoint with media category set to SUBTITLES and get the subtitle media_id. 4. Call this endpoint to associate the subtitle to the video.

Link copied to clipboard
fun Media.deleteSubtitles(payload: JsonObject, vararg options: Option): ApiRequest

Use this endpoint to dissociate subtitles from a video and delete the subtitles. You can dissociate subtitles from a video before or after Tweeting.

Link copied to clipboard
fun Media.uploadAppend(    media: MediaComponent,     mediaId: Long,     segmentIndex: Int,     mediaKey: String? = null,     vararg options: Option): EmptyApiAction

The APPEND command is used to upload a chunk (consecutive byte range) of the media file. For example, a 3 MB file could be split into 3 chunks of size 1 MB, and uploaded using 3 APPEND command requests. After the entire file is uploaded, the next step is to call the FINALIZE command. There are a number of advantages of uploading a media file in small chunks:

Link copied to clipboard
fun Media.uploadFinalize(    mediaId: Long,     mediaKey: String? = null,     vararg options: Option): JsonObjectApiAction<Media>

The FINALIZE command should be called after the entire media file is uploaded using APPEND commands. If and (only if) the response of the FINALIZE command contains a processing_info field, it may also be necessary to use a STATUS command and wait for it to return success before proceeding to Tweet creation.

Link copied to clipboard
fun Media.uploadInit(    totalBytes: Int,     mediaType: MediaType,     mediaCategory: MediaCategory = MediaCategory.Default,     additionalOwners: List<Long>? = null,     vararg options: Option): JsonObjectApiAction<Media>

The INIT command request is used to initiate a file upload session. It returns a media_id which should be used to execute all subsequent requests. The next step after a successful return from INIT command is the APPEND command. See the Uploading media guide for constraints and requirements on media files.

Link copied to clipboard
fun Media.uploadMedia(media: MediaComponent): ApiAction<Media>

Use this endpoint to upload images to Twitter. It returns a media_id which can be used in most Twitter endpoints that accept images. For example, a media_id value can be used to create a Tweet with an attached photo using the POST statuses/update endpoint. This is a simple image upload endpoint, with a limited set of features. The preferred alternative is the chunked upload endpoint which supports both images and videos, provides better reliability, allows resumption of file uploads, and other important features. In the future, new features will only be supported for the chunked upload endpoint.

Link copied to clipboard
fun Media.uploadStatus(    mediaId: Long,     mediaKey: String? = null,     vararg options: Option): JsonObjectApiAction<Media>

The STATUS command is used to periodically poll for updates of media processing operation. After the STATUS command response returns succeeded, you can move on to the next step which is usually create Tweet with media_id.