chore(style): change imports, remove url regex duplication
This commit is contained in:
parent
84765e0ed5
commit
e48ed8fd4b
|
|
@ -11,17 +11,12 @@ from typing import Union
|
|||
import aiohttp
|
||||
import orjson as json
|
||||
|
||||
from .exceptions import *
|
||||
from .objects import *
|
||||
from pomice.applemusic.exceptions import *
|
||||
from pomice.applemusic.objects import *
|
||||
from pomice.enums import URLRegex
|
||||
|
||||
__all__ = ("Client",)
|
||||
|
||||
AM_URL_REGEX = re.compile(
|
||||
r"https?://music.apple.com/(?P<country>[a-zA-Z]{2})/(?P<type>album|playlist|song|artist)/(?P<name>.+)/(?P<id>[^?]+)",
|
||||
)
|
||||
AM_SINGLE_IN_ALBUM_REGEX = re.compile(
|
||||
r"https?://music.apple.com/(?P<country>[a-zA-Z]{2})/(?P<type>album|playlist|song|artist)/(?P<name>.+)/(?P<id>.+)(\?i=)(?P<id2>.+)",
|
||||
)
|
||||
|
||||
AM_SCRIPT_REGEX = re.compile(r'<script.*?src="(/assets/index-.*?)"')
|
||||
|
||||
|
|
@ -103,7 +98,7 @@ class Client:
|
|||
if not self.token or datetime.utcnow() > self.expiry:
|
||||
await self.request_token()
|
||||
|
||||
result = AM_URL_REGEX.match(query)
|
||||
result = URLRegex.AM_URL.match(query)
|
||||
if not result:
|
||||
raise InvalidAppleMusicURL(
|
||||
"The Apple Music link provided is not valid.",
|
||||
|
|
@ -113,7 +108,7 @@ class Client:
|
|||
type = result.group("type")
|
||||
id = result.group("id")
|
||||
|
||||
if type == "album" and (sia_result := AM_SINGLE_IN_ALBUM_REGEX.match(query)):
|
||||
if type == "album" and (sia_result := URLRegex.AM_SINGLE_IN_ALBUM_REGEX.match(query)):
|
||||
# apple music likes to generate links for singles off an album
|
||||
# by adding a param at the end of the url
|
||||
# so we're gonna scan for that and correct it
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from typing import List
|
|||
from typing import Optional
|
||||
from typing import Tuple
|
||||
|
||||
from .exceptions import FilterInvalidArgument
|
||||
from pomice.exceptions import FilterInvalidArgument
|
||||
|
||||
__all__ = (
|
||||
"Filter",
|
||||
|
|
|
|||
|
|
@ -23,31 +23,31 @@ from discord.ext import commands
|
|||
from websockets import client
|
||||
from websockets import exceptions
|
||||
|
||||
from . import __version__
|
||||
from . import applemusic
|
||||
from . import spotify
|
||||
from .enums import *
|
||||
from .exceptions import InvalidSpotifyClientAuthorization
|
||||
from .exceptions import LavalinkVersionIncompatible
|
||||
from .exceptions import NodeConnectionFailure
|
||||
from .exceptions import NodeCreationError
|
||||
from .exceptions import NodeNotAvailable
|
||||
from .exceptions import NodeRestException
|
||||
from .exceptions import NoNodesAvailable
|
||||
from .exceptions import TrackLoadError
|
||||
from .filters import Filter
|
||||
from .objects import Playlist
|
||||
from .objects import Track
|
||||
from .routeplanner import RoutePlanner
|
||||
from .utils import ExponentialBackoff
|
||||
from .utils import NodeStats
|
||||
from .utils import Ping
|
||||
from pomice import __version__
|
||||
from pomice import applemusic
|
||||
from pomice import spotify
|
||||
from pomice.enums import *
|
||||
from pomice.exceptions import InvalidSpotifyClientAuthorization
|
||||
from pomice.exceptions import LavalinkVersionIncompatible
|
||||
from pomice.exceptions import NodeConnectionFailure
|
||||
from pomice.exceptions import NodeCreationError
|
||||
from pomice.exceptions import NodeNotAvailable
|
||||
from pomice.exceptions import NodeRestException
|
||||
from pomice.exceptions import NoNodesAvailable
|
||||
from pomice.exceptions import TrackLoadError
|
||||
from pomice.filters import Filter
|
||||
from pomice.models.music import Playlist
|
||||
from pomice.models.music import Track
|
||||
from pomice.models.payloads import ResumePayloadTypeAdapter
|
||||
from pomice.models.payloads import ResumePayloadV4
|
||||
from pomice.models.version import LavalinkVersion
|
||||
from pomice.routeplanner import RoutePlanner
|
||||
from pomice.utils import ExponentialBackoff
|
||||
from pomice.utils import NodeStats
|
||||
from pomice.utils import Ping
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .player import Player
|
||||
from pomice.player import Player
|
||||
|
||||
__all__ = (
|
||||
"Node",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .pool import Node
|
||||
from pomice.pool import Node
|
||||
|
||||
from pomice.utils import RouteStats
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import re
|
||||
import time
|
||||
from base64 import b64encode
|
||||
from typing import Dict
|
||||
|
|
@ -13,18 +12,15 @@ from urllib.parse import quote
|
|||
import aiohttp
|
||||
import orjson as json
|
||||
|
||||
from .exceptions import InvalidSpotifyURL
|
||||
from .exceptions import SpotifyRequestException
|
||||
from .objects import *
|
||||
from pomice.enums import URLRegex
|
||||
from pomice.spotify.exceptions import *
|
||||
from pomice.spotify.models import *
|
||||
|
||||
__all__ = ("Client",)
|
||||
|
||||
|
||||
GRANT_URL = "https://accounts.spotify.com/api/token"
|
||||
REQUEST_URL = "https://api.spotify.com/v1/{type}s/{id}"
|
||||
SPOTIFY_URL_REGEX = re.compile(
|
||||
r"https?://open.spotify.com/(?P<type>album|playlist|track|artist)/(?P<id>[a-zA-Z0-9]+)",
|
||||
)
|
||||
|
||||
|
||||
class Client:
|
||||
|
|
@ -74,7 +70,7 @@ class Client:
|
|||
if not self._bearer_token or time.time() >= self._expiry:
|
||||
await self._fetch_bearer_token()
|
||||
|
||||
result = SPOTIFY_URL_REGEX.match(query)
|
||||
result = URLRegex.SPOTIFY_URL.match(query)
|
||||
if not result:
|
||||
raise InvalidSpotifyURL("The Spotify link provided is not valid.")
|
||||
|
||||
|
|
@ -148,7 +144,7 @@ class Client:
|
|||
if not self._bearer_token or time.time() >= self._expiry:
|
||||
await self._fetch_bearer_token()
|
||||
|
||||
result = SPOTIFY_URL_REGEX.match(query)
|
||||
result = URLRegex.SPOTIFY_URL.match(query)
|
||||
if not result:
|
||||
raise InvalidSpotifyURL("The Spotify link provided is not valid.")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue