add playlist video correction and timestamp retrivial for qualifying videos
This commit is contained in:
parent
9fde02c2e0
commit
23fd49be1a
|
|
@ -25,12 +25,14 @@ class Track:
|
||||||
spotify: bool = False,
|
spotify: bool = False,
|
||||||
search_type: SearchType = SearchType.ytsearch,
|
search_type: SearchType = SearchType.ytsearch,
|
||||||
spotify_track = None,
|
spotify_track = None,
|
||||||
filters: Optional[List[Filter]] = None
|
filters: Optional[List[Filter]] = None,
|
||||||
|
timestamp: Optional[float] = None
|
||||||
):
|
):
|
||||||
self.track_id = track_id
|
self.track_id = track_id
|
||||||
self.info = info
|
self.info = info
|
||||||
self.spotify = spotify
|
self.spotify = spotify
|
||||||
self.filters: List[Filter] = filters
|
self.filters: List[Filter] = filters
|
||||||
|
self.timestamp: Optional[float] = None
|
||||||
|
|
||||||
self.original: Optional[Track] = None if spotify else self
|
self.original: Optional[Track] = None if spotify else self
|
||||||
self._search_type = search_type
|
self._search_type = search_type
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ from .exceptions import FilterInvalidArgument, FilterTagAlreadyInUse, FilterTagI
|
||||||
from .filters import Filter
|
from .filters import Filter
|
||||||
from .objects import Track
|
from .objects import Track
|
||||||
from .pool import Node, NodePool
|
from .pool import Node, NodePool
|
||||||
from .queue import Queue
|
|
||||||
|
|
||||||
class Filters:
|
class Filters:
|
||||||
"""Helper class for filters"""
|
"""Helper class for filters"""
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,14 @@ DISCORD_MP3_URL_REGEX = re.compile(
|
||||||
r"(?P<message_id>[0-9]+)/(?P<file>[a-zA-Z0-9_.]+)+"
|
r"(?P<message_id>[0-9]+)/(?P<file>[a-zA-Z0-9_.]+)+"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
YOUTUBE_PLAYLIST_REGEX = re.compile(
|
||||||
|
r"(?P<video>^.*?v.*?)(?P<list>&list.*)"
|
||||||
|
)
|
||||||
|
|
||||||
|
YOUTUBE_TIMESTAMP_REGEX = re.compile(
|
||||||
|
r"(?P<video>^.*?)(\?t|&start)=(?P<time>\d+)?.*"
|
||||||
|
)
|
||||||
|
|
||||||
URL_REGEX = re.compile(
|
URL_REGEX = re.compile(
|
||||||
r"https?://(?:www\.)?.+"
|
r"https?://(?:www\.)?.+"
|
||||||
)
|
)
|
||||||
|
|
@ -153,6 +161,11 @@ class Node:
|
||||||
"""Property which returns the latency of the node"""
|
"""Property which returns the latency of the node"""
|
||||||
return Ping(self._host, port=self._port).get_ping()
|
return Ping(self._host, port=self._port).get_ping()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ping(self):
|
||||||
|
"""Alias for `Node.latency`, returns the latency of the node"""
|
||||||
|
return self.latency
|
||||||
|
|
||||||
async def _update_handler(self, data: dict):
|
async def _update_handler(self, data: dict):
|
||||||
await self._bot.wait_until_ready()
|
await self._bot.wait_until_ready()
|
||||||
|
|
||||||
|
|
@ -302,6 +315,8 @@ class Node:
|
||||||
to be applied to your track once it plays.
|
to be applied to your track once it plays.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
timestamp = None
|
||||||
|
|
||||||
if not URL_REGEX.match(query) and not re.match(r"(?:ytm?|sc)search:.", query):
|
if not URL_REGEX.match(query) and not re.match(r"(?:ytm?|sc)search:.", query):
|
||||||
query = f"{search_type}:{query}"
|
query = f"{search_type}:{query}"
|
||||||
|
|
||||||
|
|
@ -400,6 +415,18 @@ class Node:
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# If YouTube url contains a timestamp, capture it for use later.
|
||||||
|
|
||||||
|
if (match := YOUTUBE_TIMESTAMP_REGEX.match(query)):
|
||||||
|
timestamp = float(match.group("time"))
|
||||||
|
|
||||||
|
# If query is a video thats part of a playlist, get the video and queue that instead
|
||||||
|
# (I can't tell you how much i've wanted to implement this in here)
|
||||||
|
|
||||||
|
if (match := YOUTUBE_PLAYLIST_REGEX.match(query)):
|
||||||
|
query = match.group("video")
|
||||||
|
|
||||||
|
|
||||||
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)}",
|
||||||
|
|
@ -433,20 +460,19 @@ class Node:
|
||||||
track_id=track["track"],
|
track_id=track["track"],
|
||||||
info=track["info"],
|
info=track["info"],
|
||||||
ctx=ctx,
|
ctx=ctx,
|
||||||
filters=filters
|
filters=filters,
|
||||||
|
timestamp=timestamp
|
||||||
)
|
)
|
||||||
for track in data["tracks"]
|
for track in data["tracks"]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NodePool:
|
class NodePool:
|
||||||
"""The base class for the node pool.
|
"""The base class for the node pool.
|
||||||
This holds all the nodes that are to be used by the bot.
|
This holds all the nodes that are to be used by the bot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_nodes = {}
|
_nodes: dict = {}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Pomice.NodePool node_count={self.node_count}>"
|
return f"<Pomice.NodePool node_count={self.node_count}>"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue