Skip to content

Commit 495ecb7

Browse files
qwertyadrianpython273
authored andcommitted
Исправлено получение аудиозаписей из постов
1 parent e775b1f commit 495ecb7

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

vk_api/audio.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def get_post_audio(self, owner_id, post_id):
525525

526526
ids = scrap_ids_from_html(
527527
response.text,
528-
filter_root_el={'class': 'audios_list'}
528+
filter_root_el={'class': 'AttachmentsList'}
529529
)
530530

531531
return scrap_tracks(
@@ -615,16 +615,30 @@ def scrap_ids_from_html(html, filter_root_el=None):
615615
for playlist in playlist_snippets:
616616
playlist.decompose()
617617

618-
for audio in root_el.find_all('div', {'class': 'audio_item'}):
618+
tag_name = ('div', {'class': 'audio_item'})
619+
if 'AttachmentsList' in filter_root_el.values():
620+
tag_name = ('button', {'class': 'SecondaryAttachment'})
621+
622+
for audio in root_el.find_all(*tag_name):
619623
if 'audio_item_disabled' in audio['class']:
620624
continue
621625

626+
if 'data-audio' not in audio.attrs:
627+
continue
628+
622629
data_audio = json.loads(audio['data-audio'])
623-
audio_hashes = data_audio[13].split("/")
624630

625-
full_id = (
626-
str(data_audio[1]), str(data_audio[0]), audio_hashes[2], audio_hashes[5]
627-
)
631+
if isinstance(data_audio, list):
632+
audio_hashes = data_audio[13].split("/")
633+
full_id = (
634+
str(data_audio[1]), str(data_audio[0]),
635+
audio_hashes[2], audio_hashes[5]
636+
)
637+
else:
638+
full_id = (
639+
str(data_audio['owner_id']), str(data_audio['id']),
640+
data_audio['actionHash'], data_audio['urlHash']
641+
)
628642

629643
if all(full_id):
630644
ids.append(full_id)

0 commit comments

Comments
 (0)