Utils¶
- async asyncyt.utils.call_callback(callback, *args, **kwargs)[source]¶
Call a callback, supporting both coroutine and regular functions.
- Parameters:
callback – The callback function to call.
args – Positional arguments for the callback.
kwargs – Keyword arguments for the callback.
- asyncyt.utils.clean_youtube_url(url: str) str [source]¶
Clean any YouTube URL (watch, youtu.be, shorts, embed) into its core form.
- Parameters:
url (str) – The youtube URL
- Returns:
Cleaned YouTube URL.
- async asyncyt.utils.delete_file(path: str)[source]¶
Asynchronously delete a file.
- Parameters:
path (str) – Path to the file to delete.
- asyncyt.utils.get_id(url: str, config: DownloadConfig)[source]¶
Generate a unique ID for a download based on URL and config.
- Parameters:
url (str) – Download URL.
config (DownloadConfig) – Download configuration.
- Returns:
SHA256 hash string.
- Return type:
str
- asyncyt.utils.get_unique_filename(file: Path, title: str) Path [source]¶
Generate a unique filename in the same directory, avoiding overwrites.
- Parameters:
file (Path) – Original file path.
title (str) – Desired title for the file.
- Returns:
Unique file path.
- Return type:
Path
- asyncyt.utils.get_unique_path(dir: Path, name: str) Path [source]¶
Get Unique Path if path exists
- Parameters:
dir (Path) – The dir of the file
name (str) – the Original File name
- asyncyt.utils.is_audio_compatible(format: VideoFormat, codec: AudioCodec) bool [source]¶
Check if an audio codec is compatible with a container format.
- Parameters:
format (VideoFormat) – Video container format.
codec (AudioCodec) – Audio codec.
- Returns:
True if compatible, False otherwise.
- Return type:
bool
- asyncyt.utils.is_compatible(format: VideoFormat, codec: VideoCodec) bool [source]¶
Check if a video codec is compatible with a container format.
- Parameters:
format (VideoFormat) – Video container format.
codec (VideoCodec) – Video codec.
- Returns:
True if compatible, False otherwise.
- Return type:
bool
- asyncyt.utils.suggest_audio_compatible_formats(audio_codec: AudioCodec) List[VideoFormat] [source]¶
Suggest compatible container formats for a given audio codec.
- Parameters:
audio_codec (AudioCodec) – Audio codec.
- Returns:
List of compatible formats.
- Return type:
List[VideoFormat]
- asyncyt.utils.suggest_compatible_formats(video_codec: VideoCodec) List[VideoFormat] [source]¶
Suggest compatible container formats for a given video codec.
- Parameters:
video_codec (VideoCodec) – Video codec.
- Returns:
List of compatible formats.
- Return type:
List[VideoFormat]