Skip to content

Add long-form post (CreateNoteTweet) + video upload support#62

Open
rakei076 wants to merge 1 commit into
public-clis:mainfrom
rakei076:main
Open

Add long-form post (CreateNoteTweet) + video upload support#62
rakei076 wants to merge 1 commit into
public-clis:mainfrom
rakei076:main

Conversation

@rakei076
Copy link
Copy Markdown

  • 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).
Copilot AI review requested due to automatic review settings May 27, 2026 09:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() to CreateNoteTweet when needed.
  • Extend CLI post command 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 thread twitter_cli/client.py
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)
Comment thread twitter_cli/client.py
try:
finalize_result = json.loads(resp.text)
except (json.JSONDecodeError, ValueError):
finalize_result = {}
Comment thread twitter_cli/client.py
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
Comment thread twitter_cli/client.py
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 撑爆请求
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants