Refactored method get_info()
This commit is contained in:
parent
70b56624c2
commit
f4479b7c77
@ -50,16 +50,7 @@ class Spotify(IntervalModule):
|
|||||||
on_upscroll = 'next_song'
|
on_upscroll = 'next_song'
|
||||||
on_downscroll = 'previous_song'
|
on_downscroll = 'previous_song'
|
||||||
|
|
||||||
def get_info(self, player):
|
def _get_length(self, metadata):
|
||||||
"""gets player track info from playerctl"""
|
|
||||||
|
|
||||||
artist = player.get_artist()
|
|
||||||
title = player.get_title()
|
|
||||||
album = player.get_album()
|
|
||||||
status = player.props.status.lower()
|
|
||||||
|
|
||||||
# stores the metadata and checks if it is valid
|
|
||||||
metadata = player.props.metadata
|
|
||||||
try:
|
try:
|
||||||
time = dict(metadata)["mpris:length"] / 60.0e6
|
time = dict(metadata)["mpris:length"] / 60.0e6
|
||||||
minutes = math.floor(time)
|
minutes = math.floor(time)
|
||||||
@ -67,28 +58,39 @@ class Spotify(IntervalModule):
|
|||||||
if seconds < 10:
|
if seconds < 10:
|
||||||
seconds = "0" + str(seconds)
|
seconds = "0" + str(seconds)
|
||||||
length = "{}:{}".format(minutes, seconds)
|
length = "{}:{}".format(minutes, seconds)
|
||||||
except (KeyError, TypeError):
|
except KeyError:
|
||||||
length = ""
|
length = ""
|
||||||
|
|
||||||
# returns a dictionary of all player data
|
return length
|
||||||
return {
|
|
||||||
"status": self.status[status]
|
def get_info(self, player):
|
||||||
if status in self.status.keys() else "",
|
"""gets player track info from playerctl"""
|
||||||
"title": title if title else "",
|
|
||||||
"album": album if album else "",
|
result = {
|
||||||
"artist": artist if artist else "",
|
"status": "",
|
||||||
"length": length,
|
"artist": "",
|
||||||
|
"title": "",
|
||||||
|
"album": "",
|
||||||
|
"length": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if player.props.status:
|
||||||
|
result["status"] = player.props.status.lower()
|
||||||
|
result["artist"] = player.get_artist()
|
||||||
|
result["title"] = player.get_title()
|
||||||
|
result["album"] = player.get_album()
|
||||||
|
result["length"] = self._get_length(player.props.metadata)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Main statement, executes all code every interval"""
|
"""Main statement, executes all code every interval"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.player = Playerctl.Player(player_name=self.player_name)
|
self.player = Playerctl.Player(player_name=self.player_name)
|
||||||
|
data = self.get_info(self.player)
|
||||||
|
|
||||||
fdict = self.get_info(self.player)
|
self.output = {"full_text": formatp(self.format, **data),
|
||||||
|
|
||||||
self.output = {"full_text": formatp(self.format, **fdict),
|
|
||||||
"color": self.color}
|
"color": self.color}
|
||||||
except GLib.Error:
|
except GLib.Error:
|
||||||
self.output = {"full_text": self.format_not_running,
|
self.output = {"full_text": self.format_not_running,
|
||||||
|
Loading…
Reference in New Issue
Block a user