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
Sourcelijigang/ljg-skills
Added on
NPX Install
npx skill4agent add lijigang/ljg-skills ljg-x-downloadTags
Translated version includes tags in frontmatterSKILL.md Content (Chinese)
View Translation Comparison →ljg-x-download
Download images or videos from X (Twitter) links to ~/Downloads.
Dependencies
- (already installed)
yt-dlp
Execution Steps
1. Parse Input
Extract the X/Twitter URL from user input. Supported formats:
https://x.com/user/status/123456https://twitter.com/user/status/123456https://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 to extract image URLs:
--dump-jsonbash
yt-dlp --dump-json "URL" 2>&1Result Judgment:
- If the JSON contains a array → Extract image URLs
thumbnails - If the JSON is empty or throws a error → The tweet has no media, inform the user: "This tweet does not contain downloadable images or videos"
no video - If the error contains /
login→ Login is required (see Troubleshooting)authentication - Other errors → Report the specific error message
Image Download:
Extract all image URLs from the array in the JSON, replace or with to get the original image, then download them one by one:
thumbnailsname=smallname=mediumname=origbash
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 parameter in the URL (jpg/png/webp).
format4. Report Results
After downloading is complete, use to list the downloaded files: file name, size, and path.
ls -lhTroubleshooting
Login Required
When yt-dlp reports errors containing / / , add :
loginSign inage-restricted--cookies-from-browser chromebash
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.