본문 바로가기
python

파이썬 유튜브 영상 다운로드

by 타닥타닥 토다토닥 부부 2024. 6. 26.
반응형

파이썬 유튜브 영상 다운로드

아래 링크 pytube 수정 버전 pytubefix를 이용해 주세요 ! 

 

HTTPError: HTTP Error 400: Bad Request pytube

HTTPError: HTTP Error 400: Bad Request pytube유튜브 다운과정에서 위와 같은 에러가 나오면 아래 코드로 실행해 보세요 # pytubefix 설치#pip install pytubefix# 패키지 불러오기from pytubefix import YouTubefrom pytube

noanomal.tistory.com


파이썬 코드를 이용해서 유튜브 url을 이용하여 다운로드 받는 코드를 작성합니다.

 

1. pytube 패키지 다운로드

!pip install pytube

 

 

2. 파이썬 코드

# 패키지 불러오기
import os
from pytube import YouTube

# 유튜브 url 입력
url = 'https://www.youtube.com/watch?v=2ixHoADCvlg'

# 비디오 파일이 다운로드 될 디렉션 입력
direction = "direction"

# 파일 다운을 위한 객체 생성
you = YouTube(url)
you = you.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()

# 파일 디렉션 유무 확인 후 있으면 유지 없으면 새로 만듦
os.makedirs(direction, exist_ok=True)

# url 영상 다운로드
you.download(direction)

 

3. 코드 작성이 후 아래와 같이 "direction"폴더 아래 파일 저장

 

 

반응형

댓글