/youtube-subs

A simple project for generating subtitles for YouTube videos using GCP's Speech-to-Text API.

Primary LanguagePythonMIT LicenseMIT

YouTube Subs

Overview

This is a simple CLI tool for generating subtitles (in SRT format) from YouTube videos.

Business logic

  1. You provide the CLI tool with a hyperlink for a YouTube video.
  2. The tool downloads the video to your machine as video.mp4.
  3. Then, from video.mp4 it extracts audio using FFmpeg and saves that audio locally as audio.wav.
  4. In the next step, it uploads the audio.wav file to your GCS bucket.
  5. GCP's Speech-to-Text service picks up the the audio.wav file from the GCS bucket and transcribes it.
  6. Finally, the transcription (not 100% accurate, but with timestamps!) is saved as the subtitles.srt file on your computer.

Folder structure

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.

Prerequisites

Infrastructure

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.

Application

Usage

a) download

pip install -i https://test.pypi.org/simple/ youtube-subs

b) run

ys generate https://www.youtube.com/watch?v=EgLCtVshp8E

Local development

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

Packaging & publishing

a) create a package

python setup.py sdist bdist_wheel

b) publish to Test PyPi

twine upload --repository testpypi --skip-existing dist/*

Acknowledgements

  • 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