Search code examples
pythonbashcommand-lineyoutubeyoutube-dl

Is there a way to download video while keeping their chapters metadata?


I've used many video downloaders before: atube catcher, 4k downloader, jDownloader, and currently using youtube-dl. I can't download videos, this for example, while still keeping their online chapters intact, like part1 is "intro" lasting from 00:00 to 00:45 and so on. So far I tried these parameters with youtube-dl

Filesystem

--write-annotations --write-description --write-info-json

Thumbnail images

--write-all-thumbnails

Video format

-f 'bestvideo[height<=720]+bestaudio/best[height<=720]/worst' --merge-output-format mp4

Post-processing

--add-metadata --embed-subs --embed-thumbnail


Also tried requesting the mkv video format (thought maybe it was built into it) didn't help tho.
I know these options don't really say anything about sections but I'm trying to get as much metadata as I can

Solution

  • The information you want is called chapters in the youtube-dl info JSON.

    There is a recent open pull request for youtube-dl that fixes a problem with this information. In the current release of youtube-dl, if you use the ---write-info-json or --dump-json you will see that the chapters information is null ("chapters": null). You can use the code in the fork repository to be able to obtain the information you want.

    Follow these steps:

    1. Clone this repository:

      git clone https://github.com/gschizas/youtube-dl.git
      
    2. Change to the repository directory:

      cd youtube-dl/
      
    3. Checkout the pull request branch:

      git checkout bugfix/youtube/chapters-fix-extractor
      
    4. Run youtube-dl from the current location:

      python -m youtube_dl --write-info-json https://youtu.be/LnO42jxJaC4
      

    You will see information like this in the info JSON:

    "chapters": [
        {
            "start_time": 0.0,
            "end_time": 46.0,
            "title": "Intro"
        },
        {
            "start_time": 46.0,
            "end_time": 72.0,
            "title": "QOTD"
        },
        ...
    ]
    

    Hopefully the fix will be accepted into the youtube-dl repository and included in future releases, so there will be no need to clone any repository.