smal fix & add day to standby
This commit is contained in:
parent
f3645368ec
commit
7e1db53a93
@ -27,12 +27,20 @@ class Api:
|
||||
req = requests.get(url, headers=self.header)
|
||||
if req.status_code == 204:
|
||||
return "not-playing"
|
||||
if req.status_code != 200:
|
||||
warnings.warn(f"Unknown API Error {req.status_code},\n{req.content}")
|
||||
if req.status_code == 401:
|
||||
warnings.warn("API Error: Bad or Expired token")
|
||||
elif req.status_code == 403:
|
||||
warnings.warn("API Error: Bad OAuth request, re-authenticating won't help")
|
||||
elif req.status_code == 429:
|
||||
warnings.warn("API Error: API rate limit exceeded")
|
||||
elif req.status_code != 200:
|
||||
warnings.warn(f"{req.status_code},\n{req.content}")
|
||||
return None
|
||||
return self._format_req(req.json())
|
||||
|
||||
def _format_req(self, r):
|
||||
if not r["is_playing"]:
|
||||
return "not-playing"
|
||||
item, album = r["item"], r["item"]["album"]
|
||||
res = {
|
||||
"progress_ms": r["progress_ms"],
|
||||
|
@ -58,7 +58,7 @@ def display_loop(api: Api, cfg: Dict):
|
||||
|
||||
last_api_call = 0
|
||||
last_auth_refresh = 0
|
||||
current_mode = None
|
||||
current_mode = None # 0: not-playing, 1: playing
|
||||
last_track = None
|
||||
data = None
|
||||
auth_interval = 0
|
||||
@ -72,7 +72,6 @@ def display_loop(api: Api, cfg: Dict):
|
||||
if time.time() - last_api_call >= cfg["api_interval"]:
|
||||
data = api.getPlaying()
|
||||
last_api_call = time.time()
|
||||
|
||||
if data == None:
|
||||
warnings.warn("No data found")
|
||||
d.ShowImage(error_img)
|
||||
@ -89,6 +88,13 @@ def display_loop(api: Api, cfg: Dict):
|
||||
fill=(255, 255, 255),
|
||||
# fill=cfg["color_theme"]["text"],
|
||||
)
|
||||
draw.text(
|
||||
(20, 152),
|
||||
current_time.strftime("%a %d"),
|
||||
font=Font2,
|
||||
fill=(255, 255, 255),
|
||||
# fill=cfg["color_theme"]["text"],
|
||||
)
|
||||
if current_mode != 0:
|
||||
current_mode = 0
|
||||
print("Standby mode")
|
||||
@ -135,7 +141,7 @@ def display_loop(api: Api, cfg: Dict):
|
||||
progress_time = data["progress_ms"] + int(
|
||||
(time.time() - last_api_call) * 1000
|
||||
)
|
||||
progress = progress_time / data["duration_ms"]
|
||||
progress = min(1, progress_time / data["duration_ms"])
|
||||
bar_width = int(w * progress)
|
||||
draw.rectangle(
|
||||
[(8, h - 22), (w + 2, h - 8)],
|
||||
|
Loading…
x
Reference in New Issue
Block a user