# \[SOLVED\] Does anyone here know how youtube-dl works internally

**URL:** <https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662>\
**Category:** Tutorials & Methods\
**Tags:** solved, programming\
**Created:** [April 6, 2020, 1:04pm UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662 "2020-04-06T13:04:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pankaj260](https://onehack.st/user_avatar/onehack.st/pankaj260/32/18769_2.png) [@pankaj260](https://onehack.st/u/pankaj260)\
**Post date:** [April 6, 2020, 1:04pm UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662/1 "2020-04-06T13:04:09Z")

</div>

Does anyone here know how youtube-dl works internally ? Can anyone Just explain how youtube-dl is able to download the videos of Safari books because I want to know how it operates so that I can make video downloader for many other sites which uses .m3u8 or streams .

---

<div class="post-metadata">

**Author:** ![Aina](https://onehack.st/user_avatar/onehack.st/aina/32/167469_2.png) [@Aina](https://onehack.st/u/Aina)\
**Post date:** [April 6, 2020, 1:05pm UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662/2 "2020-04-06T13:05:27Z")

</div>

If you’re wondering to download then this article can help you.

> [@Download Streaming Videos Using M3u8x](https://onehack.st/t/download-streaming-videos-using-m3u8x/56120/):
>
> m3u8x = Download m3u8-video = Download videos from M3U8 to your computer = Download m3u8-video Quite confusing? Don’t worry! Download : [MediaFire](http://www.mediafire.com/download/zi2jtfkbvakpjir/m3u8.rar)[SourceForge](https://sourceforge.net/projects/m3u8x/files/m3u8x.rar/download)[CNET Download.Com](http://download.cnet.com/M3U8X/3000-2071_4-77576835.html)[SoftPedia.com](http://www.softpedia.com/get/Multimedia/Video/Other-VIDEO-Tools/m3u8x.shtml)Program m3u8x is to help you download and save video Depends on m3u8 1) Copy M3U8 file and then paste its file link to “m3u8x” , can also support to download multiple M3U8 files one time, so you can paste many M3U8 file links to “m3u8x”. 2) you can select other file …

how it works and how to make one, I will check and solve it if possible.

---

<div class="post-metadata">

**Author:** ![pankaj260](https://onehack.st/user_avatar/onehack.st/pankaj260/32/18769_2.png) [@pankaj260](https://onehack.st/u/pankaj260)\
**Post date:** [April 6, 2020, 1:46pm UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662/3 "2020-04-06T13:46:42Z")

</div>

No i wanted to download it through paython script programmatically just like youtube-dl does. Although youtube-dl is open source but i am terrible at reading someone else’s code to be fair .

---

<div class="post-metadata">

**Author:** ![knowntheunknown](https://onehack.st/user_avatar/onehack.st/knowntheunknown/32/37540_2.png) [@knowntheunknown](https://onehack.st/u/knowntheunknown)\
**Post date:** [April 6, 2020, 2:41pm UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662/4 "2020-04-06T14:41:23Z")

</div>

> **[GitHub - ytdl-org/youtube-dl: Command-line program to download videos from...](https://github.com/ytdl-org/youtube-dl)**
>
> Command-line program to download videos from YouTube.com and other video sites

---

<div class="post-metadata">

**Author:** ![pankaj260](https://onehack.st/user_avatar/onehack.st/pankaj260/32/18769_2.png) [@pankaj260](https://onehack.st/u/pankaj260)\
**Post date:** [April 6, 2020, 2:55pm UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662/5 "2020-04-06T14:55:08Z")

</div>

Really ? like really , did you even read what i am asking ?

---

<div class="post-metadata">

**Author:** ![Margaret](https://onehack.st/user_avatar/onehack.st/margaret/32/174872_2.png) [@Margaret](https://onehack.st/u/Margaret)\
**Post date:** [April 8, 2020, 11:25pm UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662/6 "2020-04-08T23:25:56Z")

</div>

[`YoutubeDL.extract_info`](https://github.com/rg3/youtube-dl/blob/4bede0d8f5b6fc8d8e46ee240f808935e03eafa2/youtube_dl/YoutubeDL.py#L735) is a good place to start; it checks a provided URL against the extractors (from the [`extractor` package](https://github.com/rg3/youtube-dl/tree/4bede0d8f5b6fc8d8e46ee240f808935e03eafa2/youtube_dl/extractor)) [that are known](https://github.com/rg3/youtube-dl/blob/4bede0d8f5b6fc8d8e46ee240f808935e03eafa2/youtube_dl/extractor/ __init__.py#L11), each of which has site-specific rules for extracting content URLs from a web page.

Once an extractor returns a URL and other metadata, it eventually calls [`downloader.get_suitable_downloader`](https://github.com/rg3/youtube-dl/blob/4bede0d8f5b6fc8d8e46ee240f808935e03eafa2/youtube_dl/downloader/ __init__.py#L32) on the content URL provided by the extractor to determine what protocol to use when downloading. The implementation for each protocol extends [`FileDownloader`](https://github.com/rg3/youtube-dl/blob/4bede0d8f5b6fc8d8e46ee240f808935e03eafa2/youtube_dl/downloader/common.py#L19) which provides the general interface for downloading a file.

Depending on the requested options, it may need to postprocess downloaded files, for instance remuxing the requested video and audio tracks into one file. Code for doing these things is in the [`postprocessor`](https://github.com/rg3/youtube-dl/tree/4bede0d8f5b6fc8d8e46ee240f808935e03eafa2/youtube_dl/postprocessor) package.

[https://www.reddit.com/r/Python/comments/6fsd6i/how\_does\_youtubedl\_works\_on\_a\_highlevel/](https://www.reddit.com/r/Python/comments/6fsd6i/how_does_youtubedl_works_on_a_highlevel/)

[https://www.reddit.com/r/youtubedl/comments/880axi/how\_does\_youtubedl\_work/](https://www.reddit.com/r/youtubedl/comments/880axi/how_does_youtubedl_work/)

## Extra

For reference, if you can build something like this from scratch!

> **[Create a GUI downloader App using Python - CodeSpeedy](https://www.codespeedy.com/create-a-gui-downloader-app-using-python/)**
>
> In this tutorial, we are going to learn how to create a GUI application for downloading files using Python. We are going to use Tkinter and Requests module.

# Python to Download YouTube Videos with a Tkinter UI

![](https://img.youtube.com/vi/zF5TOcu9VhE/maxresdefault.jpg)https://www.youtube.com/embed/zF5TOcu9VhE?feature=oembed&wmode=opaque

[https://github.com/Tyrrrz/YoutubeExplode](https://github.com/Tyrrrz/YoutubeExplode)

---

<div class="post-metadata">

**Author:** ![pankaj260](https://onehack.st/user_avatar/onehack.st/pankaj260/32/18769_2.png) [@pankaj260](https://onehack.st/u/pankaj260)\
**Post date:** [April 9, 2020, 2:13am UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662/7 "2020-04-09T02:13:54Z")

</div>

Can you take example of YouTube or twitter and demonstrate how to go about because when I see the video source of the video tag , it is like blob:[https://YouTube.com/some\_hash\_code](https://YouTube.com/some_hash_code) and same goes for twitter. If a site has video pointing directly to a video source then it’s easy to download but like I said YouTube Twitter and many other site have stream type of video.

---

<div class="post-metadata">

**Author:** ![rameshram1334](https://onehack.st/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@rameshram1334](https://onehack.st/u/rameshram1334)\
**Post date:** [April 9, 2020, 4:51am UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662/8 "2020-04-09T04:51:29Z")

</div>

I have been one of its contributors. basically when you give an url, the corresponding extractor is called. That will parse the url’s html, get required details, such as id, name of the video, timestamp, video id, likes/upvotes, etc. Generally, everything isn’t needed, but a few are absolutely needed, such as id and video id/url. That info is passed to downloader, that actually downloads the video. Furthen, post processing is done as per needed. The extractor also handles logins, which in some cases is complexed. Many sites use encoding, such as HLS, which is much more difficult to parse. The folks @ ytdl are very smart and make a new contributor writing code for a new extractor using hls/ any other encoding as easy as possible.

---

<div class="post-metadata">

**Author:** ![pankaj260](https://onehack.st/user_avatar/onehack.st/pankaj260/32/18769_2.png) [@pankaj260](https://onehack.st/u/pankaj260)\
**Post date:** [April 9, 2020, 5:09am UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662/9 "2020-04-09T05:09:05Z")

</div>

So how do they extract download link of hls encoded video because they are very tough to extract. if possible take the example of any twitter video and explain. Because twitter also uses hls encoding.

---

<div class="post-metadata">

**Author:** ![rameshram1334](https://onehack.st/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@rameshram1334](https://onehack.st/u/rameshram1334)\
**Post date:** [April 9, 2020, 5:20am UTC](https://onehack.st/t/solved-does-anyone-here-know-how-youtube-dl-works-internally/77662/10 "2020-04-09T05:20:46Z")

</div>

There’s a lot to explain. Take a look @ [https://github.com/ytdl-org/youtube-dl/blob/master/youtube\_dl/downloader/hls.py](https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/downloader/hls.py) . The code is beautifully written easy to understand.
