Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions to create or delete subtitles for video files #1124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/TwitterOAuth.php
Expand Up @@ -325,6 +325,64 @@ public function mediaStatus(string $media_id)
false,
);
}

/**
* Add subtitles to an uploaded video
*
* @param string $video_id
* @param string $subtitles_id
* @param string $language_code
* @param string $language_name
*
* @return array|object
*/
public function createMediaSubtitles($video_id, $subtitles_id, $language_code='EN', $language_name='English') {
$postfields = [
"media_id" => $video_id,
"media_category" => "TweetVideo",
"subtitle_info" => [
"subtitles" => [
"media_id" => $subtitles_id,
"language_code" => strtoupper($language_code),
"display_name" => $language_name
]
]
];
return $this->http(
'POST',
self::UPLOAD_HOST,
'media/subtitles/create',
$postfields,
true
);
}

/**
* Delete subtitles from an uploaded video
*
* @param string $video_id
* @param string $language_code
*
* @return array|object
*/
public function deleteMediaSubtitles($video_id, $language_code='EN') {
$postfields = [
"media_id" => $video_id,
"media_category" => "TweetVideo",
"subtitle_info" => [
"subtitles" => [
"language_code" => strtoupper($language_code)
]
]
];
return $this->http(
'POST',
self::UPLOAD_HOST,
'media/subtitles/delete',
$postfields,
true
);
}

/**
* Private method to upload media (not chunked) to upload.twitter.com.
Expand Down