Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
i: function(e, t) {
return i.s(e, t ^ vk.id)
},Там не просто, надо еще прикинуться, например, андроидом и по-хитрому получить несколтко токенов, чтобы это сработало. На гитхабе видел реализацию, но у меня что-то пошло не так.
def create_playlist_file(self, user_id: Union[int, str]) -> str:
# Probably it is better to separate it all to different methods
all_music_link = f'https://api.vk.com/method/audio.get?owner_id={user_id}&access_token={self.token}&v=5.85'
all_music = requests.get(all_music_link).json()['response']['items']
song_ids = []
# Create unique song ids
for song in all_music:
if not song.get('access_key'):
continue
access_key = song['access_key']
song_id = song['id']
song_ids.append(f'{user_id}_{song_id}_{access_key}')
splited_song_ids = self.group(song_ids, 200) # Grouping ids because of VK API limits for songs in one request
result = OrderedDict() # OrderedDict here and below is to specify order of songs like in a real playlist
for chunk in splited_song_ids:
# Making one request to get data for each 200 songs
ids_for_request = ','.join(chunk)
data = {'audios': ids_for_request, 'access_token': self.token, 'v': '5.85'}
songs_with_urls = requests.post('https://api.vk.com/method/audio.getById', data=data).json()['response']
sleep(0.5) # Excepting VK API rate limit
# Getting only needed data for each song to create a beautiful playlist file
for song in songs_with_urls:
id_ = song['id']
author = song.get('artist')
title = song.get('title')
src = song.get('url')
if not src:
is_blocked = True
else:
is_blocked = False
needed_data = OrderedDict(author=author, title=title, src=src, is_blocked=is_blocked)
result[id_] = needed_dataДанная страница будет полезной для тех, кто решил взять заказ на парсер аудио-треков VK и резко понял, что ничего не понял.
Получение ссылок на аудио без VKApi