Hướng Dẫn Download Video Youtube Bằng Python

Hướng Dẫn Download Video Youtube Bằng Python

Chào các bạn, hôm nay Hieu Ham Hoc sẽ hướng dẫn các bạn cách download video trên YouTube bằng python nhé, nào chúng ta bắt đầu thôi:

CÁCH 1:

from pytube import YouTube

#Hiện thông báo để dán link muốn download
link = input(“Enter the link of YouTube video you want to download: “)
yt = YouTube(link)

#In các thông tin của video
print(“Title: “,yt.title)
print(“Number of views: “,yt.views)
print(“Length of video: “,yt.length)
print(“Rating of video: “,yt.rating)

#Chất lượng của video
ys = yt.streams.get_highest_resolution()

#Thông báo tiến trình download
print(“Đang tải về”)
ys.download()
print(“Hoàn thành.”)

CÁCH 2:

from pytube import YouTube

#ask for the link from user
link = input(“Enter the link of YouTube video you want to download: “)
yt = YouTube(link)

#Showing details
print(“Title: “,yt.title)
print(“Number of views: “,yt.views)
print(“Length of video: “,yt.length)
print(“Rating of video: “,yt.rating)
#Getting the highest resolution possible
ys = yt.streams.get_highest_resolution()

#Starting download
print(“Downloading…”)
ys.download()
print(“Download completed!!”)

Lưu ý:

  • Cài thư viện: pip install pytube3
  • Sau đó upgrade pytube: pip install –upgrade pytube3
  • Video được download ngay thư mục hiện tại của file code.