diff --git a/pomice/__init__.py b/pomice/__init__.py index 815678f..61c3da8 100644 --- a/pomice/__init__.py +++ b/pomice/__init__.py @@ -18,7 +18,7 @@ if not discord.__version__.startswith("2.0"): "Uninstall your current version and install discord.py 2.0 or a compatible fork." ) -__version__ = "1.1.6" +__version__ = "1.1.7" __title__ = "pomice" __author__ = "cloudwithax" diff --git a/pomice/filters.py b/pomice/filters.py index f135c5e..207151c 100644 --- a/pomice/filters.py +++ b/pomice/filters.py @@ -37,11 +37,6 @@ class Equalizer(Filter): return _dict - def _reset(self): - self.raw = [(0, .0), (1, .0), (2, .0), (3, .0), (4, .0), - (5, .0), (6, .0), (7, .0), (8, .0), (9, .0), - (10, .0), (11, .0), (12, .0), (13, .0), (14, .0)] - self.eq = self._factory(levels=self.raw) self.payload = {"equalizer": self.eq} @@ -82,18 +77,6 @@ class Timescale(Filter): "pitch": self.pitch, "rate": self.rate}} - def _reset(self): - self.speed = 1.0 - self.pitch = 1.0 - self.rate = 1.0 - - self.payload = {"timescale": {"speed": self.speed, - "pitch": self.pitch, - "rate": self.rate}} - - return self.payload - - def __repr__(self): return f"" @@ -123,20 +106,6 @@ class Karaoke(Filter): "filterBand": self.filter_band, "filterWidth": self.filter_width}} - def _reset(self): - self.level: float = 1.0 - self.mono_level: float = 1.0 - self.filter_band: float = 220.0 - self.filter_width: float = 100.0 - - self.payload = {"karaoke": {"level": self.level, - "monoLevel": self.mono_level, - "filterBand": self.filter_band, - "filterWidth": self.filter_width}} - - - return self.payload - def __repr__(self): return ( f"" @@ -209,15 +168,6 @@ class Vibrato(Filter): self.payload = {"vibrato": {"frequency": self.frequency, "depth": self.depth}} - - def _reset(self): - self.frequency: float = 2.0 - self.depth: float = 0.5 - - self.payload = {"vibrato": {"frequency": self.frequency, - "depth": self.depth}} - - return self.payload def __repr__(self): return f"" @@ -234,12 +184,6 @@ class Rotation(Filter): self.rotation_hertz = rotation_hertz self.payload = {"rotation": {"rotationHz": self.rotation_hertz}} - def _reset(self): - self.rotation_hertz = 5 - self.payload = {"rotation": {"rotationHz": self.rotation_hertz}} - - return self.payload - def __repr__(self) -> str: return f"" @@ -283,19 +227,6 @@ class ChannelMix(Filter): "rightToRight": self.right_to_right} } - def _reset(self): - self.left_to_left: float = 1 - self.right_to_right: float = 1 - self.left_to_right: float = 0 - self.right_to_left: float = 0 - - self.payload = {"channelMix": {"leftToLeft": self.left_to_left, - "leftToRight": self.left_to_right, - "rightToLeft": self.right_to_left, - "rightToRight": self.right_to_right} - } - - return self.payload def __repr__(self) -> str: return ( @@ -342,30 +273,6 @@ class Distortion(Filter): "scale": self.scale }} - def _reset(self): - self.sin_offset: float = 0 - self.sin_scale: float = 1 - self.cos_offset: float = 0 - self.cos_scale: float = 1 - self.tan_offset: float = 0 - self.tan_scale: float = 1 - self.offset: float = 0 - self.scale: float = 1 - - self.payload = {"distortion": { - "sinOffset": self.sin_offset, - "sinScale": self.sin_scale, - "cosOffset": self.cos_offset, - "cosScale": self.cos_scale, - "tanOffset": self.tan_offset, - "tanScale": self.tan_scale, - "offset": self.offset, - "scale": self.scale - }} - - return self.payload - - def __repr__(self) -> str: return ( f" " @@ -385,12 +292,6 @@ class LowPass(Filter): self.smoothing = smoothing self.payload = {"lowPass": {"smoothing": self.smoothing}} - def _reset(self): - self.smoothing = 20 - self.payload = {"lowPass": {"smoothing": self.smoothing}} - - return self.payload - def __repr__(self) -> str: return f"" diff --git a/pomice/objects.py b/pomice/objects.py index a91eb13..8a868bc 100644 --- a/pomice/objects.py +++ b/pomice/objects.py @@ -37,6 +37,7 @@ class Track: self.author = info.get("author") self.uri = info.get("uri") self.identifier = info.get("identifier") + self.isrc = info.get("isrc") if info.get("thumbnail"): self.thumbnail = info.get("thumbnail") diff --git a/pomice/player.py b/pomice/player.py index d50fd98..7e8ad77 100644 --- a/pomice/player.py +++ b/pomice/player.py @@ -16,7 +16,7 @@ from discord.ext import commands from . import events from .enums import SearchType from .events import PomiceEvent, TrackEndEvent, TrackStartEvent -from .exceptions import FilterInvalidArgument, TrackInvalidPosition +from .exceptions import FilterInvalidArgument, TrackInvalidPosition, TrackLoadError from .filters import Filter from .objects import Track from .pool import Node, NodePool @@ -245,11 +245,13 @@ class Player(VoiceProtocol): ignore_if_playing: bool = False ) -> Track: """Plays a track. If a Spotify track is passed in, it will be handled accordingly.""" - if track.spotify: + if track.spotify: search: Track = (await self._node.get_tracks( - f"{track._search_type}:{track.author} - {track.title}", - ctx=track.ctx - ))[0] + f"{track._search_type}:{track.title} - {track.author}", ctx=track.ctx))[0] + if not search: + raise TrackLoadError ( + "No equivalent track was able to be found." + ) track.original = search data = { @@ -298,16 +300,18 @@ class Player(VoiceProtocol): self._volume = volume return self._volume - async def set_filter(self, filter: Filter) -> Filter: + async def set_filter(self, filter: Filter, fast_apply=False) -> Filter: """Sets a filter of the player. Takes a pomice.Filter object. This will only work if you are using a version of Lavalink that supports filters. + If you would like for the filter to apply instantly, set the `fast_apply` arg to `True`. """ await self._node.send(op="filters", guildId=str(self.guild.id), **filter.payload) - await self.seek(self.position) + if fast_apply: + await self.seek(self.position) self._filter = filter return filter - async def reset_filter(self): + async def reset_filter(self, fast_apply=False): """Resets a currently applied filter to its default parameters. You must have a filter applied in order for this to work """ @@ -317,9 +321,9 @@ class Player(VoiceProtocol): "You must have a filter applied first in order to use this method." ) - _payload: dict = self._filter._reset() - await self._node.send(op="filters", guildId=str(self.guild.id), **_payload) - await self.seek(self.position) + await self._node.send(op="filters", guildId=str(self.guild.id)) + if fast_apply: + await self.seek(self.position) self._filter = None diff --git a/pomice/pool.py b/pomice/pool.py index 9f171c1..48ed006 100644 --- a/pomice/pool.py +++ b/pomice/pool.py @@ -65,7 +65,6 @@ class Node: identifier: str, secure: bool = False, heartbeat: int = 30, - region: Optional[str] = None, session: Optional[aiohttp.ClientSession] = None, spotify_client_id: Optional[str] = None, spotify_client_secret: Optional[str] = None, @@ -79,7 +78,6 @@ class Node: self._identifier = identifier self._heartbeat = heartbeat self._secure = secure - self._region: Optional[str] = region self._websocket_uri = f"{'wss' if self._secure else 'ws'}://{self._host}:{self._port}" @@ -133,11 +131,6 @@ class Node: """Property which returns a dict containing the guild ID and the player object.""" return self._players - @property - def region(self) -> Optional[str]: - """Property which returns the VoiceRegion of the node, if one is set""" - return self._region - @property def bot(self) -> Client: """Property which returns the discord.py client linked to this node""" @@ -336,7 +329,8 @@ class Node: "isStream": False, "isSeekable": True, "position": 0, - "thumbnail": spotify_results.image + "thumbnail": spotify_results.image, + "isrc": spotify_results.isrc } ) ] @@ -357,7 +351,8 @@ class Node: "isStream": False, "isSeekable": True, "position": 0, - "thumbnail": track.image + "thumbnail": track.image, + "isrc": track.isrc } ) for track in spotify_results.tracks ] @@ -455,7 +450,7 @@ class NodePool: return len(self._nodes.values()) @classmethod - def get_best_node(cls, *, algorithm: NodeAlgorithm, voice_region: str = None) -> Node: + def get_best_node(cls, *, algorithm: NodeAlgorithm) -> Node: """Fetches the best node based on an NodeAlgorithm. This option is preferred if you want to choose the best node from a multi-node setup using either the node's latency @@ -484,18 +479,6 @@ class NodePool: elif algorithm == NodeAlgorithm.by_players: tested_nodes = {node: len(node.players.keys()) for node in available_nodes} return min(tested_nodes, key=tested_nodes.get) - - else: - if voice_region == None: - raise NodeException("You must specify a VoiceRegion in order to use this functionality.") - - nodes = [node for node in available_nodes if node._region == voice_region] - if not nodes: - raise NoNodesAvailable( - f"No nodes for region {voice_region} exist in this pool." - ) - - return nodes[0] @classmethod def get_node(cls, *, identifier: str = None) -> Node: @@ -526,7 +509,6 @@ class NodePool: identifier: str, secure: bool = False, heartbeat: int = 30, - region: Optional[str] = None, spotify_client_id: Optional[str] = None, spotify_client_secret: Optional[str] = None, session: Optional[aiohttp.ClientSession] = None, @@ -541,7 +523,7 @@ class NodePool: node = Node( pool=cls, bot=bot, host=host, port=port, password=password, identifier=identifier, secure=secure, heartbeat=heartbeat, - region=region, spotify_client_id=spotify_client_id, + spotify_client_id=spotify_client_id, session=session, spotify_client_secret=spotify_client_secret ) diff --git a/pomice/spotify/track.py b/pomice/spotify/track.py index c3edc58..9539252 100644 --- a/pomice/spotify/track.py +++ b/pomice/spotify/track.py @@ -6,6 +6,7 @@ class Track: self.artists = ", ".join(artist["name"] for artist in data["artists"]) self.length = data["duration_ms"] self.id = data["id"] + self.isrc = data["external_ids"]["isrc"] if data.get("album") and data["album"].get("images"): self.image = data["album"]["images"][0]["url"] @@ -20,5 +21,5 @@ class Track: def __repr__(self) -> str: return ( f"" + f"length={self.length} id={self.id} isrc={self.isrc}>" ) diff --git a/setup.py b/setup.py index 79b87a3..11aa35f 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md") as f: setuptools.setup( name="pomice", author="cloudwithax", - version="1.1.6.1", + version="1.1.7", url="https://github.com/cloudwithax/pomice", packages=setuptools.find_packages(), license="GPL",