R
R
Ram response 2002022-02-28 06:10:07
Python
Ram response 200, 2022-02-28 06:10:07

Why audio downloaded from VK is not played?

Greetings, there is such a code that downloads audio from VK. But after downloading, the audio is not playing.
How to solve it?

import vk_api
from vk_api import audio
import requests
from time import time
import os

REQUEST_STATUS_CODE = 200
name_dir = 'music_vk'
path = r'C:\\Python\\' + name_dir
login = ''  # Номер телефона
password = ''  # Пароль
my_id = ''  # Ваш id vk

if not os.path.exists(path):
    os.makedirs(path)

vk_session = vk_api.VkApi(login=login, password=password)
vk_session.auth()
vk = vk_session.get_api()
vk_audio = audio.VkAudio(vk_session)

os.chdir(path)

time_start = time()
for i in vk_audio.get(owner_id=my_id):
    try:
        r = requests.get(i["url"])
        if r.status_code == REQUEST_STATUS_CODE:
            with open(i["artist"] + '_' + i["title"] + '.wav', 'wb') as output_file:
                output_file.write(r.content)
    except OSError:
        print(i["artist"] + '_' + i["title"])
time_finish = time()
print("Time seconds:", time_finish - time_start)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question