@@ -130,6 +130,8 @@ def get_iter(self, owner_id=None, album_id=None, access_hash=None):
130130 ids = scrap_ids (
131131 response ['data' ][0 ]['list' ]
132132 )
133+ if not ids :
134+ break
133135
134136 tracks = scrap_tracks (
135137 ids ,
@@ -138,9 +140,6 @@ def get_iter(self, owner_id=None, album_id=None, access_hash=None):
138140 convert_m3u8_links = self .convert_m3u8_links
139141 )
140142
141- if not tracks :
142- break
143-
144143 for i in tracks :
145144 yield i
146145
@@ -292,6 +291,8 @@ def search_iter(self, q, offset=0):
292291 ids = scrap_ids (
293292 json_response ['payload' ][1 ][1 ]['playlist' ]['list' ]
294293 )
294+ if not ids :
295+ break
295296
296297 if offset_left + len (ids ) >= offset :
297298 if offset_left < offset :
@@ -304,9 +305,6 @@ def search_iter(self, q, offset=0):
304305 http = self ._vk .http
305306 )
306307
307- if not tracks :
308- break
309-
310308 for track in tracks :
311309 yield track
312310
@@ -345,6 +343,8 @@ def get_updates_iter(self):
345343 ids = scrap_ids (
346344 [i [0 ] for i in updates if i ]
347345 )
346+ if not ids :
347+ break
348348
349349 tracks = scrap_tracks (
350350 ids ,
@@ -353,9 +353,6 @@ def get_updates_iter(self):
353353 http = self ._vk .http
354354 )
355355
356- if not tracks :
357- break
358-
359356 for track in tracks :
360357 yield track
361358
@@ -383,29 +380,21 @@ def get_popular_iter(self, offset=0):
383380 'https://vk.com/audio' ,
384381 data = {
385382 'block' : 'chart' ,
386- 'section' : 'explore '
383+ 'section' : 'recoms '
387384 }
388385 )
389386 json_response = json .loads (scrap_json (response .text ))
390387
391388 ids = scrap_ids (
392- json_response ['sectionData' ]['explore ' ]['playlist' ]['list' ]
389+ json_response ['sectionData' ]['recoms ' ]['playlist' ]['list' ]
393390 )
394391
395- if offset :
396- tracks = scrap_tracks (
397- ids [offset :],
398- self .user_id ,
399- convert_m3u8_links = self .convert_m3u8_links ,
400- http = self ._vk .http
401- )
402- else :
403- tracks = scrap_tracks (
404- ids ,
405- self .user_id ,
406- convert_m3u8_links = self .convert_m3u8_links ,
407- http = self ._vk .http
408- )
392+ tracks = scrap_tracks (
393+ ids [offset :] if offset else ids ,
394+ self .user_id ,
395+ convert_m3u8_links = self .convert_m3u8_links ,
396+ http = self ._vk .http
397+ )
409398
410399 for track in tracks :
411400 yield track
@@ -422,30 +411,22 @@ def get_news_iter(self, offset=0):
422411 'https://vk.com/audio' ,
423412 data = {
424413 'block' : 'new_songs' ,
425- 'section' : 'explore '
414+ 'section' : 'recoms '
426415 }
427416 )
428417 json_response = json .loads (scrap_json (response .text ))
429418
430419 ids = scrap_ids (
431- json_response ['sectionData' ]['explore ' ]['playlist' ]['list' ]
420+ json_response ['sectionData' ]['recoms ' ]['playlist' ]['list' ]
432421 )
433422
434423 if offset_left + len (ids ) >= offset :
435- if offset_left >= offset :
436- tracks = scrap_tracks (
437- ids ,
438- self .user_id ,
439- convert_m3u8_links = self .convert_m3u8_links ,
440- http = self ._vk .http
441- )
442- else :
443- tracks = scrap_tracks (
444- ids [offset - offset_left :],
445- self .user_id ,
446- convert_m3u8_links = self .convert_m3u8_links ,
447- http = self ._vk .http
448- )
424+ tracks = scrap_tracks (
425+ ids if offset_left >= offset else ids [offset - offset_left :],
426+ self .user_id ,
427+ convert_m3u8_links = self .convert_m3u8_links ,
428+ http = self ._vk .http
429+ )
449430
450431 for track in tracks :
451432 yield track
@@ -458,8 +439,8 @@ def get_news_iter(self, offset=0):
458439 data = {
459440 'al' : 1 ,
460441 'act' : 'load_catalog_section' ,
461- 'section_id' : json_response ['sectionData' ]['explore ' ]['sectionId' ],
462- 'start_from' : json_response ['sectionData' ]['explore ' ]['nextFrom' ]
442+ 'section_id' : json_response ['sectionData' ]['recoms ' ]['sectionId' ],
443+ 'start_from' : json_response ['sectionData' ]['recoms ' ]['nextFrom' ]
463444 }
464445 )
465446
@@ -468,25 +449,16 @@ def get_news_iter(self, offset=0):
468449 ids = scrap_ids (
469450 json_response ['payload' ][1 ][1 ]['playlist' ]['list' ]
470451 )
452+ if not ids :
453+ break
471454
472455 if offset_left + len (ids ) >= offset :
473- if offset_left >= offset :
474- tracks = scrap_tracks (
475- ids ,
476- self .user_id ,
477- convert_m3u8_links = self .convert_m3u8_links ,
478- http = self ._vk .http
479- )
480- else :
481- tracks = scrap_tracks (
482- ids [offset - offset_left :],
483- self .user_id ,
484- convert_m3u8_links = self .convert_m3u8_links ,
485- http = self ._vk .http
486- )
487-
488- if not tracks :
489- break
456+ tracks = scrap_tracks (
457+ ids if offset_left >= offset else ids [offset - offset_left :],
458+ self .user_id ,
459+ convert_m3u8_links = self .convert_m3u8_links ,
460+ http = self ._vk .http
461+ )
490462
491463 for track in tracks :
492464 yield track
@@ -613,7 +585,7 @@ def scrap_ids(audio_data):
613585
614586
615587def scrap_json (html_page ):
616- """ Парсинг списка хэшей ауфдиозаписей новинок или популярных + nextFrom&sessionId """
588+ """ Парсинг списка хэшей аудиозаписей новинок или популярных + nextFrom&sessionId """
617589
618590 find_json_pattern = r"new AudioPage\(.*?(\{.*\})"
619591 fr = re .search (find_json_pattern , html_page ).group (1 )
0 commit comments