diff --git a/vk_api/audio.py b/vk_api/audio.py index e7330fd..3409b3e 100644 --- a/vk_api/audio.py +++ b/vk_api/audio.py @@ -128,6 +128,8 @@ def get_iter(self, owner_id=None, album_id=None, access_hash=None): ids = scrap_ids( response['data'][0]['list'] ) + if not ids: + break tracks = scrap_tracks( ids, @@ -136,9 +138,6 @@ def get_iter(self, owner_id=None, album_id=None, access_hash=None): convert_m3u8_links=self.convert_m3u8_links ) - if not tracks: - break - for i in tracks: yield i @@ -290,6 +289,8 @@ def search_iter(self, q, offset=0): ids = scrap_ids( json_response['payload'][1][1]['playlist']['list'] ) + if not ids: + break if offset_left + len(ids) >= offset: if offset_left < offset: @@ -302,9 +303,6 @@ def search_iter(self, q, offset=0): http=self._vk.http ) - if not tracks: - break - for track in tracks: yield track @@ -343,6 +341,8 @@ def get_updates_iter(self): ids = scrap_ids( [i[0] for i in updates if i] ) + if not ids: + break tracks = scrap_tracks( ids, @@ -351,9 +351,6 @@ def get_updates_iter(self): http=self._vk.http ) - if not tracks: - break - for track in tracks: yield track @@ -381,29 +378,21 @@ def get_popular_iter(self, offset=0): 'https://vk.com/audio', data={ 'block': 'chart', - 'section': 'explore' + 'section': 'recoms' } ) json_response = json.loads(scrap_json(response.text)) ids = scrap_ids( - json_response['sectionData']['explore']['playlist']['list'] + json_response['sectionData']['recoms']['playlist']['list'] ) - if offset: - tracks = scrap_tracks( - ids[offset:], - self.user_id, - convert_m3u8_links=self.convert_m3u8_links, - http=self._vk.http - ) - else: - tracks = scrap_tracks( - ids, - self.user_id, - convert_m3u8_links=self.convert_m3u8_links, - http=self._vk.http - ) + tracks = scrap_tracks( + ids[offset:] if offset else ids, + self.user_id, + convert_m3u8_links=self.convert_m3u8_links, + http=self._vk.http + ) for track in tracks: yield track @@ -420,30 +409,22 @@ def get_news_iter(self, offset=0): 'https://vk.com/audio', data={ 'block': 'new_songs', - 'section': 'explore' + 'section': 'recoms' } ) json_response = json.loads(scrap_json(response.text)) ids = scrap_ids( - json_response['sectionData']['explore']['playlist']['list'] + json_response['sectionData']['recoms']['playlist']['list'] ) if offset_left + len(ids) >= offset: - if offset_left >= offset: - tracks = scrap_tracks( - ids, - self.user_id, - convert_m3u8_links=self.convert_m3u8_links, - http=self._vk.http - ) - else: - tracks = scrap_tracks( - ids[offset - offset_left:], - self.user_id, - convert_m3u8_links=self.convert_m3u8_links, - http=self._vk.http - ) + tracks = scrap_tracks( + ids if offset_left >= offset else ids[offset - offset_left:], + self.user_id, + convert_m3u8_links=self.convert_m3u8_links, + http=self._vk.http + ) for track in tracks: yield track @@ -456,8 +437,8 @@ def get_news_iter(self, offset=0): data={ 'al': 1, 'act': 'load_catalog_section', - 'section_id': json_response['sectionData']['explore']['sectionId'], - 'start_from': json_response['sectionData']['explore']['nextFrom'] + 'section_id': json_response['sectionData']['recoms']['sectionId'], + 'start_from': json_response['sectionData']['recoms']['nextFrom'] } ) @@ -466,25 +447,16 @@ def get_news_iter(self, offset=0): ids = scrap_ids( json_response['payload'][1][1]['playlist']['list'] ) + if not ids: + break if offset_left + len(ids) >= offset: - if offset_left >= offset: - tracks = scrap_tracks( - ids, - self.user_id, - convert_m3u8_links=self.convert_m3u8_links, - http=self._vk.http - ) - else: - tracks = scrap_tracks( - ids[offset - offset_left:], - self.user_id, - convert_m3u8_links=self.convert_m3u8_links, - http=self._vk.http - ) - - if not tracks: - break + tracks = scrap_tracks( + ids if offset_left >= offset else ids[offset - offset_left:], + self.user_id, + convert_m3u8_links=self.convert_m3u8_links, + http=self._vk.http + ) for track in tracks: yield track @@ -561,7 +533,7 @@ def scrap_ids(audio_data): def scrap_json(html_page): - """ Парсинг списка хэшей ауфдиозаписей новинок или популярных + nextFrom&sessionId """ + """ Парсинг списка хэшей аудиозаписей новинок или популярных + nextFrom&sessionId """ find_json_pattern = r"new AudioPage\(.*?(\{.*\})" fr = re.search(find_json_pattern, html_page).group(1)