Skip to content

vkpymusic.models.song

This module contains the Song class.

Classes

Song

A class that represents a song.

Attributes:

Name Type Description
title str

The title of the song.

artist str

The artist of the song.

duration int

The duration of the song in seconds.

track_id str

The ID of the song.

owner_id str

The ID of the song's owner.

url str

The URL of the song.

Functions

__init__(title, artist, duration, track_id, owner_id, url='')

Initializes a Song object.

Parameters:

Name Type Description Default
title str

The title of the song.

required
artist str

The artist of the song.

required
duration int

The duration of the song in seconds.

required
track_id str

The ID of the song.

required
owner_id str

The ID of the song's owner.

required
url str

The URL of the song.

''
to_dict()

Converts the song to a dictionary.

Returns:

Name Type Description
dict dict

The song as a dictionary.

to_safe()

Removes all non-alphanumeric characters from the song's title and artist.

from_json(item) classmethod

Creates a Song object from a JSON object.

Parameters:

Name Type Description Default
item dict

A JSON object.

required

Returns:

Name Type Description
Song Song

A Song object.