---
# System prepended metadata

title: 批量下載 youtube 影片
tags: [Python]

---

###### tags: `Python`
# 批量下載 youtube 影片
```cmd
pip install pytube
```

```python=
from pytube import YouTube

# 放入所有要下載影片的網址
video_name = ['https://www.youtube.com/watch?','https://www.youtube.com/']
j = 0
for i in video_name:
    # 建立 YouTube 物件
    yt = YouTube(video_name[j])
    # 影片標題
    print(yt.title)

    # 篩選 progressive 類型的 MP4 影片格式
    progMP4 = yt.streams.filter(progressive=True, file_extension='mp4')

    # 找出解析度最好的 MP4 影片
    targetMP4 = progMP4.order_by('resolution').desc().first()

    # 下載影片並儲存至 /tmp/youtube_dl 目錄
    video_file = targetMP4.download("C:\\Users\Admin\Desktop\movie")
    j+=1

```