Skip to content

Commit 13149b9

Browse files
vanyasempython273
authored andcommitted
Update audio url decryption script (#104)
* Update audio url decryption script * Remove audio link formatting
1 parent 0ccf762 commit 13149b9

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

examples/get_album_audio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
import collections
1+
# -*- coding: utf-8 -*-
32

43
import vk_api
54
from vk_api.audio import VkAudio

vk_api/audio.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
class VkAudio:
1313

14-
__slots__ = ('_vk',)
14+
__slots__ = ('_vk', 'user_id')
1515

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

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

52-
return scrap_data(response.text)
53+
return scrap_data(response.text, self.user_id)
5354

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

101102
return [
102-
i for i in scrap_data(response.text)
103+
i for i in scrap_data(response.text, self.user_id)
103104
if RE_AUDIO.search(i['id'])
104105
]
105106

@@ -119,10 +120,10 @@ def search(self, q='', offset=0):
119120
}
120121
)
121122

122-
return scrap_data(response.text)
123+
return scrap_data(response.text, self.user_id)
123124

124125

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

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

135136
if 'audio_api_unavailable' in link:
136-
link = decode_audio_url(link)
137+
link = decode_audio_url(link, user_id)
137138

138139
tracks.append({
139140
'artist': artist,

vk_api/audio_url_decoder.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def splice(l, a, b, c):
1919
return l[:a] + [c] + l[a + b:], l[a:a + b]
2020

2121

22-
def decode_audio_url(string):
22+
def decode_audio_url(string, user_id):
2323
vals = string.split("?extra=", 1)[1].split("#")
2424

2525
tstr = vk_o(vals[0])
@@ -38,6 +38,8 @@ def decode_audio_url(string):
3838
tstr = vk_xor(tstr, arg[0])
3939
elif cmd == 's':
4040
tstr = vk_s(tstr, arg[0])
41+
elif cmd == 'i':
42+
tstr = vk_i(tstr, arg[0], user_id)
4143
else:
4244
raise VkAudioUrlDecodeError(
4345
'Unknown decode cmd: "{}"; Please send bugreport'.format(cmd)
@@ -107,8 +109,8 @@ def vk_s_child(t, e):
107109
e = int(e)
108110

109111
for a in range(i - 1, -1, -1):
110-
e = abs(e) + a + i
111-
o.append(e % i | 0)
112+
e = (i * (a + 1) ^ e + a) % i
113+
o.append(e)
112114

113115
return o[::-1]
114116

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

129131
return ''.join(t)
132+
133+
134+
def vk_i(t, e, user_id):
135+
return vk_s(t, int(e) ^ user_id)

0 commit comments

Comments
 (0)