Youtube downloader. Uses yt-dlp.
Run with docker:
docker build -t downwithu . && docker run -p 8000:8000 downwithuIf you need to inspect the container:
docker exec -it $(docker ps --filter "ancestor=downwithu" --format "{{.Names}}") /bin/shNote: These examples assume the Back-end is running locally on port 8000. The pieces of content used as examples are all copyright-free material.
- Example 1 ("Chollima on the Wing"):
http://127.0.0.1:8000/download_audio?url=https://www.youtube.com/watch?v=DKsj5mCR7qs - Example 2 ("I Love Beijing Tiananmen"):
http://127.0.0.1:8000/download_audio?url=https://www.youtube.com/watch?v=mJmjljQP3oY - Example 3, shortest one (Linux Startup Sound):
http://127.0.0.1:8000/download_audio?url=https://www.youtube.com/watch?v=rnbX7VUvxGU
Sometimes Youtube might update the website and make this package's functionality break. To update the main dependency that enables the download, run:
bash self_update.shThis will update yt-dlp and then overwrite requirements.txt with the new version.
This should probably be put into a cron job or something to guarantee an always up to date service.
NOTE: It might include extra packages in requirements.txt if you had more dependencies installed.
First, install ffmpeg.
sudo apt-get install ffmpeg # debian-based Linux distros
brew install ffmpeg # macOS
# For windows, see: https://ffmpeg.org/download.html# Optional but highly recommended: set-up pyenv version. See: https://dev.to/otamm/python-version-management-with-pyenv-3fig
pyenv local 3.12
# Optional but highly recommended: setup virtual env
python -m venv .venv && source .venv/bin/activate
# Optional: setup direnv. See: https://dev.to/otamm/one-environment-per-project-manage-directory-scoped-envs-with-direnv-in-posix-systems-4n3c
touch .envrc && echo 'export VIRTUAL_ENV=."venv" && layout python' >> .envrc && direnv allow
# installs packages to venv context
pip install -r requirements.txt # OR $ python -m pip install fastapi uvicorn yt-dlp
# writes libraries and versions to a reusable file
pip freeze > requirements.txt Use this commands from the same directory level as pyproject.toml:
# uvicorn command
uvicorn app.main:app --host 0.0.0.0 --port 8000 # prod mode
uvicorn app.main:app --host 0.0.0.0 --port 8000 ---reload # dev mode
# fastapi command
fastapi run # prod mode
fastapi run --reload # dev modeIf you wish to test locally:
python -m pip install -r requirements_test.txt
pytest test/Run only integration tests (these are the most important as they check the core library's current working status):
pytest tests/integrationTesting the self-updater script:
bash test_self_update.shNOTE: It might include extra packages in requirements.txt if you had more dependencies installed.