title: Python, Youtube-video-downloader-merger Can i inproove this script run faster?
body: <p>I created script which one downloading video and sound from Youtube, and after that merging sound and video with ffmpeg, i wondering is another way to make same result but in faster way?  Because this script takes about 7 min ~ depends on Video quality and duration. My code bellow:</p>
  
  <pre><code>from pytube import YouTube
  import sys
  import ffmpeg
  import os
  
  
  class Downloader(YouTube):
  
      def __init__(self, link):
          self.link = YouTube(link)
          self.hq = []
          self.best_video = []
          self.best_sound = []
  
  
      def stream_objects(self):
          q = [self.hq.append(x) for x in self.link.streams.all()]
          self.best_video.append(str(self.hq[1]).split()[1].split('\"')[1])
          self.best_sound.append(str(self.hq[-1]).split()[1].split('\"')[1])
          return self.best_video, self.best_sound
  
      def downloady(self):
          vid = self.link.streams.get_by_itag(str(self.best_video).strip("['']"))
          audio = self.link.streams.get_by_itag(str(self.best_sound).strip("['']"))
          self.vid_title = (f"{vid.title}"+".mp4")
  
          vid.download(filename='video')
          audio.download(filename='audio')
          print('Downloaded, Now Starting Merge \n\n\n\n\n')
          print(f'{self.vid_title}'+'\n')
  
      def merge(self):
          ffmpeg.output(ffmpeg.input('video.mp4'), ffmpeg.input('audio.webm'), self.vid_title).run()
          os.remove('video.mp4')
          os.remove('audio.webm')
  
  
  
  if __name__=='__main__':
      a = Downloader(link = sys.argv[1])
      a.stream_objects()
      a.downloady()
      a.merge()
  </code></pre>
  
  <p>OKE UPDATE:
  Now code looks like that..Second problem is slow downloading mp4 files from YouTube server, i have 10Gb/s internet. Good connection with YT servers, but why so poor downloading ? ? ? :)</p>
  
  <pre><code>from pytube import YouTube
  import sys
  import ffmpeg
  import os 
  import subprocess
  
  class Downloader(YouTube):
  
      def __init__(self, link):
          self.link = YouTube(link)
          self.hq = []
  
  
      def stream_objects(self):
          self.best = self.link.streams.filter(file_extension='mp4')
          q = [self.hq.append(x) for x in self.best.all()]
          self.best_vid_itag = str(self.best.all()[1]).split()[1].split('\"')[1]
          self.best_audio_itag = str(self.best.all()[-1]).split()[1].split('\"')[1]
  
      def downloader(self):
          vid = self.link.streams.get_by_itag(self.best_vid_itag)
          aud = self.link.streams.get_by_itag(self.best_audio_itag)
          print('Donwloading Video file...\n')
          vid.download(filename='video')
          print('Video file downloaded... Now Trying download Audio file..\n')
          aud.download(filename='audio')
          print('Audio file downloaded... Now Trying to merge audio and video files...\n')
  
      def merger(self):
          lin = str(self.link.title).rstrip()
          lin2 = (lin+'.mp4')
          subprocess.run(f'ffmpeg -i video.mp4 -i audio.mp4 -c copy "{lin2}"', shell=True)
          os.remove('video.mp4')
          os.remove('audio.mp4')
          print('Done....\n')
  
  if __name__=='__main__':
      a = Downloader(link = sys.argv[1])
      a.stream_objects()
      a.downloader()
      a.merger()
  </code></pre>