From 481e61641491822a14272569fb9fd7ec6ab4702f Mon Sep 17 00:00:00 2001 From: cloudwithax Date: Sat, 11 Mar 2023 00:22:38 -0500 Subject: [PATCH] switch formatting to black --- pomice/__init__.py | 2 +- pomice/applemusic/__init__.py | 2 +- pomice/applemusic/client.py | 13 +- pomice/applemusic/exceptions.py | 2 + pomice/applemusic/objects.py | 29 ++-- pomice/enums.py | 34 ++-- pomice/events.py | 92 +++++------ pomice/exceptions.py | 21 +++ pomice/filters.py | 283 +++++++++++++++++--------------- pomice/objects.py | 13 +- pomice/player.py | 193 ++++++++++------------ pomice/pool.py | 267 ++++++++++++++++-------------- pomice/queue.py | 38 ++--- pomice/routeplanner.py | 2 + pomice/spotify/client.py | 16 +- pomice/spotify/exceptions.py | 2 + pomice/spotify/objects.py | 14 +- pomice/utils.py | 33 +--- pyproject.toml | 7 +- setup.py | 42 ++--- 20 files changed, 537 insertions(+), 568 deletions(-) diff --git a/pomice/__init__.py b/pomice/__init__.py index 0d7a0f1..6671545 100644 --- a/pomice/__init__.py +++ b/pomice/__init__.py @@ -10,6 +10,7 @@ Licensed under GPL-3.0 import discord if not discord.version_info.major >= 2: + class DiscordPyOutdated(Exception): pass @@ -34,4 +35,3 @@ from .queue import * from .player import * from .pool import * from .routeplanner import * - diff --git a/pomice/applemusic/__init__.py b/pomice/applemusic/__init__.py index 1c9005c..abd0722 100644 --- a/pomice/applemusic/__init__.py +++ b/pomice/applemusic/__init__.py @@ -2,4 +2,4 @@ from .exceptions import * from .objects import * -from .client import Client \ No newline at end of file +from .client import Client diff --git a/pomice/applemusic/client.py b/pomice/applemusic/client.py index 9023326..8d11735 100644 --- a/pomice/applemusic/client.py +++ b/pomice/applemusic/client.py @@ -35,9 +35,7 @@ class Client: if not self.session: self.session = aiohttp.ClientSession() - async with self.session.get( - "https://music.apple.com/assets/index.919fe17f.js" - ) as resp: + async with self.session.get("https://music.apple.com/assets/index.919fe17f.js") as resp: if resp.status != 200: raise AppleMusicRequestException( f"Error while fetching results: {resp.status} {resp.reason}" @@ -50,9 +48,7 @@ class Client: "Origin": "https://apple.com", } token_split = self.token.split(".")[1] - token_json = base64.b64decode( - token_split + "=" * (-len(token_split) % 4) - ).decode() + token_json = base64.b64decode(token_split + "=" * (-len(token_split) % 4)).decode() token_data = json.loads(token_json) self.expiry = datetime.fromtimestamp(token_data["exp"]) @@ -105,7 +101,6 @@ class Client: return Artist(data, tracks=tracks) else: - track_data: dict = data["relationships"]["tracks"] tracks = [Song(track) for track in track_data.get("data")] @@ -119,9 +114,7 @@ class Client: next_page_url = AM_BASE_URL + track_data.get("next") while next_page_url is not None: - async with self.session.get( - next_page_url, headers=self.headers - ) as resp: + async with self.session.get(next_page_url, headers=self.headers) as resp: if resp.status != 200: raise AppleMusicRequestException( f"Error while fetching results: {resp.status} {resp.reason}" diff --git a/pomice/applemusic/exceptions.py b/pomice/applemusic/exceptions.py index f9c1f7d..6d60fa3 100644 --- a/pomice/applemusic/exceptions.py +++ b/pomice/applemusic/exceptions.py @@ -1,8 +1,10 @@ class AppleMusicRequestException(Exception): """An error occurred when making a request to the Apple Music API""" + pass class InvalidAppleMusicURL(Exception): """An invalid Apple Music URL was passed""" + pass diff --git a/pomice/applemusic/objects.py b/pomice/applemusic/objects.py index c7cd7c1..67e5643 100644 --- a/pomice/applemusic/objects.py +++ b/pomice/applemusic/objects.py @@ -5,8 +5,8 @@ from typing import List class Song: """The base class for an Apple Music song""" + def __init__(self, data: dict) -> None: - self.name: str = data["attributes"]["name"] self.url: str = data["attributes"]["url"] self.isrc: str = data["attributes"]["isrc"] @@ -14,8 +14,8 @@ class Song: self.id: str = data["id"] self.artists: str = data["attributes"]["artistName"] self.image: str = data["attributes"]["artwork"]["url"].replace( - "{w}x{h}", - f'{data["attributes"]["artwork"]["width"]}x{data["attributes"]["artwork"]["height"]}' + "{w}x{h}", + f'{data["attributes"]["artwork"]["width"]}x{data["attributes"]["artwork"]["height"]}', ) def __repr__(self) -> str: @@ -23,10 +23,11 @@ class Song: f"" ) - + class Playlist: """The base class for an Apple Music playlist""" + def __init__(self, data: dict, tracks: List[Song]) -> None: self.name: str = data["attributes"]["name"] self.owner: str = data["attributes"]["curatorName"] @@ -36,7 +37,7 @@ class Playlist: self.url: str = data["attributes"]["url"] # we'll use the first song's image as the image for the playlist # because apple dynamically generates playlist covers client-side - self.image = self.tracks[0].image + self.image = self.tracks[0].image def __repr__(self) -> str: return ( @@ -44,9 +45,10 @@ class Playlist: f"total_tracks={self.total_tracks} tracks={self.tracks}>" ) - + class Album: """The base class for an Apple Music album""" + def __init__(self, data: dict) -> None: self.name: str = data["attributes"]["name"] self.url: str = data["attributes"]["url"] @@ -55,8 +57,8 @@ class Album: self.total_tracks: int = data["attributes"]["trackCount"] self.tracks: List[Song] = [Song(track) for track in data["relationships"]["tracks"]["data"]] self.image: str = data["attributes"]["artwork"]["url"].replace( - "{w}x{h}", - f'{data["attributes"]["artwork"]["width"]}x{data["attributes"]["artwork"]["height"]}' + "{w}x{h}", + f'{data["attributes"]["artwork"]["width"]}x{data["attributes"]["artwork"]["height"]}', ) def __repr__(self) -> str: @@ -64,11 +66,11 @@ class Album: f"" ) - class Artist: """The base class for an Apple Music artist""" + def __init__(self, data: dict, tracks: dict) -> None: self.name: str = f'Top tracks for {data["attributes"]["name"]}' self.url: str = data["attributes"]["url"] @@ -76,12 +78,9 @@ class Artist: self.genres: str = ", ".join(genre for genre in data["attributes"]["genreNames"]) self.tracks: List[Song] = [Song(track) for track in tracks] self.image: str = data["attributes"]["artwork"]["url"].replace( - "{w}x{h}", - f'{data["attributes"]["artwork"]["width"]}x{data["attributes"]["artwork"]["height"]}' + "{w}x{h}", + f'{data["attributes"]["artwork"]["width"]}x{data["attributes"]["artwork"]["height"]}', ) def __repr__(self) -> str: - return ( - f"" - ) \ No newline at end of file + return f"" diff --git a/pomice/enums.py b/pomice/enums.py index 2f1c97a..93e0eea 100644 --- a/pomice/enums.py +++ b/pomice/enums.py @@ -18,6 +18,7 @@ class SearchType(Enum): SearchType.scsearch searches using SoundCloud, which is an alternative to YouTube or YouTube Music. """ + ytsearch = "ytsearch" ytmsearch = "ytmsearch" scsearch = "scsearch" @@ -51,6 +52,7 @@ class TrackType(Enum): def __str__(self) -> str: return self.value + class PlaylistType(Enum): """ The enum for the different playlist types for Pomice. @@ -74,7 +76,6 @@ class PlaylistType(Enum): return self.value - class NodeAlgorithm(Enum): """ The enum for the different node algorithms in Pomice. @@ -98,6 +99,7 @@ class NodeAlgorithm(Enum): def __str__(self) -> str: return self.value + class LoopMode(Enum): """ The enum for the different loop modes. @@ -109,11 +111,11 @@ class LoopMode(Enum): LoopMode.QUEUE sets the queue loop to the whole queue. """ + # We don't have to define anything special for these, since these just serve as flags TRACK = "track" QUEUE = "queue" - def __str__(self) -> str: return self.value @@ -160,7 +162,7 @@ class RouteIPType(Enum): IPV6 = "Inet6Address" -class URLRegex(): +class URLRegex: """ The enums for all the URL Regexes in use by Pomice. @@ -181,6 +183,7 @@ class URLRegex(): URLRegex.BASE_URL returns the standard URL Regex. """ + SPOTIFY_URL = re.compile( r"https?://open.spotify.com/(?Palbum|playlist|track|artist)/(?P[a-zA-Z0-9]+)" ) @@ -199,13 +202,9 @@ class URLRegex(): r"^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))/playlist\?list=.*" ) - YOUTUBE_VID_IN_PLAYLIST = re.compile( - r"(?P