title: pytube urllib.error.HTTPError: HTTP Error 404: Not Found
body: <p>I tried to create a script to download a Youtube video. Sometime it works but sometime it comes out with a 'HTTP Error 404' error. Below is the code:</p>
  <p>/*** A001MainMenu.py ***/</p>
  <pre><code>from C001Youtube import C001_YouTube
  
  vlink = input(&quot;Enter the link: &quot;)
  fer = &quot;D:\ABC\Youtube&quot;
  
  video = C001_YouTube(vlink, fer, None)
  C001_YouTube.DVideo(video, vlink, fer, None)
  </code></pre>
  <p>/*** C001YouTube.py ***/</p>
  <pre><code>from pytube import YouTube
  from pytube import extract
  import ffmpeg
  
  class C001_YouTube:
  
      def __init__(self, video_link, folder, maxres):
          self.video_link = video_link
          self.folder = folder
          self.maxres = maxres
  
      def checkfilename(self, filename):
          deletechars = &quot;\&quot;&quot; + '&quot;' + &quot;\\&quot; + &quot;/:*?&lt;&gt;|&quot;
          print(deletechars)
          for c in deletechars:
              filename = filename.replace(c, '')
          return filename
  
      def setfilename(self, video_link):
          filename = extract.video_id(video_link) + &quot;_&quot; + YouTube(video_link).title
          fname = self.checkfilename(filename)
          return fname
  
      def DVideo(self, video_link, folder, maxres=None):
          video_name = self.setfilename(video_link)
          print(video_name)
          if maxres is None:
              print(&quot;Video Started 2&quot;)
              video_file = YouTube(self.video_link).streams.order_by('resolution').desc().first().download()
              print(&quot; Video Done 1&quot;)
  
          else:
              print(&quot;Video Started 3&quot;)
              video_file = YouTube(self.video_link).streams.filter(res=maxres).order_by('resolution').desc().first().download()
              print(&quot;Video Done 2&quot;)
  
          print(&quot;Audio Started&quot;)
          audio_file = YouTube(self.video_link).streams.filter(only_audio=True).order_by('abr').desc().first().download(filename_prefix=&quot;audio_&quot;)
          print(&quot;Audio Done&quot;)
  
          source_audio = ffmpeg.input(audio_file)
          source_video = ffmpeg.input(video_file)
  
          print(&quot;Concatenation Started&quot;)
          ffmpeg.concat(source_video, source_audio, v=1, a=1).output(f&quot;{folder}\{video_name}.mp4&quot;).run()
          print(&quot;Concatenation Done&quot;)
  
          return None
  </code></pre>
  <p>Below is a sample video link that works: <a href="https://www.youtube.com/watch?v=bH7dRlbEDJY" rel="nofollow noreferrer">https://www.youtube.com/watch?v=bH7dRlbEDJY</a>
  Below is a sample video link that is not worked (Error 404): <a href="https://www.youtube.com/watch?v=DjbhQJhXfs8" rel="nofollow noreferrer">https://www.youtube.com/watch?v=DjbhQJhXfs8</a></p>
  <p>It would be grateful if someone can give me a hand to understand why sometime the code is working and sometime isn't. Thanks a lot in advance.</p>