Skip to main content

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

Release files for tldw 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tldw 1.0.4
File Size Uploaded
tldw-1.0.4.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tldw 1.0.4
File Interpreter ABI Platform
tldw-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / tldw-1.0.4.tar.gz

Download URL tldw-1.0.4.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2ecf6f19ecfae1e486fb00fa2fad9398f605f458f8facd9eccff51e738cdacf5
BLAKE2b-256 checksum
How to use checksums
7851b19528279dcedcfb21283bf54a549c3839c5e71fddf3380df6ee86e561f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / tldw-1.0.4-py3-none-any.whl

Download URL tldw-1.0.4-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f15a0259416132e9eb5721f94b267e4055b6d024f8fd714ffb279efe315410e
BLAKE2b-256 checksum
How to use checksums
5435dd5f6eeed4cf2f05335bf6c7025c4136daefa9f901c151bfbcd47f06fb69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page