Skip to main content

A Python package to summarize YouTube videos using the OpenAI API.

Project description

TLDW (Too Long; Didn't Watch)

PyPI version Python 3.8+ License: MIT Test

A Python package that instantly summarizes YouTube videos using AI. Get the key points from any video without watching it!

✨ Features

  • 🎥 YouTube Video Summarization: Extract transcripts and generate concise summaries
  • 🤖 OpenAI GPT Integration: Powered by GPT-4o-mini for high-quality summaries
  • 🎨 Beautiful CLI Output: Colorized terminal output with ASCII art
  • 🔄 Streaming Response: Real-time summary generation
  • 🐍 Simple Python API: Easy to integrate into your projects

🚀 Quick Start

Prerequisites

Installation

Install from PyPI:

pip install tldw

From source:

git clone git@github.com:DavidZirinsky/tl-dw.git
cd tl-dw/
python3 -m pip install .

Usage

from tldw import tldw
import os

# Initialize with your OpenAI API key
summary = tldw(os.environ.get('OPENAI_API_KEY'))

# Summarize a YouTube video
summary.summarize('https://www.youtube.com/watch?v=LCEmiRjPEtQ')

Using a Proxy

If you need to use a proxy to fetch the YouTube transcript, you can pass a proxies dictionary. This is useful for environments with network restrictions.

from tldw import tldw
import os

# Your proxy URL
proxy_url = "http://user:pass@host:port"

# Initialize with proxy settings
summary = tldw(
    os.environ.get('OPENAI_API_KEY'),
    proxies={'http': proxy_url, 'https': proxy_url}
)

# Summarize a YouTube video through the proxy
summary.summarize('https://www.youtube.com/watch?v=LCEmiRjPEtQ')

Note: The proxy is only used for fetching the YouTube transcript, not for requests to the OpenAI API.

📝 Example Output

  ________    ____ _       __
 /_  __/ /   / __ \ |     / /
  / / / /   / / / / | /| / /
 / / / /___/ /_/ /| |/ |/ /
/_/ /_____/_____/ |__/|__/


Summarizing video: https://www.youtube.com/watch?v=LCEmiRjPEtQ

--- Summary ---

In his talk, Andre Carpathy, former director of AI at Tesla, discusses the evolving
nature of software in the era of AI, particularly emphasizing the transition from
traditional coding (Software 1.0) to an AI-driven paradigm (Software 2.0 and 3.0).
He categorizes Software 1.0 as conventional code that directly instructs computers,
while Software 2.0 encompasses neural networks where the focus is on tuning data
sets instead of writing explicit code. He introduces Software 3.0, which involves
large language models (LLMs) that can be prompted in natural language, making
programming more accessible to non-coders.

[...continued summary...]

--- End of Summary ---

❓ Troubleshooting

Common Issues

"OpenAI API key is required" Error

  • Make sure your OpenAI API key is set in the environment variable OPENAI_API_KEY
  • Verify your API key is valid and has sufficient credits

"Invalid YouTube URL provided" Error

  • Ensure the URL is a valid YouTube video URL
  • Supported formats: https://www.youtube.com/watch?v=VIDEO_ID or https://youtu.be/VIDEO_ID

"Failed to get transcript" Error

  • The video may not have English captions/transcripts available
  • Some videos may have restricted access to transcripts
  • Try with a different video that has confirmed English captions
  • If you are behind a firewall, you may need to use a proxy (see Using a Proxy section)

API Rate Limiting

  • If you encounter rate limiting, wait a few moments before trying again
  • Consider upgrading your OpenAI API plan for higher rate limits

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

🛠️ Development Setup

  1. Install Dependencies:

    pip install -e .
    
  2. Then Run This With:

    python3 src/tldw/tldw.py
    

🧪 Running Tests

To run the tests:

Locally:

pytest

You can also run tests in the Docker container, mimicking a PyPI wheel distribution installation.

docker compose down && docker compose up -d --build && docker logs tests -f

🤝 Pre-commit Hooks

This project uses pre-commit hooks to ensure code quality and consistency before commits.

  1. Install pre-commit: If you don't have pre-commit installed globally, you can install it into your virtual environment:

    pip install pre-commit
    
  2. Install the Git hooks: Navigate to the root of the repository and run:

    pre-commit install
    

    This command sets up the hooks in your .git/ directory.

  3. Run hooks manually (optional): To run all configured hooks against all files, without making a commit:

    pre-commit run --all-files
    

Now, every time you try to commit, the pre-commit hooks will automatically run. If any hook fails, the commit will be aborted, allowing you to fix the issues before committing.

📦 Packaging for PyPI and Test PyPi

For PyPI:

Build and Upload:

pip install build twine
python3 -m build
python3 -m twine upload  dist/*

For Test PyPi:

Build and Upload:

pip install build twine
python3 -m build
python3 -m twine upload --repository testpypi dist/*

Test PyPi Installation:

pip install --index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
tldw==1.0.3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tldw-1.0.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tldw-1.0.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file tldw-1.0.2.tar.gz.

File metadata

  • Download URL: tldw-1.0.2.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for tldw-1.0.2.tar.gz
Algorithm Hash digest
SHA256 eb0b342122ea1f48a10f5130adf97824a9eb4e260483dd36f25529f267d03942
MD5 edaa35b9708f9d3bbba36f63f565e89e
BLAKE2b-256 b9dcb1ccc9dbc9af43b02750fe546f3eb2485e9b30f173be3b9395ffa5336863

See more details on using hashes here.

File details

Details for the file tldw-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: tldw-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for tldw-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 119f7c40559d7e5f0001a0db6fa4d80b6375506f038be67aa7bbc9b31285de0c
MD5 b98dc813b11365e11bcb09d4587f8f54
BLAKE2b-256 7d9ab6261ac7bcae1bcb1740ad3a8a543023d346bd5399ccff1b916657d69d9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page