ljg-x-download
ljg-x-download
從 X (Twitter) 連結下載圖片或影片到 ~/Downloads。
依賴
yt-dlp(已安裝)
執行流程
1. 解析輸入
從使用者輸入中提取 X/Twitter URL。支援的格式:
https://x.com/user/status/123456https://twitter.com/user/status/123456https://mobile.twitter.com/user/status/123456- 帶查詢引數的 URL(yt-dlp 自動處理
?s=20等追蹤引數)
縮短連結(t.co)先解析:curl -Ls -o /dev/null -w '%{url_effective}' "SHORT_URL"
如果使用者沒有提供 URL,用 AskUserQuestion 要求提供。
2. 嘗試直接下載(影片優先)
直接用 yt-dlp 下載,無需先探測:
yt-dlp -o "~/Downloads/%(uploader)s_%(id)s.%(ext)s" "URL"
如果成功(影片推文),完成。跳到步驟 4 彙報結果。
3. 影片下載失敗時,提取圖片
yt-dlp 對純圖片推文可能報錯。此時用 --dump-json 提取圖片 URL:
yt-dlp --dump-json "URL" 2>&1
判斷結果:
- JSON 中有
thumbnails陣列 → 提取圖片 URL - JSON 為空或報錯
no video→ 推文無媒體,告知使用者"該推文不包含可下載的圖片或影片" - 報錯含
login/authentication→ 需要登入(見故障排除) - 其他錯誤 → 報告具體錯誤資訊
圖片下載:
從 JSON 的 thumbnails 陣列提取所有圖片 URL,替換 name=small 或 name=medium 為 name=orig 獲取原圖,然後逐一下載:
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"
副檔名跟隨 URL 中的 format 引數(jpg/png/webp)。
4. 彙報結果
下載完成後,用 ls -lh 列出已下載的檔案:檔名、大小、路徑。
故障排除
需要登入
yt-dlp 報錯含 login / Sign in / age-restricted 時,加 --cookies-from-browser chrome:
yt-dlp --cookies-from-browser chrome -o "~/Downloads/%(uploader)s_%(id)s.%(ext)s" "URL"
推文無媒體
純文字推文沒有可下載的媒體。告知使用者即可。
More from yelban/ljg-skills.tw
ljg-card
Content caster (鑄). Transforms content into PNG visuals. Six molds: -l (default) long reading card, -i infograph, -m multi-card reading cards (1080x1440), -v visual sketchnote, -c comic (manga-style B&W), -w whiteboard (marker-style board layout). Output to ~/Downloads/. Use when user says '鑄', 'cast', '做成圖', '做成卡片', '做成資訊圖', '做成海報', '視覺筆記', 'sketchnote', '漫畫', 'comic', 'manga', '白板', 'whiteboard'. Replaces ljg-cards and ljg-infograph.
5ljg-word
Deep-dive English word mastery tool. Deconstructs a single English word into core semantics and epiphany. Use when user asks to explain/master a specific English word.
5ljg-rank
給一個領域,找出背後真正撐著它的幾根獨立的力。十幾個現象砍到不可再少的生成器——砍完能把現象一個個生回來,才算數。Use when user says '降秩', '找秩', '秩是什麼', '這個領域靠什麼撐著', '背後是什麼', or wants to decompose any domain to its irreducible generators.
5ljg-writes
寫作引擎。帶著一個觀點出發,在寫的過程中把它想透。
5ljg-plain
Cognitive atom: Plain (白). Rewrites any content so a smart 12-year-old groks it. Structure-free — form follows content. Use when user says '白話說', '說人話', '解釋一下', 'plain', 'grok'.
5ljg-travel
Deep travel research workflow for museums and ancient architecture. Input a city name, auto-generates structured knowledge document (org-mode) + portable reference cards (PNG). Covers historical background, museum highlights, archaeological significance, and architectural heritage. Use when user says '旅行研究', '博物館功課', '古建功課', 'travel research', '出發前功課', or provides a city name with intent to do deep cultural travel preparation.
5