get-pytube / pytube3

A lightweight, dependency-free Python 3 library (and command-line utility) for downloading YouTube Videos.
https://pytube3.readthedocs.io
Other
178 stars 55 forks source link

HTTPError: HTTP Error 404: Not Found #103

Open chihsuanbjjh opened 4 years ago

chihsuanbjjh commented 4 years ago

I want to download video from youtube, and my code is below, but with this url "https://www.youtube.com/watch?v=XJGiS83eQLk" can work this url "https://www.youtube.com/watch?v=B5BgPWBZhvY" can't

youtube_url = "https://www.youtube.com/watch?v=B5BgPWBZhvY"
def onComplete(stream,filepath):
  global file_path,filename,filedir
  file_path = filepath
  filename = os.path.basename(filepath)
  filedir = os.path.dirname(filepath)

yt = YouTube(youtube_url)
video_title = yt.title
print(f'影片名稱為:{video_title}')

(YouTube(youtube_url,on_complete_callback=onComplete).streams
 .order_by('resolution')[0]
 .download(filename = 'tempvideo')
 )

(YouTube(youtube_url).streams
 .filter(type = 'audio')[0]
 .download(filename = 'tempaudio')
)

====================== HTTPError Traceback (most recent call last)

in () 24 .order_by('resolution')[0] 25 # .filter(subtype = 'mp4',resolution = '1080p')[0] ---> 26 .download(filename = 'tempvideo') 27 ) 28 # os.rename(file_path,os.path.join(filedir+"/"+"temp_video.mp4")) 10 frames /usr/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs) 648 class HTTPDefaultErrorHandler(BaseHandler): 649 def http_error_default(self, req, fp, code, msg, hdrs): --> 650 raise HTTPError(req.full_url, code, msg, hdrs, fp) 651 652 class HTTPRedirectHandler(BaseHandler): HTTPError: HTTP Error 404: Not Found