ljg-x-download

Original🇨🇳 Chinese
Translated

Download images and videos from X (Twitter) posts to ~/Downloads. Use when user shares an X/Twitter link and wants to save media, or says '下载', 'download', '保存图片', '保存视频', or provides a x.com/twitter.com URL with intent to download media.

5installs
Added on

NPX Install

npx skill4agent add lijigang/ljg-skills ljg-x-download

SKILL.md Content (Chinese)

View Translation Comparison →

ljg-x-download

Download images or videos from X (Twitter) links to ~/Downloads.

Dependencies

  • yt-dlp
    (already installed)

Execution Steps

1. Parse Input

Extract the X/Twitter URL from user input. Supported formats:
  • https://x.com/user/status/123456
  • https://twitter.com/user/status/123456
  • https://mobile.twitter.com/user/status/123456
  • URLs with query parameters (yt-dlp automatically handles tracking parameters like
    ?s=20
    )
Resolve shortened links (t.co) first:
curl -Ls -o /dev/null -w '%{url_effective}' "SHORT_URL"
If the user does not provide a URL, use AskUserQuestion to request it.

2. Attempt Direct Download (Video Priority)

Download directly with yt-dlp without prior detection:
bash
yt-dlp -o "~/Downloads/%(uploader)s_%(id)s.%(ext)s" "URL"
If successful (video tweet), the process is complete. Proceed to step 4 to report the result.

3. Extract Images When Video Download Fails

yt-dlp may throw errors for image-only tweets. In this case, use
--dump-json
to extract image URLs:
bash
yt-dlp --dump-json "URL" 2>&1
Result Judgment:
  • If the JSON contains a
    thumbnails
    array → Extract image URLs
  • If the JSON is empty or throws a
    no video
    error → The tweet has no media, inform the user: "This tweet does not contain downloadable images or videos"
  • If the error contains
    login
    /
    authentication
    → Login is required (see Troubleshooting)
  • Other errors → Report the specific error message
Image Download:
Extract all image URLs from the
thumbnails
array in the JSON, replace
name=small
or
name=medium
with
name=orig
to get the original image, then download them one by one:
bash
curl -L -o ~/Downloads/tweet_ID_1.jpg "https://pbs.twimg.com/media/xxx?format=jpg&name=orig"
curl -L -o ~/Downloads/tweet_ID_2.jpg "https://pbs.twimg.com/media/yyy?format=jpg&name=orig"
The file extension follows the
format
parameter in the URL (jpg/png/webp).

4. Report Results

After downloading is complete, use
ls -lh
to list the downloaded files: file name, size, and path.

Troubleshooting

Login Required

When yt-dlp reports errors containing
login
/
Sign in
/
age-restricted
, add
--cookies-from-browser chrome
:
bash
yt-dlp --cookies-from-browser chrome -o "~/Downloads/%(uploader)s_%(id)s.%(ext)s" "URL"

No Media in Tweet

Text-only tweets have no downloadable media. Simply inform the user.