|
21 | 21 | RE_ACCESS_HASH = re.compile(r'access_hash=(\w+)') |
22 | 22 | RE_M3U8_TO_MP3 = re.compile(r'/[0-9a-f]+(/audios)?/([0-9a-f]+)/index.m3u8') |
23 | 23 |
|
| 24 | +RE_USER_AUDIO_HASH = re.compile(r"AudioUtils.(un)?followOwner\(\d+, '([^)]+)'\)") |
| 25 | + |
24 | 26 | RPS_DELAY_RELOAD_AUDIO = 1.5 |
25 | 27 | RPS_DELAY_LOAD_SECTION = 2.0 |
26 | 28 |
|
@@ -543,6 +545,56 @@ def get_post_audio(self, owner_id, post_id): |
543 | 545 |
|
544 | 546 | return tracks |
545 | 547 |
|
| 548 | + def follow_user(self, user_id): |
| 549 | + data = self._vk.http.get(f"https://vk.com/audios{user_id}") |
| 550 | + |
| 551 | + user_hash = RE_USER_AUDIO_HASH.search(data.text) |
| 552 | + if user_hash is None: |
| 553 | + raise AccessDenied( |
| 554 | + 'You don\'t have permissions to browse {}\'s audio'.format( |
| 555 | + user_id |
| 556 | + ) |
| 557 | + ) |
| 558 | + user_hash = user_hash.groups()[1] |
| 559 | + |
| 560 | + response = self._vk.http.post( |
| 561 | + 'https://vk.com/al_audio.php', |
| 562 | + data={ |
| 563 | + 'al': 1, |
| 564 | + 'act': 'follow_owner', |
| 565 | + 'owner_id': user_id, |
| 566 | + 'hash': user_hash, |
| 567 | + } |
| 568 | + ) |
| 569 | + json_response = json.loads(response.text.replace('<!--', '')) |
| 570 | + |
| 571 | + return json_response |
| 572 | + |
| 573 | + def unfollow_user(self, user_id): |
| 574 | + data = self._vk.http.get(f"https://vk.com/audios{user_id}") |
| 575 | + |
| 576 | + user_hash = RE_USER_AUDIO_HASH.search(data.text) |
| 577 | + if user_hash is None: |
| 578 | + raise AccessDenied( |
| 579 | + 'You don\'t have permissions to browse {}\'s audio'.format( |
| 580 | + user_id |
| 581 | + ) |
| 582 | + ) |
| 583 | + user_hash = user_hash.groups()[1] |
| 584 | + |
| 585 | + response = self._vk.http.post( |
| 586 | + 'https://vk.com/al_audio.php', |
| 587 | + data={ |
| 588 | + 'al': 1, |
| 589 | + 'act': 'unfollow_owner', |
| 590 | + 'owner_id': user_id, |
| 591 | + 'hash': user_hash, |
| 592 | + } |
| 593 | + ) |
| 594 | + json_response = json.loads(response.text.replace('<!--', '')) |
| 595 | + |
| 596 | + return json_response |
| 597 | + |
546 | 598 |
|
547 | 599 | def scrap_ids(audio_data): |
548 | 600 | """ Парсинг списка хэшей аудиозаписей из json объекта """ |
|
0 commit comments