Added Discord audio attachment URL regex to better parse audio tracks. Take that, Groovy...
This commit is contained in:
parent
e138091fcf
commit
f6a3752298
|
|
@ -16,7 +16,7 @@ class Track:
|
||||||
info: dict,
|
info: dict,
|
||||||
ctx: Optional[commands.Context],
|
ctx: Optional[commands.Context],
|
||||||
search_type: SearchType = None,
|
search_type: SearchType = None,
|
||||||
spotify: bool = False
|
spotify: bool = False,
|
||||||
):
|
):
|
||||||
self.track_id = track_id
|
self.track_id = track_id
|
||||||
self.info = info
|
self.info = info
|
||||||
|
|
|
||||||
|
|
@ -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]+)"
|
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:
|
class Node:
|
||||||
"""The base class for a node.
|
"""The base class for a node.
|
||||||
|
|
@ -374,6 +378,29 @@ class Node:
|
||||||
except SpotifyException:
|
except SpotifyException:
|
||||||
raise SpotifyTrackLoadFailed(f"Unable to find results for {query}")
|
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:
|
else:
|
||||||
async with self._session.get(
|
async with self._session.get(
|
||||||
url=f"{self._rest_uri}/loadtracks?identifier={quote(query)}",
|
url=f"{self._rest_uri}/loadtracks?identifier={quote(query)}",
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -6,7 +6,7 @@ with open("README.md") as f:
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="pomice",
|
name="pomice",
|
||||||
author="cloudwithax",
|
author="cloudwithax",
|
||||||
version="1.0.5.2",
|
version="1.0.5.3",
|
||||||
url="https://github.com/cloudwithax/pomice",
|
url="https://github.com/cloudwithax/pomice",
|
||||||
packages=setuptools.find_packages(),
|
packages=setuptools.find_packages(),
|
||||||
license="GPL",
|
license="GPL",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue