66from .audio_url_decoder import decode_audio_url
77from .exceptions import AccessDenied
88
9- RE_AUDIO = re .compile (r'audio\d +_\d+_audios\d+' )
9+ RE_AUDIO = re .compile (r'audio[-\d] +_\d+_audios\d+' )
1010
1111
1212class VkAudio :
@@ -30,12 +30,16 @@ def get(self, owner_id=None, album_id=None, offset=0):
3030 )
3131 elif owner_id is not None and album_id is not None :
3232 raise TypeError ('get() too many arguments' )
33+ if album_id is not None and get_albums is True :
34+ raise TypeError ('get() too many arguments' )
3335
3436 id = owner_id
3537 url = 'https://m.vk.com/audios{}'
3638 if album_id is not None :
3739 id = album_id
3840 url = 'https://m.vk.com/audio?act=audio_playlist{}'
41+ if get_albums is True :
42+ url = 'https://m.vk.com/audio?act=audio_playlists{}'
3943
4044 response = self ._vk .http .get (
4145 url .format (id ),
@@ -52,6 +56,8 @@ def get(self, owner_id=None, album_id=None, offset=0):
5256 )
5357 )
5458
59+ if get_albums :
60+ return scrap_albums (response .text )
5561 return scrap_data (response .text )
5662
5763 def search_user (self , owner_id , q = '' ):
@@ -123,3 +129,22 @@ def scrap_data(html):
123129 })
124130
125131 return tracks
132+
133+
134+ def scrap_albums (html ):
135+ """ Парсинг списка альбомов из html странцы """
136+
137+ soup = BeautifulSoup (html , 'html.parser' )
138+ albums = []
139+ for album in soup .find_all ('div' , {'class' : 'audioPlaylistsPage__item' }):
140+ link = album .select ('.audioPlaylistsPage__itemLink' )[0 ]['href' ]
141+
142+ albums .append ({
143+ 'artist' : album .select ('.audioPlaylistsPage__author' )[0 ].text ,
144+ 'title' : album .select ('.audioPlaylistsPage__title' )[0 ].text ,
145+ 'plays' : album .select ('.audioPlaylistsPage__stats' )[0 ].text ,
146+ 'id' : album ['class' ][1 ],
147+ 'url' : 'https://m.vk.com/audio?act=audio_playlist{}' .format (link )
148+ })
149+
150+ return albums
0 commit comments