Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/get_album_audio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
import collections
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ненужный импорт висел с прошлого ПРа, забыл убрать

# -*- coding: utf-8 -*-

import vk_api
from vk_api.audio import VkAudio
Expand Down
13 changes: 7 additions & 6 deletions vk_api/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

class VkAudio:

__slots__ = ('_vk',)
__slots__ = ('_vk', 'user_id')

def __init__(self, vk):
self.user_id = vk.get_api().users.get()[0]['id']
self._vk = vk

def get(self, owner_id=None, album_id=None, offset=0):
Expand Down Expand Up @@ -49,7 +50,7 @@ def get(self, owner_id=None, album_id=None, offset=0):
'You don\'t have permissions to browse user\'s audio'
)

return scrap_data(response.text)
return scrap_data(response.text, self.user_id)

def get_albums(self, owner_id, offset=0):
""" Получить список альбомов пользователя
Expand Down Expand Up @@ -99,7 +100,7 @@ def search_user(self, owner_id, q=''):
)

return [
i for i in scrap_data(response.text)
i for i in scrap_data(response.text, self.user_id)
if RE_AUDIO.search(i['id'])
]

Expand All @@ -119,10 +120,10 @@ def search(self, q='', offset=0):
}
)

return scrap_data(response.text)
return scrap_data(response.text, self.user_id)


def scrap_data(html):
def scrap_data(html, user_id):
""" Парсинг списка аудиозаписей из html странцы """

soup = BeautifulSoup(html, 'html.parser')
Expand All @@ -133,7 +134,7 @@ def scrap_data(html):
link = audio.select('.ai_body')[0].input['value']

if 'audio_api_unavailable' in link:
link = decode_audio_url(link)
link = decode_audio_url(link, user_id)

tracks.append({
'artist': artist,
Expand Down
12 changes: 9 additions & 3 deletions vk_api/audio_url_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def splice(l, a, b, c):
return l[:a] + [c] + l[a + b:], l[a:a + b]


def decode_audio_url(string):
def decode_audio_url(string, user_id):
vals = string.split("?extra=", 1)[1].split("#")

tstr = vk_o(vals[0])
Expand All @@ -38,6 +38,8 @@ def decode_audio_url(string):
tstr = vk_xor(tstr, arg[0])
elif cmd == 's':
tstr = vk_s(tstr, arg[0])
elif cmd == 'i':
tstr = vk_i(tstr, arg[0], user_id)
else:
raise VkAudioUrlDecodeError(
'Unknown decode cmd: "{}"; Please send bugreport'.format(cmd)
Expand Down Expand Up @@ -107,8 +109,8 @@ def vk_s_child(t, e):
e = int(e)

for a in range(i - 1, -1, -1):
e = abs(e) + a + i
o.append(e % i | 0)
e = (i * (a + 1) ^ e + a) % i
o.append(e)

return o[::-1]

Expand All @@ -127,3 +129,7 @@ def vk_s(t, e):
t[a] = y[0]

return ''.join(t)


def vk_i(t, e, user_id):
return vk_s(t, int(e) ^ user_id)