Added Discord audio attachment URL regex to better parse audio tracks. Take that, Groovy...

This commit is contained in:
cloudwithax 2021-10-08 21:11:58 -04:00
parent e138091fcf
commit f6a3752298
3 changed files with 29 additions and 2 deletions

View File

@ -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

View File

@ -34,6 +34,10 @@ SPOTIFY_URL_REGEX = re.compile(
r"https?://open.spotify.com/(?P<type>album|playlist|track)/(?P<id>[a-zA-Z0-9]+)"
)
DISCORD_MP3_URL_REGEX = re.compile(
r"https?://cdn.discordapp.com/attachments/(?P<channel_id>[0-9]+)/(?P<message_id>[0-9]+)/(?P<file>[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)}",

View File

@ -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",