Metadata-Version: 2.4
Name: yt-details
Version: 0.1.2
Summary: Fast, efficient batch YouTube metadata fetching with Redis caching.
Author-email: HarshalMjn <mahajanh006@gmail.com>
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx
Provides-Extra: redis
Requires-Dist: redis; extra == "redis"
Dynamic: license-file

# YouTube Details

A standalone, asynchronous Python library to efficiently fetch metadata from YouTube URLs. It supports batch fetching and individual video caching with Redis.

## Features

- ⚡ **Asynchronous**: Built with `httpx` for high-performance async requests.
- 📦 **Batch Fetching**: Automatically batches requests (50 per call) to stay within API limits.
- 🚀 **Redis Caching**: Optional Redis support to cache metadata and reduce API costs.
- 🔗 **Smart Extraction**: Supports multiple YouTube URL formats (watch, shorts, embed, youtu.be).
- 🛠️ **Lightweight**: Minimal dependencies, easy to integrate.

## Installation

```bash
pip install yt-details
```

To include Redis support:
```bash
pip install "yt-details[redis]"
```

## Quick Start

### Basic Usage

```python
import asyncio
from yt_details import YouTubeService

async def main():
    service = YouTubeService(api_key="YOUR_API_KEY")
    
    # Fetch a single video
    details = await service.get_video_details("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
    print(f"Title: {details['title']}")

if __name__ == "__main__":
    asyncio.run(main())
```

### With Redis Caching

```python
import redis.asyncio as redis
from yt_details import YouTubeService

# Initialize async Redis client
redis_client = redis.from_url("redis://localhost:6379")

# Service will now cache results for 24 hours (86400 seconds)
service = YouTubeService(
    api_key="YOUR_API_KEY", 
    redis_client=redis_client,
    cache_ttl=86400
)
```

## Batch Fetching

The service handles batching efficiently:

```python
urls = [
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
    "https://youtu.be/kJQP7kiw5Fk",
    # ... more URLs
]

results = await service.get_videos_details_batch(urls)
for url, data in results.items():
    if "error" not in data:
        print(f"{data['title']} - {data['views_formatted']} views")
```

## License

MIT
