Skip to content

Conversation

@vanyasem
Copy link
Contributor

@vanyasem vanyasem commented Nov 3, 2017

Добавил поддержку загрузки альбомов, для них введён отдельный аргумент (как в старой версии API): album_id

Загрузка по профилю (owner_id) остаётся на месте и всё так же чудесно работает

Прикрепляю example для теста

vk_api/audio.py Outdated
"""

if owner_id is None and album_id is None:
raise TypeError("get() missing 1 required argument: 'album_id' or 'owner_id'")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наверное слишком длинно, нужно чтобы короче 80 символов. И поменять на одинарные кавычки

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@python273
Copy link
Owner

хм, а где брать id альбомов?

@vanyasem
Copy link
Contributor Author

ID альбома из 2х частей состоит: userid_albumid. Для сообществ значение userid отрицательно.

Пример альбома: -56703560_85005375

@vanyasem
Copy link
Contributor Author

Сами альбомы можно или руками в профиле создавать, или в сообществах искать. Сейчас исполнители очень активно фишку использовать начали

@python273
Copy link
Owner

Наверное тогда стоит добавить загрузку списка альбомов пользователя/группы, иначе как-то не много смысла

@vanyasem
Copy link
Contributor Author

Логично, сейчас запилим 😃

@vanyasem
Copy link
Contributor Author

vanyasem commented Nov 10, 2017

Парсер альбомов сообщества / пользователя готов.

Поиск работать отказался. Запрос: act=audio_playlists-28905875&q=kizaru. В вебе отлично ищет, через Requests просто возвращает список всех альбомов (такое ощущение, что q где-то просирается). Это особенно странно, если учесть, что поиск с помощью q работает для аудиозаписей

@python273
Copy link
Owner

Нужно отдельным методом сделать, все засовывать в одну функцию - не очень

@vanyasem
Copy link
Contributor Author

ну там только урлы меняются, не хотелось копипастить. самого напрягло ) может, вынести в метод с параметрами просто?

@python273
Copy link
Owner

Просто вынеси в отдельный метод получение альбомов. То что код повторяться будет в методах - это окей

@vanyasem
Copy link
Contributor Author

Разделил поиск альбомов и поиск треков в разные методы. Поиск треков у пользователя и поиск треков в альбоме решил оставить в общем методе, ибо это одно и то же по сути

vk_api/audio.py Outdated
if not response.text:
raise AccessDenied(
'You don\'t have permissions to browse {}\'s audio'.format(
id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id shadowed built-in name id

""" Получить список аудиозаписей пользователя
:param owner_id: ID владельца (отрицательные значения для групп)
:param album_id: ID альбома (отрицательные значения для групп)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID альбомов тоже отрицательные?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да, я писал же выше

vk_api/audio.py Outdated
url = 'https://m.vk.com/audios{}'
if album_id is not None:
user_id = album_id
url = 'https://m.vk.com/audio?act=audio_playlist{}'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можешь вместо этого сделать

if album_id is not None:
    url = 'https://m.vk.com/audio?act=audio_playlist{}'.format(album_id)
else:
    url = 'https://m.vk.com/audios{}'.format(owner_id)

и убрать .format(user_id) ниже из запроса. Из AccessDenied можно убрать user_id тоже

@python273
Copy link
Owner

Еще пример нужно пофиксить. Думаю еще можно проще сделать - типа получение списка альбомов пользователя и получение списка аудио первого альбома

@vanyasem
Copy link
Contributor Author

сделано, сэр

break

for album in temp_albums:
albums.append(album)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

albums += temp_albums


offset += len(temp_albums)

print('\nLast 5:')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

последние 5 альбомов пользователя

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

там ниже [:5], значит первые?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну по сути то они первые, ибо отображаются альбомы сверху-вниз. от последнего к первому.


# Ищем треки последнего альбома
print('\nSearch for', albums[0]['title'])
tracks = vkaudio.get(album_id=albums[0]['id'][25:])
Copy link
Owner

@python273 python273 Nov 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[25:]

?

Copy link
Contributor Author

@vanyasem vanyasem Nov 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ой я идиот, это надо было в audio.py вынести. там у айдишника в начале мусор на 25 символов (что-то вроде audioplaylistblablabla)

@vanyasem
Copy link
Contributor Author

надо научится спать по ночам, с головой проблемы уже



def main():
""" Пример составления топа исполнителей для альбома вк """
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

надо бы обновить под новый смысл примера

@vanyasem
Copy link
Contributor Author

Merge it 😄

@python273 python273 merged commit 3c04df0 into python273:master Nov 18, 2017
@python273
Copy link
Owner

Не было времени затестить, вроде все норм 👍

@vanyasem
Copy link
Contributor Author

если что-то и не работает - будет второй ПР, я на базе этой фичи сейчас качалку делаю )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants