diff --git a/pomice/objects.py b/pomice/objects.py index 6acdbd2..700d903 100644 --- a/pomice/objects.py +++ b/pomice/objects.py @@ -16,7 +16,7 @@ class Track: info: dict, ctx: Optional[commands.Context], search_type: SearchType = None, - spotify: bool = False + spotify: bool = False, ): self.track_id = track_id self.info = info diff --git a/pomice/pool.py b/pomice/pool.py index 4bf989b..8060f5e 100644 --- a/pomice/pool.py +++ b/pomice/pool.py @@ -34,6 +34,10 @@ SPOTIFY_URL_REGEX = re.compile( r"https?://open.spotify.com/(?Palbum|playlist|track)/(?P[a-zA-Z0-9]+)" ) +DISCORD_MP3_URL_REGEX = re.compile( + r"https?://cdn.discordapp.com/attachments/(?P[0-9]+)/(?P[0-9]+)/(?P[a-zA-Z0-9_.]+)+" +) + class Node: """The base class for a node. @@ -374,6 +378,29 @@ class Node: except SpotifyException: raise SpotifyTrackLoadFailed(f"Unable to find results for {query}") + elif discord_url := DISCORD_MP3_URL_REGEX.match(query): + async with self._session.get( + url=f"{self._rest_uri}/loadtracks?identifier={quote(query)}", + headers={"Authorization": self._password} + ) as response: + data: dict = await response.json() + + + track: dict = data["tracks"][0] + info: dict = track.get('info') + + return [Track( + track_id=track['track'], + info={ + "title": discord_url.group('file'), + "author": "Unknown", + "length": info.get('length'), + "uri": info.get('uri'), + "position": info.get('position'), + "identifier": info.get('identifier') + }, + ctx=ctx)] + else: async with self._session.get( url=f"{self._rest_uri}/loadtracks?identifier={quote(query)}", diff --git a/setup.py b/setup.py index aa689c9..070079e 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.0.5.2", + version="1.0.5.3", url="https://github.com/cloudwithax/pomice", packages=setuptools.find_packages(), license="GPL",