added equality functions for tracks and currently playing

This commit is contained in:
aj 2019-12-22 12:14:50 +00:00
parent 2ef5e9c1c4
commit de5da3e057
2 changed files with 22 additions and 1 deletions

View File

@ -94,5 +94,20 @@ class CurrentlyPlaying:
f'context({self.context}) track({self.track}) device({self.device}) shuffle({self.shuffle}) ' \ f'context({self.context}) track({self.track}) device({self.device}) shuffle({self.shuffle}) ' \
f'repeat({self.repeat}) time({self.timestamp})' f'repeat({self.repeat}) time({self.timestamp})'
def __eq__(self, other):
return isinstance(other, CurrentlyPlaying) and other.track == self.track
@staticmethod
def _format_duration(duration):
total_seconds = duration / 1000
minutes = int((total_seconds/60) % 60)
seconds = int(total_seconds % 60)
return f'{minutes}:{seconds}'
def __str__(self): def __str__(self):
return f'playing: {self.is_playing} - {self.track} on {self.device}' if self.is_playing:
playing = 'playing'
else:
playing = '(paused)'
return f'{playing} {self.track} on {self.device} ({self._format_duration(self.progress_ms)})'

View File

@ -53,6 +53,9 @@ class Track:
return Color.YELLOW + Color.BOLD + 'Track' + Color.END + \ return Color.YELLOW + Color.BOLD + 'Track' + Color.END + \
f': {self.name}, ({self.album}), {self.artists}' f': {self.name}, ({self.album}), {self.artists}'
def __eq__(self, other):
return isinstance(other, Track) and other.name == self.name and other.artists == self.artists
@staticmethod @staticmethod
def wrap(name: str = None, def wrap(name: str = None,
artists: List[str] = None, artists: List[str] = None,
@ -110,6 +113,9 @@ class SpotifyTrack(Track):
return string return string
def __eq__(self, other):
return isinstance(other, SpotifyTrack) and other.uri == self.uri
@staticmethod @staticmethod
def wrap(uri: Uri = None, def wrap(uri: Uri = None,
name: str = None, name: str = None,