Reference for youtube_dl_scraper/converter/audio_converter.py
¶
youtube_dl_scraper.converter.audio_converter.AudioConverter
¶
AudioConverter(input_path: str, output_path: str, audio_codec: Optional[str], bitrate: Optional[str] = None, force_render: bool = False, experimental: bool = True)
Bases: BaseConverter
AudioConverter class provides functionality to convert audio files into different formats by re-encoding or copying the existing audio stream with the specified audio codec.
Attributes:
Name | Type | Description |
---|---|---|
input_path |
str
|
Path to the input audio or video file. |
output_path |
str
|
Path to the output audio file. |
audio_codec |
str
|
Desired audio codec (e.g., "aac", "mp3"). |
bitrate |
Optional[str]
|
Desired audio bitrate (e.g., "128k", "192k"). |
force_render |
bool
|
If True, forces re-rendering even if codecs match. |
experimental |
bool
|
If True, allow for experimental codec supported by ffmpeg else don't. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_path
|
str
|
Path to the input file (audio or video). |
required |
output_path
|
str
|
Path to the output audio file. |
required |
audio_codec
|
Optional[str]
|
Desired audio codec (e.g., "aac", "mp3"). |
required |
bitrate
|
Optional[str]
|
Desired audio bitrate (e.g., "128k", "192k"). |
None
|
force_render
|
bool
|
If True, force re-rendering even if codecs match. |
False
|
experimental
|
bool
|
If True, allow for experimental codec supported by ffmpeg else don't. |
True
|
Source code in youtube_dl_scraper/converter/audio_converter.py
convert
¶
Perform the conversion.
Converts input audio or video file into the desired audio format, with an optional bitrate.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path to the converted audio file if successful. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the input file does not exist or the output file was not created. |
Source code in youtube_dl_scraper/converter/audio_converter.py
get_audio_codec
staticmethod
¶
Retrieve the audio codec of a file using ffmpeg-python.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Path to the file (audio or video). |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The audio codec of the file, or None if no audio stream is found. |
Source code in youtube_dl_scraper/converter/audio_converter.py
get_default_extension
¶
Determine the appropriate file extension based on the audio codec.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A suitable file extension (e.g., ".mp3", ".m4a"). |