Skip to main content

A Python library for interacting with the yt-dlp-host API

Project description

yt-dlp-host API Client

This is a Python library for interacting with the yt-dlp-host API.

Installation

You can install the library using pip:

pip install yt-dlp-host-api

Usage

Here's a basic example of how to use the library:

import yt_dlp_host_api

# Initialize the API client
api = yt_dlp_host_api.api('http://your-api-url.com')
client = api.get_client('YOUR_API_KEY')

# Download a complete video
client.get_video(url='https://youtu.be/1FPdtR_5KFo').save_file("test_video.mp4")
print("Video saved to test_video.mp4")

# Download a video segment (first 5 minutes)
client.get_video(
    url='https://youtu.be/1FPdtR_5KFo',
    end_time="00:05:00"
).save_file("first_5min.mp4")
print("First 5 minutes saved to first_5min.mp4")

# Download a video segment (from 5 minutes to 10 minutes)
client.get_video(
    url='https://youtu.be/1FPdtR_5KFo',
    start_time="00:05:00",
    end_time="00:10:00"
).save_file("5min_to_10min.mp4")
print("5-10 minute segment saved to 5min_to_10min.mp4")

# Download a complete audio
client.get_audio(url='https://youtu.be/1FPdtR_5KFo').save_file("test_audio.mp3")
print("Audio saved to test_audio.mp3")

# Get info
info_json = client.get_info(url='https://youtu.be/1FPdtR_5KFo').get_json(['qualities', 'title'])
print("Video info:", info_json)

# Admin operations (requires admin API key)
new_key = client.create_key("user_key", ["get_video", "get_audio", "get_info"])
keys = client.get_keys()
key = client.get_key("user_key")
client.delete_key("user_key")

Features

  • Download YouTube videos
    • Download complete videos
    • Download specific time segments
    • Choose video and audio quality
  • Download YouTube audio
    • Download complete audio
    • Download specific time segments
    • Choose audio quality
  • Extract live stream segments
  • Retrieve video information
  • Checking client permissions
  • Admin operations:
    • Create new API keys
    • List existing API keys
    • Get API key by key name
    • Delete API keys

API Reference

Client

  • client.get_video(url, video_format="bestvideo", audio_format="bestaudio", start_time=None, end_time=None): Get video with optional time segment selection
  • client.get_audio(url, audio_format="bestaudio", start_time=None, end_time=None): Get audio with optional time segment selection
  • client.get_live_video(url, duration, start=0, video_format="bestvideo", audio_format="bestaudio"): Get live video segment
  • client.get_live_audio(url, duration, start=0, audio_format="bestaudio"): Get live audio segment
  • client.get_info(url): Get video information
  • client.send_task.get_video(url, video_format="bestvideo", audio_format="bestaudio", start_time=None, end_time=None): Initiate a video download task
  • client.send_task.get_audio(url, audio_format="bestaudio", start_time=None, end_time=None): Initiate an audio download task
  • client.send_task.get_live_video(url, duration, start=0, video_format="bestvideo", audio_format="bestaudio"): Initiate a live video download task
  • client.send_task.get_live_audio(url, duration, start=0, audio_format="bestaudio"): Initiate a live audio download task
  • client.send_task.get_info(url): Initiate an info retrieval task
  • client.check_permissions(permissions): Check for all permissions in the list

Time Format

Time parameters (start_time and end_time) should be provided in the following format:

  • "HH:MM:SS" (hours:minutes:seconds) Examples:
  • "00:05:00" - 5 minutes
  • "01:30:45" - 1 hour, 30 minutes, and 45 seconds

Task

  • task.get_status(): Get the current status of a task
  • task.get_result(): Wait for and return the result of a task

TaskResult

  • result.get_file(): Get the file
  • result.get_file_url(): Get the URL of the downloaded file
  • result.save_file(path): Save the downloaded file to the specified path
  • result.get_json(fields=None): Get the JSON data for info tasks (optionally filtered by fields)

Admin

  • client.create_key(name, permissions): Create a new API key
  • client.get_keys(): List all existing API keys
  • client.get_key(name): Get API key by key name
  • client.delete_key(name): Delete an API key

Error Handling

The library uses exceptions to handle errors. Catch yt_dlp_host_api.exceptions.APIError to handle API-related errors.

Contributing

Contributions to yt-dlp-host-api are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue on the GitHub repository. Pull requests are also encouraged.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

yt_dlp_host_api-0.1.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file yt_dlp_host_api-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for yt_dlp_host_api-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 51e98cb6ba2715ad55fe7166ebfca99672065191c954f97f2e99cea40002ef26
MD5 0488b8992d919212b309de728fb0c55e
BLAKE2b-256 72659bee3458469cd01d6dd94a039f612ca21c94c2c98ebd1f17281882d0cb77

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