Metadata-Version: 2.4
Name: BROKENXAPI
Version: 2.0.7
Summary: Official async Python SDK and CLI for BrokenX YouTube API
Author-email: Mr Broken <brokenxnetwork@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Mr Broken
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/mrxbroken011/BROKENXAPI
Project-URL: Repository, https://github.com/mrxbroken011/BROKENXAPI
Project-URL: Documentation, https://brokenxapi-docs.vercel.app
Project-URL: Issues, https://github.com/mrxbroken011/BROKENXAPI/issues
Keywords: brokenx,youtube,api,async,sdk,cli,aiohttp,telegram
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Multimedia :: Video
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Framework :: AsyncIO
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp>=3.8.0
Dynamic: license-file

# BROKENXAPI Documentation


**BROKENXAPI** is an async-first Python SDK that allows developers to access
BrokenX YouTube services securely using an API key.
---

> [!CAUTION]
> **IMPORTANT DISCLAIMER**
>
> This project is designed for **Educational Purposes Only**.
> Usage of this software to download copyrighted content (Music/Videos) without permission may violate YouTube's Terms of Service and local copyright laws.
>
> The developer (**MR BROKEN**) assumes **NO responsibility** for any misuse or legal consequences resulting from the use of this tool. Use it at your own risk.

---

## Features
- Async / non-blocking
- Secure header-based authentication
- Clean SDK (no backend exposure)
- Telegram-powered media delivery

## Requirements
- Python 3.8 or higher
- Valid BrokenX API key Get it from [Here](https://t.me/AboutbrokenX) 
- Internet access

---
##### Install with pip:
```bash
pip install BROKENXAPI
```

# Quick Start

Recommended: set your API key as an environment variable for local development.

Linux / macOS:
```bash
export API_KEY="BROKENXAPI-XXXX"
```

Windows (cmd):
```bat
set API_KEY=BROKENXAPI-XXXX
```

Basic usage (using env var):
```python
import os
import asyncio
from brokenxapi import BrokenXAPI

API_KEY = os.getenv("API_KEY")  # recommended
async def main():
    async with BrokenXAPI(api_key=API_KEY) as api:
        result = await api.search("Arijit Singh")
        print(result)

asyncio.run(main())
```

Or pass API key directly (less secure):
```python
async with BrokenXAPI(api_key="BROKENXAPI-XXXX") as api:
    result = await api.search("No Copyright sounds", video=False)
```

---

# Authentication

BROKENXAPI uses header-based authentication. The SDK sets the `Authorization` header for you when you pass `api_key` to the constructor.

Header format (used internally by the SDK):
```
Authorization: Bearer YOUR_API_KEY
```

Do not commit or share your API key in public repositories.

---


Context-manager usage:
```python
async with BrokenXAPI(api_key="...") as api:
    ...
```

### search(query: str, video: bool = False, limit: int = 20)
Search for YouTube content.

- Parameters:
  - query (str): search keyword
  - video (bool): False = audio (default), True = video
  - limit (int): number of results to request (default 20)

- Returns: dict — a JSON-compatible dictionary including keys such as:
  - title
  - video_id
  - duration
  - thumbnail

Example:
```python
result = await api.search("no copyright sounds", video=False)
video_id = result["video_id"]
```

### download(video_id: str, media: str = "audio")
Download audio or video via BrokenX backend.

- Parameters:
  - video_id (str): YouTube video id
  - media (str): "audio" (default) or "video"

- Returns: dict — download metadata. Example keys:
  - telegram_url

Example:
```python
audio = await api.download(video_id, media="audio")
print(audio["telegram_url"])
```

Notes:
- The SDK converts boolean query parameters to strings before sending (e.g. True -> "true").
- All network requests raise on non-2xx responses via aiohttp.

---

# Error Handling

All SDK errors inherit from `BrokenXAPIError`.

Example:
```python
from brokenxapi.exceptions import BrokenXAPIError

try:
    await api.download("invalid_id")
except BrokenXAPIError as e:
    print("Error:", e)
```

---

# CLI

The package provides a `brokenx` CLI. Example usage:

- Save API key:
```bash
brokenx auth BROKENXAPI-XXXX
```

- Search:
```bash
brokenx search "no copyright sounds"
```

- Download (audio):
```bash
brokenx download VIDEO_ID
```

- Download (video):
```bash
brokenx download VIDEO_ID -v
```

---

# Running tests

Set the `YTKEY` env var before running tests that hit the real backend:

```bash
export API_KEY="BROKENXAPI-XXXX"
pytest -q
```

Tests that require a live API key are skipped automatically if `API_KEY` is not set.
