S
S
Setaz2132021-05-11 18:17:09
YouTube
Setaz213, 2021-05-11 18:17:09

How to choose a different download method in YoutubeDL?

Good afternoon! If you upload a video of any DASH format via youtube_dl (in my case 298) immediately:

from youtube_dl import YoutubeDL
with YoutubeDL({'outtmpl': 'test.mp4', 'format': '298'}) as ydl:
  ydl.download(["https://www.youtube.com/watch?v=LXb3EKWsInQ'])
, then all 90 MB will be loaded in a couple of seconds.

But if you first get a direct link to a video of the same format and download it:
with YoutubeDL({'outtmpl': 'test.mp4'}) as ydl:
  info_dict = ydl.extract_info('https://www.youtube.com/watch?v=LXb3EKWsInQ', download=False)
  url = [i for i in info_dict['formats'] if i['format_id'] == '298'][0]['url']
  ydl.download([url])
, then the same 90 MB will be loaded in a few minutes.

So I think that in the first case, youtube_dl chose the appropriate download method for the video, but in the second it could not. Is it possible to somehow select the desired method and download through it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Setaz213, 2021-05-16
@Setaz213

In youtube_dl solved it like this:

filename = 'test.mp4'
url = '...' # Прямая ссылка на нужный формат видео
youtube_dl.downloader.HttpFD(YoutubeDL({}), {}).download(filename, {'url': url, 'downloader_options': {'http_chunk_size': 10485760}})

Loads fast just like I wanted.

M
Matvey Polubryukhov, 2021-05-16
@matveypol003

It's better to download YouTube videos through the pytube library. It works a little faster than youtube_dl. Yes, and write only one line of code (not counting imports and inputs).

from pytube import YouTube
link = input()
YouTube(link).streams.first().download()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question