Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_timestamp_formatted_back_to_string(self):
time_str = '2019-01-01T12:00:00Z'
t = Timestamp.from_string(time_str)
assert str(t) == time_str
def __post_init__(self):
self.added_at = Timestamp.from_string(self.added_at)
self.album = FullAlbum(**self.album)
def __post_init__(self):
self.track = FullTrack(**self.track)
self.played_at = Timestamp.from_string(self.played_at)
if self.context is not None:
self.context = Context(**self.context)
def __post_init__(self):
self.added_at = Timestamp.from_string(self.added_at)
self.added_by = PublicUser(**self.added_by)
if self.video_thumbnail is not None:
self.video_thumbnail = Image(**self.video_thumbnail)
if self.track is not None:
if self.is_local:
self.track = LocalPlaylistTrack(**self.track)
else:
self.track = track_type[self.track['type']](**self.track)
self.items = ModelList(SimpleTrack(**t) for t in self.items)
@dataclass(repr=False)
class Tracks(Model):
"""Minimal representation of playlist tracks."""
href: str
total: int
@dataclass(repr=False)
class SavedTrack(Model):
"""Track saved to library."""
added_at: Timestamp
track: FullTrack
def __post_init__(self):
self.added_at = Timestamp.from_string(self.added_at)
self.track = FullTrack(**self.track)
@dataclass(repr=False)
class SavedTrackPaging(OffsetPaging):
"""Paging of tracks in library."""
items: List[SavedTrack]
def __post_init__(self):
self.items = ModelList(SavedTrack(**t) for t in self.items)
def default(self, o):
"""Convert into serialisable data types."""
if isinstance(o, (Enum, Timestamp)):
return str(o)
elif isinstance(o, Model):
return asdict(o)
else:
return super().default(o)
is_playable: True = None
def __post_init__(self):
super().__post_init__()
if self.available_markets is not None:
self.available_markets = ModelList(self.available_markets)
self.copyrights = ModelList(Copyright(**c) for c in self.copyrights)
self.genres = ModelList(self.genres)
self.tracks = SimpleTrackPaging(**self.tracks)
@dataclass(repr=False)
class SavedAlbum(Model):
"""Album saved to library."""
added_at: Timestamp
album: FullAlbum
def __post_init__(self):
self.added_at = Timestamp.from_string(self.added_at)
self.album = FullAlbum(**self.album)
@dataclass(repr=False)
class SavedAlbumPaging(OffsetPaging):
"""Paging of albums in library."""
items: List[SavedAlbum]
def __post_init__(self):
self.items = ModelList(SavedAlbum(**a) for a in self.items)
episode: bool = False
track: bool = True
track_type = {
'track': FullPlaylistTrack,
'episode': FullPlaylistEpisode,
}
@dataclass(repr=False)
class PlaylistTrack(Model):
"""Track or episode on a playlist."""
added_at: Timestamp
added_by: PublicUser
is_local: bool
primary_color: str
video_thumbnail: Optional[Image]
track: Union[FullPlaylistTrack, LocalPlaylistTrack, FullPlaylistEpisode, None]
def __post_init__(self):
self.added_at = Timestamp.from_string(self.added_at)
self.added_by = PublicUser(**self.added_by)
if self.video_thumbnail is not None:
self.video_thumbnail = Image(**self.video_thumbnail)
if self.track is not None:
if self.is_local:
self.track = LocalPlaylistTrack(**self.track)
from .track import FullTrack
from .paging import CursorPaging, Cursor
from .context import Context
from .serialise import Model, ModelList, Timestamp
@dataclass(repr=False)
class PlayHistory(Model):
"""
Previously played track.
Context is supposedly sometimes available.
"""
track: FullTrack
played_at: Timestamp
context: Optional[Context]
def __post_init__(self):
self.track = FullTrack(**self.track)
self.played_at = Timestamp.from_string(self.played_at)
if self.context is not None:
self.context = Context(**self.context)
@dataclass(repr=False)
class PlayHistoryCursor(Cursor):
"""Cursor to play history."""
before: str
@dataclass(repr=False)
class SimpleShowPaging(OffsetPaging):
"""Paging of simplified shows."""
items: List[SimpleShow]
def __post_init__(self):
self.items = ModelList(SimpleShow(**i) for i in self.items)
@dataclass(repr=False)
class SavedShow(Model):
"""Show saved in library."""
added_at: Timestamp
show: SimpleShow
def __post_init__(self):
self.added_at = Timestamp.from_string(self.added_at)
self.show = SimpleShow(**self.show)
@dataclass(repr=False)
class SavedShowPaging(OffsetPaging):
"""Paging of shows in library."""
items: List[SavedShow]
def __post_init__(self):
self.items = ModelList(SavedShow(**i) for i in self.items)