lux用Go编写的快速简单的视频下载库和CLI工具

Lux


👾 Lux 是一款使用 Go 构建的快速、简单的视频下载器。

安装

先决条件

以下依赖项是必需的,必须单独安装。

注意:FFmpeg 不影响下载,仅影响最终文件合并。

通过 go install 安装

要安装 Lux,请使用 go install,或从 Releases 页面下载二进制文件。

bash 复制代码
$ go install github.com/iawia002/lux@latest

Homebrew(仅限 macOS)

对于 macOS 用户,您可以通过以下方式安装 lux

bash 复制代码
$ brew install lux

Arch Linux

对于 Arch 用户,AUR 软件包可用。

Void Linux

对于 Void Linux 用户,您可以通过以下方式安装 lux

复制代码
$ xbps-install -S lux

Windows 上的 Scoop

sh 复制代码
$ scoop install lux

Windows 上的 Chocolatey

复制代码
$ choco install lux

Windows/macOS/Linux 上的 Cask

sh 复制代码
$ cask install github.com/iawia002/lux

入门

用法:

复制代码
lux [选项] URL [URL...]

下载视频

控制台 复制代码
$ lux "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

网站:YouTube youtube.com
标题:Rick Astley - Never Gonna Give You Up (Video)
类型:视频
流媒体:
[248] -------------------
质量:1080p video/webm; codecs="vp9"
大小:63.93 MiB (67038963 字节)
# 使用以下命令下载:lux -f 248 ...

41.88 MiB / 63.93 MiB [==================>-------------] 65.51% 4.22 MiB/s 00m05s
console 复制代码
$ lux -i "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

 Site:      YouTube youtube.com
 Title:     Rick Astley - Never Gonna Give You Up (Video)
 Type:      video
 Streams:   # All available quality
     [248]  -------------------
     Quality:         1080p video/webm; codecs="vp9"
     Size:            49.29 MiB (51687554 Bytes)
     # download with: lux -f 248 ...

     [137]  -------------------
     Quality:         1080p video/mp4; codecs="avc1.640028"
     Size:            43.45 MiB (45564306 Bytes)
     # download with: lux -f 137 ...

     [398]  -------------------
     Quality:         720p video/mp4; codecs="av01.0.05M.08"
     Size:            37.12 MiB (38926432 Bytes)
     # download with: lux -f 398 ...

     [136]  -------------------
     Quality:         720p video/mp4; codecs="avc1.4d401f"
     Size:            31.34 MiB (32867324 Bytes)
     # download with: lux -f 136 ...

     [247]  -------------------
     Quality:         720p video/webm; codecs="vp9"
     Size:            31.03 MiB (32536181 Bytes)
     # download with: lux -f 247 ...

使用 lux -f stream "URL" 可以下载 -i 选项输出中列出的特定流。

下载其他内容

如果 Lux 接收到特定资源的 URL,则会直接下载:

console 复制代码
$ lux "https://img9.bcyimg.com/drawer/15294/post/1799t/1f5a87801a0711e898b12b640777720f.jpg"

lux 目前不支持此 URL,但它会尝试直接下载。

站点:Universal
标题:1f5a87801a0711e898b12b640777720f
类型:image/jpeg
流:
[默认] -------------------
大小:1.00 MiB (1051042 字节)
# 使用以下命令下载:lux -f default "URL"

1.00 MiB / 1.00 MiB [====================================] 100.00% 1.21 MiB/s 0s

下载播放列表

-p 选项下载整个播放列表而不是单个视频。

console 复制代码
$ lux -i -p "https://www.bilibili.com/bangumi/play/ep198061"

 Site:      哔哩哔哩 bilibili.com
 Title:     Doctor X 第四季:第一集
 Type:      video
 Streams:   # All available quality
     [default]  -------------------
     Quality:         高清 1080P
     Size:            845.66 MiB (886738354 Bytes)
     # download with: lux -f default "URL"


 Site:      哔哩哔哩 bilibili.com
 Title:     Doctor X 第四季:第二集
 Type:      video
 Streams:   # All available quality
     [default]  -------------------
     Quality:         高清 1080P
     Size:            930.71 MiB (975919195 Bytes)
     # download with: lux -f default "URL"

......

您可以使用 -start-end-items 选项指定列表的下载范围:

复制代码
-start
    	Playlist video to start at (default 1)
