title: 五分鐘you-get入門
date: 2022-02-19 14:00:00
categories: python
description: python you-get
1. You-Get介紹
命令行程序,為下載網(wǎng)絡(luò)上的媒體信息提供便利。
2. 用途
- 下載流行網(wǎng)站之音視頻,例如
YouTube、Youku、Niconico等。 - 于您心儀的媒體播放器中觀看在線視頻,脫離瀏覽器與廣告
- 下載您喜歡的網(wǎng)頁(yè)上的圖片
- 下載任何非 HTML 內(nèi)容,例如二進(jìn)制文件
3. 安裝升級(jí)
安裝方法有很多,這里只說(shuō)明以 Python 環(huán)境,并且 pip / pip3 為介紹。
- 安裝
C:\Users\WONGS>pip3 install you-get
- 升級(jí)
C:\Users\WONGS>pip3 install --upgrade you-get
4. 參數(shù)列表
4.1. 可選參數(shù)
| 參數(shù) | 描述 |
|---|---|
| -V, --version | 查看版本并退出 |
| -h, --help | 查看幫助信息 |
4.2. 不影響使用的選項(xiàng)
| 參數(shù) | 描述 |
|---|---|
| -i, --info | 查看頁(yè)面視頻信息 |
| -u, --url | 查看頁(yè)面視頻信息包括解析的url地址 |
| --json | 以json格式查看頁(yè)面視頻信息 |
4.3. 下載選項(xiàng)
| 參數(shù) | 描述 |
|---|---|
| -n, --no-merge | 不合并視頻 |
| --no-caption | 不下載字幕 |
| -f, --force | 強(qiáng)制覆蓋現(xiàn)有文件 |
| -F STREAM_ID, --format STREAM_ID | 指定視頻的格式 |
| -O FILE, --output-filename FILE | 指定下載的文件名稱 |
| -o DIR, --output-dir DIR | 指定下載文件的目錄 |
| -p PLAYER, --player PLAYER | 把視頻流輸出到指定的播放器 |
| -c COOKIES_FILE, --cookies COOKIES_FILE | 加載cookie文件 |
| -t SECONDS, --timeout SECONDS | 設(shè)置超時(shí)時(shí)間 |
| -d, --debug | 顯示跟蹤、調(diào)試信息 |
| -I FILE, --input-file FILE | 從文件讀取url列表 |
| -P PASSWORD, --password PASSWORD | 指定加密視頻的密碼 |
| -l, --playlist | 顯示可以下載的列表 |
| -a, --auto-rename | 自動(dòng)重命名相同的名稱不同的文件 |
4.4. 代理選項(xiàng)
| 參數(shù) | 描述 |
|---|---|
| -x HOST:PORT, --http-proxy HOST:PORT | 使用http代理下載 |
| -y HOST:PORT, --extractor-proxy HOST:PORT | 僅抓取數(shù)據(jù)時(shí)使用http代理 |
| --no-proxy | 關(guān)閉代理 |
| -s HOST:PORT, --socks-proxy HOST:PORT | 使用socks5代理進(jìn)行下載 |
5. 入門
5.1. 下載視頻
下載視頻之前,可以用 -i 查看所有可用畫(huà)質(zhì)與格式,方便我們自己根據(jù)需要選擇。
C:\Users\WONGS>you-get -i https://www.youtube.com/watch?v=Uoa3m1j5PgA
site: YouTube
title: Beijing 2022 Olympic Winter Games Opening Ceremony | Beijing 2022
streams: # Available quality and codecs
[ DASH ] ____________________________________
- itag: 136
container: mp4
quality: 1280x720 (720p)
size: 1932.5 MiB (2026328465 bytes)
# download-with: you-get --itag=136 [URL]
- itag: 247
container: webm
quality: 1280x720 (720p)
size: 1415.6 MiB (1484314406 bytes)
# download-with: you-get --itag=247 [URL]
- itag: 135
container: mp4
quality: 854x480 (480p)
size: 1074.5 MiB (1126707395 bytes)
# download-with: you-get --itag=135 [URL]
- itag: 244
container: webm
quality: 854x480 (480p)
size: 791.8 MiB (830242418 bytes)
# download-with: you-get --itag=244 [URL]
- itag: 134
container: mp4
quality: 640x360 (360p)
size: 640.3 MiB (671439244 bytes)
# download-with: you-get --itag=134 [URL]
- itag: 243
container: webm
quality: 640x360 (360p)
size: 505.3 MiB (529846456 bytes)
# download-with: you-get --itag=243 [URL]
- itag: 133
container: mp4
quality: 426x240 (240p)
size: 373.3 MiB (391437550 bytes)
# download-with: you-get --itag=133 [URL]
- itag: 242
container: webm
quality: 426x240 (240p)
size: 343.8 MiB (360489245 bytes)
# download-with: you-get --itag=242 [URL]
- itag: 160
container: mp4
quality: 256x144 (144p)
size: 244.3 MiB (256160530 bytes)
# download-with: you-get --itag=160 [URL]
- itag: 278
container: webm
quality: 256x144 (144p)
size: 236.6 MiB (248121107 bytes)
# download-with: you-get --itag=278 [URL]
[ DEFAULT ] _________________________________
- itag: 22
container: mp4
quality: hd720
size: 1931.3 MiB (2025107647 bytes)
# download-with: you-get --itag=22 [URL]
- itag: 18
container: mp4
quality: medium
# download-with: you-get --itag=18 [URL]
[ DEFAULT ] _________________________________ 為默認(rèn)畫(huà)質(zhì),默認(rèn)選項(xiàng)的畫(huà)質(zhì)為最高畫(huà)質(zhì),,不選畫(huà)質(zhì)的話就是以這個(gè)為默認(rèn)選擇的。
C:\Users\WONGS>you-get -o F:\YouGet https://www.youtube.com/watch?v=Uoa3m1j5PgA --itag=160
site: YouTube
title: Beijing 2022 Olympic Winter Games Opening Ceremony | Beijing 2022
stream:
- itag: 160
container: mp4
quality: 256x144 (144p)
size: 244.3 MiB (256160530 bytes)
# download-with: you-get --itag=160 [URL]
Downloading Beijing 2022 Olympic Winter Games Opening Ceremony - Beijing 2022.mp4 ...
0.0% ( 0.0/244.3MB) ├────────────────────────────────────────┤[1/2]
-
-o: 下載目錄,后面為路徑 -
--itag=160: 指定需要的視頻畫(huà)質(zhì),其他參數(shù)可以查看上一章節(jié)。
5.2. 加載cookie
如果資源需要登錄才能查看,嘗試將瀏覽器 cookie 通過(guò) -c 加入,根據(jù)官方說(shuō)明,目前只支持兩種 cookie 格式 Mozilla cookies.sqlite 、 Netscape cookies.txt。