如何从源代码重建 python youtube-dl

How to rebuild python youtube-dl from the source

起初我想承认我是python编程的菜鸟。但不知何故,我还是设法弄清楚了如何修改一些 python 正则表达式,因为提取器可以为我获取一些额外的数据。不幸的是,我不知道如何从更改后的源代码构建可执行文件。因为我正在使用 PHP 包装器来使用 youtube-dl ubuntu 可执行文件来 抓取 一些数据。

我注意到

中有一个 6 岁以上的 post

Python youtube-dl recompile

但不幸的是,解决方案没有提供重新编译或重建的方法。我什至还没有在

的开发人员官方文档中找到如何重建

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.

最后使用 git

进行开源贡献
  1. Finally, create a pull request. We'll then review and merge it.

但找不到任何可在本地构建以在本地使用的内容。

development instructions 中所述,您可以 运行 youtube-dl 与

交互
python -m youtube_dl

而 youtube-dl 存储库在您的 PYTHONPATH 中,例如因为您的 cwd 是 youtube-dl 存储库的根目录。

对于开发,运行 测试通常更容易。同样,as documented,这些工作中的任何一项:

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

如果你正在开发一个提取器,你可以运行

python test/test_download.py TestDownload.test_YourExtractor

只是测试你的提取器。

如果您真的想要一个 youtube-dl 二进制文件,请输入

make

在 youtube-dl 存储库的根目录中。你会得到一个名为 youtube-dl.

的二进制文件

请注意,make 可以与 任何 维护良好的软件项目一起使用,尽管一些新千年的时髦语言更喜欢重新发明他们自己的不兼容版本。

如果你很着急,想测试你对 youtube-dl 文件的更改,你可以 运行 从源文件 python 主文件 src_path/youtube_dl/__main__.py 我用它在 Python3.8 上测试 运行ning youtube-dl 而不是我的系统默认 2.7.12 我只是将 #!/usr/bin/env python 更改为 #!/usr/bin/env python3.8 然后我软link 到我系统 /usr/local/sbin/ 上的文件 youtube_dl/__main__.py 以便您可以立即测试您的更改。