VideoDownload tool for Youtube/BiliBili
Requirements:
- Aria2 (for Youtube)
- FFmpeg (for Youtube、BiliBili)
- Poetry (as package management)
- Python 3.8.3+
Setup:
git clone https://github.com/dxsooo/VideoDownload.git
cd VideoDownload
# unix like systems
poetry export -f requirements.txt --without-hashes | pip install -r /dev/stdin
# for windows powershell or cmd
poetry export -f requirements.txt --output requirements.txt --without-hashes
pip install -r requirements.txt
Run:
python download.py -u <VideoURL>
VideoURL is the video playing url and the url pattern should follow:
source | url pattern |
---|---|
Youtube | https://www.youtube.com/watch?v=xxxx |
BiliBili | https://www.bilibili.com/video/BVxxxx or http://www.bilibili.com/video/avxxxx |
The video is saved in videos/
of the current path and named with video id.
There are more options:
% python download.py --help
usage: download.py [-h] -u URL [-d DIR]
options:
-h, --help show this help message and exit
-u URL, --url URL video playing url
-d DIR, --dir DIR video save directory
You can easily download video by docker:
docker run -t -v/path/to/save:/app/videos dxsooo/video-download:0.4.11 download.py -u <VideoURL>
As YT-DLP is used in youtube download, a method to config its options is provided. You can add an ini file in configs/youtube.ini
with content like:
[ydl_opts]
max_filesize=314572800 ; limit file size, 300M
subtitleslang=en.* ; set subtitles langs to en, default is zh
You can also mount the ini file to docker container for configuration.
VideoDownload can also work as a Celery worker that receive download tasks, making it possible and convenient to deploy in distribute systems and integrate with cloud-native services.
It is recommended to use by docker:
docker run -d --name video-downloader-1 \
-e BROKER=${YOUR_CELERY_BROKER} \
-e BACKEND=${YOUR_CELERY_BACKEND} \
-v /path/to/save:/app/videos \
--entrypoint=celery \
dxsooo/video-download:0.4.11 -A celery_worker worker -c 4 -E
For BiliBili, as some deps could not run with multi process, concurrency(-c) should be 1. But it is ok to run multi docker containers to walk around.
And then you can send task by one of the following methods:
# pip install celery
from celery import Celery
celery = Celery(broker="<YOUR_CELERY_BROKER>")
celery.send_task('celery_worker.download',("<VideoURL>",))
Start flower by:
docker run -d --name video-downloader-flower \
-e BROKER=${YOUR_CELERY_BROKER} \
-e BACKEND=${YOUR_CELERY_BACKEND} \
--entrypoint=celery \
-p 5555:5555 \
dxsooo/video-download:0.4.11 -A celery_worker flower
Example request:
POST /api/task/async-apply/celery_worker.download HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Type: application/json; charset=utf-8
Host: localhost:5555
{
"args": ["<VideoURL>"]
}
if you want to use custom queue instead of the default
celery
, start worker with-Q <queue>
, and send request refer mher/flower#456
Read the source code for more parameters to control task.