This is a simple CLI tool for generating subtitles (in SRT format) from YouTube videos.
- You provide the CLI tool with a hyperlink for a YouTube video.
- The tool downloads the video to your machine as
video.mp4
. - Then, from
video.mp4
it extracts audio using FFmpeg and saves that audio locally asaudio.wav
. - In the next step, it uploads the
audio.wav
file to your GCS bucket. - GCP's Speech-to-Text service
picks up the the
audio.wav
file from the GCS bucket and transcribes it. - Finally, the transcription (not 100% accurate,
but with timestamps!) is saved as the
subtitles.srt
file on your computer.
This project consists of a smaller, but still vital, infrastructure part, and a bigger, in terms of lines of code (LOC), application part.
The infrastructure lives in the ./infra
directory
(with its own REAMDE.md
file),
the app's business logic lives in the ./src
directory,
while the setup.py
and other files necessary to package this CLI tool, live here, at the project's root.
Before using the CLI or commencing with local development, you must a) meet the infrastructure prerequisites,
and b) stand up the infra using the pulumi up
command.
Refer to the infra README for more details.
-
(OPTIONAL)wheel, setuptools, and twine:
pip3 install wheel setuptools twine
-
(OPTIONAL) user account at Test PyPi
a) download
pip install -i https://test.pypi.org/simple/ youtube-subs
b) run
ys generate https://www.youtube.com/watch?v=EgLCtVshp8E
a) set up and activate Virtual Environment
pip3 -m venv venv
source venv/bin/activate
b) install dependencies
pip3 install -r requirements
c) build the tool for development
python3 setup.py develop
d) run the tool
ys
a) create a package
python setup.py sdist bdist_wheel
b) publish to Test PyPi
twine upload --repository testpypi --skip-existing dist/*
- the main business logic relies heavily on this blog post
- this article served me as a guidance for building and distributing a CLI tool in Python