Skip to content

Commit 99ede5b

Browse files
committed
Add VkUpload.audio
1 parent 78f45f4 commit 99ede5b

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

vk_api/vk_upload.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,30 @@ def photo_wall(self, photos, user_id=None, group_id=None):
112112

113113
return response
114114

115+
def audio(self, file_path, artist, title):
116+
""" Загрузка аудио
117+
118+
:param file_path: путь к аудиофайлу
119+
:param artist: исполнитель
120+
:param title: название
121+
"""
122+
123+
url = self.vk.method('audio.getUploadServer')['upload_url']
124+
125+
filetype = file_path.split('.')[-1]
126+
audio_file = [(('file', ( 'file.' + filetype, open(file_path, 'rb'))))]
127+
128+
response = self.vk.http.post(url, files=audio_file).json()
129+
130+
response.update({
131+
'artist': artist,
132+
'title': title
133+
})
134+
135+
response = self.vk.method('audio.save', response)
136+
137+
return response
138+
115139
def document(self, file_path, title=None, tags=None, group_id=None):
116140
""" Загрузка документа
117141

0 commit comments

Comments
 (0)