Skip to content

Commit

Permalink
Add support for AppleMusic embed specials
Browse files Browse the repository at this point in the history
  • Loading branch information
MCausc78 committed Aug 2, 2024
1 parent 1416367 commit bb709dc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyvolt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .enums import *
from .errors import *
from .events import *
from .flags import *
from .http import *
from .invite import *
from .message import *
Expand Down
15 changes: 14 additions & 1 deletion pyvolt/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class _BaseEmbed(abc.ABC):
def _stateful(self, state: State) -> Embed: ...


class EmbedSpecial(abc.ABC):
@define(slots=True)
class EmbedSpecial:
"""Information about special remote content."""


Expand Down Expand Up @@ -123,6 +124,17 @@ class BandcampEmbedSpecial(EmbedSpecial):
"""The Bandcamp content ID."""


@define(slots=True)
class AppleMusicEmbedSpecial(EmbedSpecial):
"""Represents information about Apple Music track."""

album_id: str = field(repr=True, kw_only=True, eq=True)
"""The Apple Music album ID."""

track_id: str | None = field(repr=True, kw_only=True, eq=True)
"""The Apple Music track ID."""


@define(slots=True)
class StreamableEmbedSpecial(EmbedSpecial):
"""Represents information about Streamable video."""
Expand Down Expand Up @@ -278,6 +290,7 @@ def _stateful(self, state: State) -> Embed:
'SoundcloudEmbedSpecial',
'_SOUNDCLOUD_EMBED_SPECIAL',
'BandcampEmbedSpecial',
'AppleMusicEmbedSpecial',
'StreamableEmbedSpecial',
'ImageEmbed',
'VideoEmbed',
Expand Down
10 changes: 9 additions & 1 deletion pyvolt/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
SoundcloudEmbedSpecial,
_SOUNDCLOUD_EMBED_SPECIAL,
BandcampEmbedSpecial,
AppleMusicEmbedSpecial,
StreamableEmbedSpecial,
ImageSize,
ImageEmbed,
Expand Down Expand Up @@ -249,6 +250,7 @@ def __init__(self, state: State) -> None:
'Spotify': self.parse_spotify_embed_special,
'Soundcloud': self.parse_soundcloud_embed_special,
'Bandcamp': self.parse_bandcamp_embed_special,
'AppleMusic': self.parse_apple_music_embed_special,
'Streamable': self.parse_streamable_embed_special,
}
self._emoji_parsers = {
Expand Down Expand Up @@ -281,7 +283,13 @@ def __init__(self, state: State) -> None:

# basic start

def parse_asset_metadata(self, d: raw.Metadata) -> AssetMetadata:
def parse_apple_music_embed_special(self, d: raw.AppleMusicSpecial, /) -> AppleMusicEmbedSpecial:
return AppleMusicEmbedSpecial(
album_id=d['album_id'],
track_id=d.get('track_id'),
)

def parse_asset_metadata(self, d: raw.Metadata, /) -> AssetMetadata:
return AssetMetadata(
type=AssetMetadataType(d['type']),
width=d.get('width'),
Expand Down
8 changes: 8 additions & 0 deletions pyvolt/raw/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class BandcampSpecial(typing.TypedDict):
id: str


class AppleMusicSpecial(typing.TypedDict):
type: typing.Literal['AppleMusic']
album_id: str
track_id: typing.NotRequired[str]


class StreamableSpecial(typing.TypedDict):
type: typing.Literal['Streamable']
id: str
Expand All @@ -80,6 +86,7 @@ class StreamableSpecial(typing.TypedDict):
| TwitchSpecial
| SpotifySpecial
| BandcampSpecial
| AppleMusicSpecial
| StreamableSpecial
)

Expand Down Expand Up @@ -143,6 +150,7 @@ class NoneEmbed(typing.TypedDict):
'SpotifySpecial',
'SoundcloudSpecial',
'BandcampSpecial',
'AppleMusicSpecial',
'StreamableSpecial',
'Special',
'WebsiteMetadata',
Expand Down

0 comments on commit bb709dc

Please sign in to comment.