Add long-form post (CreateNoteTweet) + video upload support#62
Open
rakei076 wants to merge 1 commit into
Open
Conversation
rakei076
commented
May 27, 2026
- client.py: extend upload_media() to handle videos (mp4/mov, up to 512MB): multi-segment APPEND + STATUS polling until server-side transcode completes; also adds CreateNoteTweet GraphQL endpoint for posts > 280 weighted chars.
- cli.py: add --video / -V option to post command (mutually exclusive with --image).
- client.py: extend upload_media() to handle videos (mp4/mov, up to 512MB): multi-segment APPEND + STATUS polling until server-side transcode completes; also adds CreateNoteTweet GraphQL endpoint for posts > 280 weighted chars. - cli.py: add --video / -V option to post command (mutually exclusive with --image).
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds video upload support and automatic routing to long-form “Note Tweet” creation when tweet text exceeds the normal character limit.
Changes:
- Extend
upload_media()to support MP4/MOV uploads with chunked APPEND and STATUS polling. - Add a weighted-length heuristic and route
create_tweet()/quote_tweet()toCreateNoteTweetwhen needed. - Extend CLI
postcommand with--video/-V(mutually exclusive with--image).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| twitter_cli/client.py | Adds video media upload flow and long-form tweet routing via CreateNoteTweet. |
| twitter_cli/cli.py | Adds --video flag to upload a video and post it in a tweet. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+552
to
+561
| media_data = base64.b64encode(chunk).decode("ascii") | ||
| headers = self._build_headers(url=upload_url, method="POST") | ||
| headers.pop("Content-Type", None) | ||
| append_data = { | ||
| "command": "APPEND", | ||
| "media_id": media_id, | ||
| "segment_index": str(segment_index), | ||
| "media_data": media_data, | ||
| } | ||
| resp = session.post(upload_url, headers=headers, data=append_data, timeout=180) |
| try: | ||
| finalize_result = json.loads(resp.text) | ||
| except (json.JSONDecodeError, ValueError): | ||
| finalize_result = {} |
Comment on lines
+642
to
+655
| @staticmethod | ||
| def _weighted_length(text): | ||
| # type: (str) -> int | ||
| """Return X's weighted character count for a tweet. | ||
|
|
||
| X counts basic ASCII characters as 1 and most other characters (CJK, | ||
| emoji, etc.) as 2. The standard tweet limit is 280 weighted units; | ||
| anything above must go through the CreateNoteTweet endpoint (X | ||
| Premium long-form post). | ||
| """ | ||
| n = 0 | ||
| for ch in text: | ||
| n += 1 if ord(ch) < 0x80 else 2 | ||
| return n |
| raise MediaUploadError("APPEND failed (HTTP %d): %s" % (resp.status_code, resp.text[:300])) | ||
| logger.info("Media APPEND: segment 0 uploaded") | ||
| if is_video: | ||
| # 视频分多段(4 MB / segment),避免大块 base64 撑爆请求 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.