-end
    	Playlist video to end at
-items
    	Playlist video items to download. Separated by commas like: 1,5,6,8-10

仅适用于 bilibili 播放列表:

复制代码
-eto
  File name of each bilibili episode doesn't include the playlist title

多个输入

您还可以一次下载多个 URL:

console 复制代码
$ lux -i "https://www.bilibili.com/video/av21877586" "https://www.bilibili.com/video/av21990740"

 Site:      哔哩哔哩 bilibili.com
 Title:     【莓机会了】甜到虐哭的13集单集MAD「我现在什么都不想干,更不想看14集」
 Type:      video
 Streams:   # All available quality
     [default]  -------------------
     Quality:         高清 1080P
     Size:            51.88 MiB (54403767 Bytes)
     # download with: lux -f default "URL"


 Site:      哔哩哔哩 bilibili.com
 Title:     【莓救了】甜到虐哭!!!国家队单集MAD-当熟悉的bgm响起,眼泪从脸颊滑下
 Type:      video
 Streams:   # All available quality
     [default]  -------------------
     Quality:         高清 1080P
     Size:            77.63 MiB (81404093 Bytes)
     # download with: lux -f default "URL"

这些 URL 将被逐个下载。 您也可以使用 -F 选项从文件中读取 URL:

console 复制代码
$ lux -F ~/Desktop/u.txt

 Site:      微博 weibo.com
 Title:     在Google,我们设计什么? via@阑夕
 Type:      video
 Stream:
     [default]  -------------------
     Size:            19.19 MiB (20118196 Bytes)
     # download with: lux -f default "URL"

 19.19 MiB / 19.19 MiB [=================================] 100.00% 9.69 MiB/s 1s

......

您可以使用 -start-end-items 选项指定列表的下载范围:

复制代码
-start
    	File line to start at (default 1)
-end
    	File line to end at
-items
    	File lines to download. Separated by commas like: 1,5,6,8-10

恢复下载

Ctrl+C 可中断下载。

输出目录中会保留一个临时的 .download 文件。如果使用相同的参数运行 lux,则下载进度将从上一个会话恢复。

自动重试

下载失败时,lux 将自动重试,您可以使用 -retry 选项指定重试次数(默认为 100)。

Cookies

如果访问视频需要 Cookies,可以使用 -c 选项提供给 lux

Cookies 可以是以下格式或 Netscape Cookie 格式:

console 复制代码
name=value; name2=value2; ...

Cookies 可以是字符串或文本文件,通过以下两种方式之一提供 cookies。

As a string:

console 复制代码
$ lux -c "name=value; name2=value2" "https://www.bilibili.com/video/av20203945"

As a text file:

console 复制代码
$ lux -c cookies.txt "https://www.bilibili.com/video/av20203945"

Proxy

You can set the HTTP/SOCKS5 proxy using environment variables:

console 复制代码
$ HTTP_PROXY="http://127.0.0.1:1087/" lux -i "https://www.youtube.com/watch?v=Gnbch2osEeo"
console 复制代码
$ HTTP_PROXY="socks5://127.0.0.1:1080/" lux -i "https://www.youtube.com/watch?v=Gnbch2osEeo"

多线程

使用 --multi-thread-m 选项设置多线程下载单个视频。

使用 --thread-n 选项设置下载线程数(默认为 10)。

注意:如果视频包含多个片段,实际下载线程数将会增加。

例如:

  • 如果 -n 设置为 10,且视频包含 2 个片段,则实际会使用 20 个线程。
  • 如果视频包含 20 个片段,则同时只会下载 10 个片段,实际线程数为 100。

特别提示:mgtv 下载中使用过多线程会导致 HTTP 403 错误,我们建议将线程数设置为 1

短链接

bilibili

您可以直接使用 avep 编号下载 bilibili 的视频:

console 复制代码
$ lux -i ep198381 av21877586

 Site:      哔哩哔哩 bilibili.com
 Title:     狐妖小红娘:第79话 南国公主的吃货本色
 Type:      video
 Streams:   # All available quality
     [default]  -------------------
     Quality:         高清 1080P
     Size:            485.23 MiB (508798478 Bytes)
     # download with: lux -f default "URL"


 Site:      哔哩哔哩 bilibili.com
 Title:     【莓机会了】甜到虐哭的13集单集MAD「我现在什么都不想干,更不想看14集」
 Type:      video
 Streams:   # All available quality
     [default]  -------------------
     Quality:         高清 1080P
     Size:            51.88 MiB (54403767 Bytes)
     # download with: lux -f default "URL"

