Search code examples
pythonpython-3.xyoutube-dl

How to rebuild python youtube-dl from the source


At first I want to admit that I am a noob in python programming. but still somehow I have managed to figure out how to modify some python regular expressions as the extractor can get some extra data for me. Unfortunately I don't know how to build executable from the changed source code. because I am using a PHP wrapper to use the youtube-dl ubuntu executable for scraping some data.

I have noticed there is a 6+ years old post on this in

Python youtube-dl recompile

but unfortunately the solution didn't provide the way to recompile or rebuild. I even haven't found how to rebuild in the official documentation for developer here in

https://github.com/ytdl-org/youtube-dl#developer-instructions

Most users do not need to build youtube-dl and can download the builds or get them from their distribution.

To run youtube-dl as a developer, you don't need to build anything either.

and at the end for open source contribution using git

  1. Finally, create a pull request. We'll then review and merge it.

but couldn't find anything to build it locally to use locally.


Solution

  • As documented in the development instructions, you can run youtube-dl interactively with

    python -m youtube_dl
    

    while the youtube-dl repository is in your PYTHONPATH, for example because your cwd is the root of the youtube-dl repository.

    For development, it's often easier to run the tests instead. Again, as documented, any of these work:

    python -m unittest discover
    python test/test_download.py
    nosetests
    

    If you're developing an extractor, you can run

    python test/test_download.py TestDownload.test_YourExtractor
    

    to just test your extractor.

    If you actually want a youtube-dl binary, type

    make
    

    in the root directory of the youtube-dl repository. You will get a binary called youtube-dl.

    Note that make works with any well-maintained software project, although some new-millennium hipster languages prefer to reinvent their own incompatible version.