Skip to content

vkpymusic.utils

This module contains utilities for conversion and logging.

Classes:

Name Description
Converter

A class for performing various conversion operations.

create_logger

A function for getting or creating a logger.

download_m3u8_as_mp3_pyav

A function for downloading m3u8 stream and converting to mp3.

Converter

A class that converts a response from VK to a list of songs or playlists.

response_to_songs(response) staticmethod

Converts a response to a list of songs.

Parameters:

Name Type Description Default
response VkApiResponse

The response object from VK.

required

Returns:

Type Description
List[Song]

List[Song]: A list of songs converted from the response.

response_to_playlists(response) staticmethod

Converts a response to a list of playlists.

Parameters:

Name Type Description Default
response VkApiResponse

The response object from VK.

required

Returns:

Type Description
List[Playlist]

List[Playlist]: A list of playlists converted from the response.

response_to_userinfo(response) staticmethod

Converts a response to a UserInfo.

Parameters:

Name Type Description Default
response VkApiResponse

The response object from VK.

required

Returns:

Name Type Description
UserInfo UserInfo

A UserInfo converted from the response.

Converts a response to a list of POPULAR songs.

Parameters:

Name Type Description Default
response VkApiResponse

The response object from VK.

required

Returns:

Type Description
List[Song]

List[Song]: A list of songs converted from the response.

on_captcha_handler(redirect_uri)

Default sync handler for captcha. Opens a browser window for the user to solve VK ID Captcha.

Parameters:

Name Type Description Default
redirect_uri str

redirect_uri for solving VK ID Captcha.

required

Returns:

Name Type Description
str str

success_token after captcha is solved.

on_2fa_handler()

Default sync handler to 2fa.

Returns:

Name Type Description
str str

code from VK/SMS.

on_invalid_client_handler()

Default sync handler to invalid_client.

on_critical_error_handler(response_or_error)

Default sync handler to critical error.

Parameters:

Name Type Description Default
response_or_error ...

Message or object to research.

required

on_captcha_handler_async(data) async

Default async handler for captcha. Opens a browser window for the user to solve VK ID Captcha.

Parameters:

Name Type Description Default
data Dict

Error details from VK API containing redirect_uri.

required

Returns:

Name Type Description
str str

success_token after captcha is solved.

on_2fa_handler_async() async

Default async handler to 2fa.

Returns:

Name Type Description
str str

code from VK/SMS.

on_invalid_client_handler_async() async

Default async handler to invalid_client.

on_critical_error_handler_async(response_or_error) async

Default async handler to critical error.

Parameters:

Name Type Description Default
response_or_error ...

Message or object to research.

required

create_logger(name, console=True, file=True)

Returns a logger instance with configured handlers.

Parameters:

Name Type Description Default
name str

The name of the logger.

required
console bool

Whether to enable debug messages in the console.

True
file bool

Whether to enable debug messages in the log file.

True

Returns:

Name Type Description
logger Logger

A logger instance with configured handlers.

download_m3u8_as_mp3_pyav(url, output_path)

Download m3u8 stream and convert to mp3 using PyAV (no ffmpeg CLI required).

Parameters:

Name Type Description Default
url str

URL of the m3u8 playlist.

required
output_path str

Path to the output mp3 file.

required