使用指定的 Referrer

可以使用“-r”选项为请求使用 Referrer:

console 复制代码
$ lux -r "https://www.bilibili.com/video/av20383055/" "http://cn-scnc1-dx.acgvideo.com/"

指定输出路径和名称

-o 选项设置路径,-O 选项设置下载文件的名称:

console 复制代码
$ lux -o ../ -O "hello" "https://example.com"

Debug 模式

-d 选项输出网络请求消息:

console 复制代码
$ lux -i -d "http://www.bilibili.com/video/av20088587"

URL:         http://www.bilibili.com/video/av20088587
Method:      GET
Headers:     http.Header{
    "Referer":         {"http://www.bilibili.com/video/av20088587"},
    "Accept":          {"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},
    "Accept-Charset":  {"UTF-8,*;q=0.5"},
    "Accept-Encoding": {"gzip,deflate,sdch"},
    "Accept-Language": {"en-US,en;q=0.8"},
    "User-Agent":      {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"},
}
Status Code: 200

URL:         https://interface.bilibili.com/v2/playurl?appkey=84956560bc028eb7&cid=32782944&otype=json&qn=116&quality=116&type=&sign=fb2e3f261fec398652f96d358517e535
Method:      GET
Headers:     http.Header{
    "Accept-Charset":  {"UTF-8,*;q=0.5"},
    "Accept-Encoding": {"gzip,deflate,sdch"},
    "Accept-Language": {"en-US,en;q=0.8"},
    "User-Agent":      {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"},
    "Referer":         {"https://interface.bilibili.com/v2/playurl?appkey=84956560bc028eb7&cid=32782944&otype=json&qn=116&quality=116&type=&sign=fb2e3f261fec398652f96d358517e535"},
    "Accept":          {"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},
}
Status Code: 200

 Site:      哔哩哔哩 bilibili.com
 Title:     燃油动力的遥控奥迪R8跑赛道
 Type:      video
 Streams:   # All available quality
     [default]  -------------------
     Quality:         高清 1080P
     Size:            64.38 MiB (67504795 Bytes)
     # download with: lux -f default "URL"

重复使用提取的数据

-j 选项将以 JSON 格式打印提取的数据。

console 复制代码
$ lux -j "https://www.bilibili.com/video/av20203945"

{
    "site": "哔哩哔哩 bilibili.com",
    "title": "【2018拜年祭单品】相遇day by day",
    "type": "video",
    "streams": {
        "15": {
            "urls": [
                {
                    "url": "...",
                    "size": 18355205,
                    "ext": "flv"
                }
            ],
            "quality": "流畅 360P",
            "size": 18355205
        },
        "32": {
            "urls": [
                {
                    "url": "...",
                    "size": 40058632,
                    "ext": "flv"
                }
            ],
            "quality": "清晰 480P",
            "size": 40058632
        },
        "64": {
            "urls": [
                {
                    "url": "...",
                    "size": 82691087,
                    "ext": "flv"
                }
            ],
            "quality": "高清 720P",
            "size": 82691087
        },
        "80": {
            "urls": [
                {
                    "url": "...",
                    "size": 121735559,
                    "ext": "flv"
                }
            ],
            "quality": "高清 1080P",
            "size": 121735559
        }
    }
}

Options

复制代码
  -i	Information only
  -F string
    	URLs file path
  -d	Debug mode
  -j	Print extracted data
  -s	Minimum outputs
  -v	Show version

Download:

复制代码
  -f string
    	Select specific stream to download
  -p	Download playlist
  -n int
    	The number of download thread (only works for multiple-parts video) (default 10)
  -c string
    	Cookie
  -r string
    	Use specified Referrer
  -cs int
    	HTTP chunk size for downloading (in MB) (default 1)

Network:

复制代码
  -retry int
    	How many times to retry when the download failed (default 10)

Playlist:

复制代码
  -start int
    	Playlist video to start at (default 1)
  -end int
    	Playlist video to end at
  -items string
    	Playlist video items to download. Separated by commas like: 1,5,6,8-10

Filesystem:

复制代码
  -o string
    	Specify the output path
  -O string
    	Specify the output file name

Subtitle:

复制代码
  -C	Download captions

Youku:

复制代码
  -ccode string
    	Youku ccode (default "0502")
  -ckey string
    	Youku ckey (default "7B19C0AB12633B22E7FE81271162026020570708D6CC189E4924503C49D243A0DE6CD84A766832C2C99898FC5ED31F3709BB3CDD82C96492E721BDD381735026")
  -password string
    	Youku password

aria2:

Note: 如果使用aria2下载,则需要自行合并多部分视频。

复制代码
  -aria2
    	Use Aria2 RPC to download
  -aria2addr string
    	Aria2 Address (default "localhost:6800")
  -aria2method string
    	Aria2 Method (default "http")
  -aria2token string
    	Aria2 RPC Token

支持的网站

Site URL 🎬 Videos 🌁 Images 🔊 Audio 📚 Playlist 🍪 VIP adaptation Build Status
抖音 https://www.douyin.com douyin
哔哩哔哩 https://www.bilibili.com bilibili
半次元 https://bcy.net bcy
pixivision https://www.pixivision.net pixivision
优酷 https://www.youku.com youku
YouTube https://www.youtube.com youtube
西瓜视频(头条) https://m.toutiao.com, https://v.ixigua.com, https://www.ixigua.com ixigua
爱奇艺 https://www.iqiyi.com iqiyi
新片场 https://www.xinpianchang.com xinpianchang
芒果 TV https://www.mgtv.com mgtv
糖豆广场舞 https://www.tangdou.com tangdou
Tumblr https://www.tumblr.com tumblr
Vimeo https://vimeo.com vimeo
Facebook https://facebook.com facebook
斗鱼视频 https://v.douyu.com douyu
秒拍 https://www.miaopai.com miaopai
微博 https://weibo.com weibo
Instagram https://www.instagram.com instagram
Threads https://www.threads.net threads
Twitter https://twitter.com twitter
腾讯视频 https://v.qq.com qq
网易云音乐 https://music.163.com netease
音悦台 https://yinyuetai.com yinyuetai
极客时间 https://time.geekbang.org geekbang
Pornhub https://pornhub.com pornhub
XVIDEOS https://xvideos.com xvideos
聯合新聞網 https://udn.com udn
TikTok https://www.tiktok.com tiktok
Pinterest https://www.pinterest.com pinterest
好看视频 https://haokan.baidu.com haokan
AcFun https://www.acfun.cn acfun
Eporner https://eporner.com eporner
StreamTape https://streamtape.com streamtape
虎扑 https://hupu.com hupu
虎牙视频 https://v.huya.com huya
喜马拉雅 https://www.ximalaya.com ximalaya
快手 https://www.kuaishou.com kuaishou
Reddit https://www.reddit.com reddit
VKontakte https://vk.com vk
知乎 https://zhihu.com zhihu
Rumble https://rumble.com rumble
小红书 https://xiaohongshu.com xiaohongshu
Zing MP3 https://zingmp3.vn zingmp3
Bitchute https://www.bitchute.com bitchute
Odysee https://odysee.com odysee

Known issues

优酷

优酷的 ccode 经常变化导致 lux 不可用,如果你知道有新的可用的 ccode,可以直接使用 lux -ccode ... 而不用等待 lux 更新(当然,也欢迎你给我们提一个 Pull request 来更新默认的 ccode

最好是每次下载都附带登录过的 Cookie 以避免部分 ccode 的问题

西瓜/头条视频

西瓜/头条视频必须带 Cookie 才能下载成功,西瓜和头条可共用西瓜视频的 Cookie,Cookie 的有效期可能较短,下载失败就更新 Cookie 尝试:

复制代码
$ lux -c "msToken=yoEh0-qLUq4obZ8Sfxsem_CxCo9R3NM6ViTrWaRcM1...; ttwid=1%7C..." "https://m.toutiao.com/is/iYbTfJ79/"

类似的项目

License

MIT Copyright (c) 2018-present, iawia002

关于项目

用 Go 编写的快速简单的视频下载库和 CLI 工具,支持抖音、哔哩哔哩、优酷、YouTube、爱奇艺、芒果 TV等。
MIT
Golang
30,506
3210
385
2018-02-24
2025-09-15

增长趋势 - stars