예제 #1
0
    def download_video(self, queue: YoutubeQueue):
        # Download audio part
        default_audio_name = "audio"
        audio_file = queue.save_location + "\\" + default_audio_name
        output_file_path = audio_file + '.%(ext)s'
        ydl_opts = self.build_audio_fragment_download_options(output_file_path)
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([queue.link])
            result = ydl.extract_info("{}".format(queue.link))
            queue.audio_dl_stats = copy.deepcopy(self.download_stats)

        # Download video part (has no sound)
        default_video_name = "video"
        video_file = queue.save_location + "\\" + default_video_name
        output_file_path = video_file + '.%(ext)s'
        ydl_opts = self.build_video_fragment_download_options(output_file_path)
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([queue.link])
            result = ydl.extract_info("{}".format(queue.link))
            queue.video_dl_stats = copy.deepcopy(self.download_stats)

        # Replace tags from file_name by its values from queue.video_dl_stats
        queue.replace_file_name_tags()

        # Merge audio and video parts to single file
        audio_file = default_audio_name + "." + constants.M4A
        video_file_extension = File.get_file_name_with_extension(queue.save_location, default_video_name).split(".")[-1]
        video_file = default_video_name + "." + video_file_extension

        merged_file = queue.file_name + "." + queue.save_format
        Ffmpeg.merge_audio_and_video(queue.save_location, audio_file, video_file, merged_file)