diff --git a/examples/music.py b/examples/music.py index 185481cb..d3a0d439 100644 --- a/examples/music.py +++ b/examples/music.py @@ -184,7 +184,7 @@ async def play(self, ctx, *, query: str): results = await player.node.get_tracks(query) # Results could be None if Lavalink returns an invalid response (non-JSON/non-200 (OK)). - # ALternatively, resullts.tracks could be an empty array if the query yielded no tracks. + # Alternatively, results.tracks could be an empty array if the query yielded no tracks. if not results or not results.tracks: return await ctx.send('Nothing found!') diff --git a/lavalink/__init__.py b/lavalink/__init__.py index e16325f3..bd59a31f 100644 --- a/lavalink/__init__.py +++ b/lavalink/__init__.py @@ -4,7 +4,7 @@ __author__ = 'Devoxin' __license__ = 'MIT' __copyright__ = 'Copyright 2017-present Devoxin' -__version__ = '4.0.3' +__version__ = '4.0.4' import inspect @@ -25,7 +25,8 @@ from .nodemanager import NodeManager from .playermanager import PlayerManager from .stats import Penalty, Stats -from .utils import decode_track, format_time, parse_time, timestamp_to_millis +from .utils import (decode_track, encode_track, format_time, parse_time, + timestamp_to_millis) from .websocket import WebSocket diff --git a/lavalink/client.py b/lavalink/client.py index 876206c5..136c0ab1 100644 --- a/lavalink/client.py +++ b/lavalink/client.py @@ -383,7 +383,7 @@ async def _hook_wrapper(hook, event): # clarity. tasks = [_hook_wrapper(hook, event) for hook in itertools.chain(generic_hooks, targeted_hooks)] - await asyncio.wait(tasks) + await asyncio.gather(*tasks) _log.debug('Dispatched \'%s\' to all registered hooks', type(event).__name__) diff --git a/lavalink/stats.py b/lavalink/stats.py index 9d80134f..1bb3f805 100644 --- a/lavalink/stats.py +++ b/lavalink/stats.py @@ -45,15 +45,8 @@ class Penalty: def __init__(self, stats): self.player_penalty = stats.playing_players self.cpu_penalty = 1.05 ** (100 * stats.system_load) * 10 - 10 - self.null_frame_penalty = 0 - self.deficit_frame_penalty = 0 - - if stats.frames_nulled != -1: - self.null_frame_penalty = (1.03 ** (500 * (stats.frames_nulled / 3000))) * 300 - 300 - self.null_frame_penalty *= 2 - - if stats.frames_deficit != -1: - self.deficit_frame_penalty = (1.03 ** (500 * (stats.frames_deficit / 3000))) * 600 - 600 + self.null_frame_penalty = ((1.03 ** (500 * (stats.frames_nulled / 3000))) * 300 - 300) * 2 + self.deficit_frame_penalty = (1.03 ** (500 * (stats.frames_deficit / 3000))) * 600 - 600 self.total = self.player_penalty + self.cpu_penalty + self.null_frame_penalty + self.deficit_frame_penalty @@ -128,9 +121,9 @@ def __init__(self, node, data): self.lavalink_load = cpu['lavalinkLoad'] frame_stats = data.get('frameStats', {}) - self.frames_sent = frame_stats.get('sent', -1) - self.frames_nulled = frame_stats.get('nulled', -1) - self.frames_deficit = frame_stats.get('deficit', -1) + self.frames_sent = frame_stats.get('sent', 0) + self.frames_nulled = frame_stats.get('nulled', 0) + self.frames_deficit = frame_stats.get('deficit', 0) self.penalty = Penalty(self) @classmethod diff --git a/lavalink/utils.py b/lavalink/utils.py index 59ff63ae..d5babdfd 100644 --- a/lavalink/utils.py +++ b/lavalink/utils.py @@ -22,9 +22,10 @@ SOFTWARE. """ import struct +from base64 import b64encode from typing import Tuple -from .datarw import DataReader +from .datarw import DataReader, DataWriter from .models import AudioTrack @@ -159,23 +160,23 @@ def decode_track(track: str) -> AudioTrack: return AudioTrack(track_object, 0, position=position, encoder_version=version) -# def encode_track(track: dict): -# assert {'title', 'author', 'length', 'identifier', 'is_stream', 'uri', 'source', 'position'} == track.keys() +def encode_track(track: dict): + assert {'title', 'author', 'length', 'identifier', 'isStream', 'uri', 'sourceName', 'position'} == track.keys() -# writer = DataWriter() + writer = DataWriter() -# version = struct.pack('B', 2) -# writer.write_byte(version) -# writer.write_utf(track['title']) -# writer.write_utf(track['author']) -# writer.write_long(track['length']) -# writer.write_utf(track['identifier']) -# writer.write_boolean(track['is_stream']) -# writer.write_boolean(track['uri']) -# writer.write_utf(track['uri']) -# writer.write_utf(track['source']) -# writer.write_long(track['position']) + version = struct.pack('B', 2) + writer.write_byte(version) + writer.write_utf(track['title']) + writer.write_utf(track['author']) + writer.write_long(track['length']) + writer.write_utf(track['identifier']) + writer.write_boolean(track['isStream']) + writer.write_boolean(track['uri']) + writer.write_utf(track['uri']) + writer.write_utf(track['sourceName']) + writer.write_long(track['position']) -# enc = writer.finish() -# b64 = b64encode(enc) -# return b64 + enc = writer.finish() + b64 = b64encode(enc) + return b64