[PYTHON] How to download youtube videos using pytube3

environment

OS: mac os x 10.15.5 python: 3.8.0 python version control: pyenv

What is pytube3

pytube is a python library that installs youtube videos. Since google has released youtube Data API, use the youtube video download function for business etc. In that case, we recommend that you do not use pytube.

pytube is a private, non-profit activity and should be used to the extent that it does not send excessive requests.

Install pytube3

If you are using python3, please install pytube3.

pip install pytube3

If you are using python2, please install pytube.


pip install pytube

Prepare a csv file with a video link inserted

youtube_links.csv


https://www.youtube.com/watch?v=-VoogELsBms
https://www.youtube.com/watch?v=cN1qnAx8tqg

Source code to install

main.py


import csv
from pytube import YouTube


def download(url, index):
    yt = YouTube(url)
    print(str(index) + "Download the second video.")
    yt.streams.filter(progressive=True, file_extension='mp4').order_by(
        'resolution').desc().first().download('./news', str(index))


with open('youtube_links.csv') as f:
    reader = csv.reader(f)
    for index, row in enumerate(reader):
        url = row[0]
        print("start download")
        download(url, index)
        print("completed download")

Run

$ python main.py

I will post the source code on github. https://github.com/SeiyaTakahashi/pytube3-project

Recommended Posts

How to download youtube videos using pytube3
Try to download Youtube videos using Pytube
How to download youtube videos with youtube-dl
I tried to search videos using Youtube Data API (beginner)
How to convert Youtube to mp3 and download it super-safely [Python]
How to install python using anaconda
How to draw a graph using Matplotlib
How to set up SVM using Optuna
How to install a package using a repository
How to set xg boost using Optuna
Automatically search and download YouTube videos with Python
How to code a drone using image recognition
youtube download memo
How to set up Random forest using Optuna
Transcription of YouTube videos using GCP's Cloud Speech-to-Text
How to deal with SessionNotCreatedException when using Selenium
How to get article data using Qiita API
How to set up Random forest using Optuna
Get information about videos uploaded to YouTube [Python]
How to display videos inline in Google Colab
How to search HTML data using Beautiful Soup
How to upload to a shared drive using pydrive
How to uninstall a module installed using setup.py
[Rails] How to get location information using Geolocation API
How to read dynamically generated table definitions using SQLAlchemy
How to write a GUI using the maya command
How to set up a Python environment using pyenv
How to scrape horse racing data using pandas read_html
How to auto-submit Microsoft Forms using python (Mac version)
[Python] How to specify the download location with youtube-dl
How to hold a hands-on seminar using Jupyter using docker
How to right click using keyboard input in RPA?
How to make a Python package using VS Code
How to download files from Selenium in Python in Chrome
How to exit when using Python in Terminal (Mac)
How to play Cyberpunk 2077 on Linux/Ubuntu 20.04 using AMD GPU
How to analyze with Google Colaboratory using Kaggle API
How to retrieve multiple arrays using slice in python.
How to execute a command using subprocess in Python
How to write faster when using numpy like deque
[Introduction to Python] How to write repetitive statements using for statements
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use virtualenv
Scraping 2 How to scrape
How to use Seaboan
How to use image-match
How to use shogun
Download images using requests
How to install Python
How to read PyPI
How to install pip
How to use Virtualenv
How to use numpy.vectorize
How to update easy_install
How to install archlinux
How to use pytest_report_header
How to restart gunicorn
How to virtual host
How to debug selenium