Added base jsonlike return for player
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import disnake
|
import disnake
|
||||||
from disnake import Option
|
from disnake import Option
|
||||||
from disnake.ext import commands
|
from disnake.ext import commands
|
||||||
|
|
||||||
|
from lib import YandexPlayer
|
||||||
from lib.Logger import logger
|
from lib.Logger import logger
|
||||||
|
|
||||||
|
|
||||||
@@ -13,13 +15,15 @@ class Testing(commands.Cog, name='Testing'):
|
|||||||
logger.info(f'Cog {__name__.split(".")[1]} is ready!.')
|
logger.info(f'Cog {__name__.split(".")[1]} is ready!.')
|
||||||
|
|
||||||
@commands.slash_command(name='play', description='play audio test from yandex.music', options=[
|
@commands.slash_command(name='play', description='play audio test from yandex.music', options=[
|
||||||
Option(name='search', description='seach track/artist'),
|
Option(name='search',
|
||||||
Option(name='type', description='type of search',
|
description='seach track/artist',
|
||||||
choices=['all', 'artist', 'user', 'album', 'playlist', 'track', 'podcast', 'podcast_episode'])
|
required=True),
|
||||||
])
|
])
|
||||||
async def play(self, inter: disnake.ApplicationCommandInteraction, audio):
|
async def play(self, inter: disnake.ApplicationCommandInteraction, search: str):
|
||||||
# TODO add yandex_music player with queue, playlists
|
# TODO add yandex_music player with queue, playlists
|
||||||
pass
|
result = YandexPlayer.search(search)
|
||||||
|
await inter.response.send_message(result, ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot): # an extension must have a setup function
|
def setup(bot): # an extension must have a setup function
|
||||||
|
|||||||
@@ -2,10 +2,80 @@ import os
|
|||||||
|
|
||||||
from yandex_music import Client
|
from yandex_music import Client
|
||||||
|
|
||||||
client = Client(os.getenv('Yandex_Token')).init()
|
client = Client('AQAAAAAzqNkbAAG8XrWGNg9A5kCakiE_9HDst58').init()
|
||||||
|
|
||||||
|
|
||||||
def _search(_str: str, _type: str):
|
def search(_str: str, _type: str = 'all') -> dict:
|
||||||
search_result = client.search(_str, type_=_type)
|
search_result = client.search(_str, type_=_type)
|
||||||
print(search_result)
|
type_ = search_result.best.type
|
||||||
pass
|
best = search_result.best.result
|
||||||
|
# print(search_result)
|
||||||
|
if type_ == 'track':
|
||||||
|
artists = ''
|
||||||
|
if best.artists:
|
||||||
|
artists = ', '.join(artist.name for artist in best.artists)
|
||||||
|
if best.albums:
|
||||||
|
for i in best.albums:
|
||||||
|
album_id = i.id
|
||||||
|
album_title = i.title
|
||||||
|
else:
|
||||||
|
album_id = None
|
||||||
|
album_title = None
|
||||||
|
|
||||||
|
# Generate json for track
|
||||||
|
result_json = {
|
||||||
|
"artist": {
|
||||||
|
"id": best.id,
|
||||||
|
"name": artists
|
||||||
|
},
|
||||||
|
"track": {
|
||||||
|
"id": best.trackId,
|
||||||
|
"title": best.title
|
||||||
|
},
|
||||||
|
"album": {
|
||||||
|
"id": album_id,
|
||||||
|
"title": album_title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elif type_ == 'artist':
|
||||||
|
result_json = {
|
||||||
|
"artist": {
|
||||||
|
"id": best.id,
|
||||||
|
"name": best.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elif type_ == 'album':
|
||||||
|
artists = ''
|
||||||
|
if best.artists:
|
||||||
|
artists = ', '.join(artist.name for artist in best.artists)
|
||||||
|
for i in best.artists:
|
||||||
|
artist_id = i.id
|
||||||
|
artist_name = i.name
|
||||||
|
_tracks = []
|
||||||
|
tracks = {}
|
||||||
|
album = client.albums_with_tracks(best.id)
|
||||||
|
for i, volume in enumerate(album.volumes):
|
||||||
|
if len(album.volumes) > 1:
|
||||||
|
_tracks.append(f'💿 Диск {i + 1}')
|
||||||
|
_tracks += volume
|
||||||
|
_i = 1
|
||||||
|
for track in _tracks:
|
||||||
|
tracks[f"track_{_i}"] = {
|
||||||
|
"id": track.id,
|
||||||
|
"tittle": track.title
|
||||||
|
}
|
||||||
|
_i += 1
|
||||||
|
|
||||||
|
result_json = {
|
||||||
|
"artist": {
|
||||||
|
"id": artist_id,
|
||||||
|
"name": artist_name
|
||||||
|
},
|
||||||
|
"album": {
|
||||||
|
"id": best.id,
|
||||||
|
"title": best.title
|
||||||
|
},
|
||||||
|
"tracks": tracks
|
||||||
|
}
|
||||||
|
print(_type)
|
||||||
|
return result_json
|
||||||
|
|||||||
Reference in New Issue
Block a user