From f5c6e9e0aa5f86e221c69bf88f47acd1f14f3c57 Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Tue, 21 May 2024 21:15:22 +0100 Subject: [PATCH] Show media album and TV show details on media screens --- api.py | 7 ++++-- screens.py | 63 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/api.py b/api.py index 0f204cc..98f819b 100644 --- a/api.py +++ b/api.py @@ -61,10 +61,13 @@ def getMediaPlayerData(entity_id: str) -> dict: "shuffle": response["attributes"]["shuffle"] if e and "shuffle" in response["attributes"] else False, "repeat": response["attributes"]["repeat"] == "on" if e and "repeat" in response["attributes"] else False, "volume_level": response["attributes"]["volume_level"] if e and "volume_level" in response["attributes"] else 0, - "entity_picture": response["attributes"]["entity_picture"] if e and "entity_picture" in (dict)(response["attributes"]) else None, + "media_content_type": response["attributes"]["media_content_type"] if e and "media_content_type" in (dict)(response["attributes"]) else "music", + "media_series_title": response["attributes"]["media_series_title"] if e and "media_series_title" in (dict)(response["attributes"]) else "", + "media_season": response["attributes"]["media_season"] if e and "media_season" in (dict)(response["attributes"]) else "", + "media_episode": response["attributes"]["media_episode"] if e and "media_episode" in (dict)(response["attributes"]) else "", "media_duration": response["attributes"]["media_duration"] if e and "media_duration" in (dict)(response["attributes"]) else 0, "media_position": p, - "media_title": response["attributes"]["media_title"] if e and "media_title" in (dict)(response["attributes"]) else "Nothing playing", + "media_title": response["attributes"]["media_title"] if e and "media_title" in (dict)(response["attributes"]) else "Not playing", "media_artist": response["attributes"]["media_artist"] if e and "media_artist" in (dict)(response["attributes"]) else "", "media_album_name": response["attributes"]["media_album_name"] if e and "media_album_name" in (dict)(response["attributes"]) else "" } diff --git a/screens.py b/screens.py index 186e3be..44b1802 100644 --- a/screens.py +++ b/screens.py @@ -33,8 +33,7 @@ class MediaScreen(Screen): super().__init__(n) self.e = e self.valid = e != None and e != "" - self.m_t = -1 - self.m_a = -1 + self.str_start_i = [-1, -1, -1] def display(self, lcd) -> bool: super().display(lcd) @@ -64,32 +63,44 @@ class MediaScreen(Screen): lcd.pixel(col_i + x_offset, row_i + y_offset, 0xffff) self.__updateMediaPositionBar(lcd, self.d["media_position"], self.d["media_duration"]) if (self.d["media_duration"] != None): - mins = self.d["media_duration"] // 60 - secs = self.d["media_duration"] % 60 - rght_st(lcd, f"{mins}:{secs}", lcd.width, lcd.height - 16, 1, 180, 180, 180) - mt_cs = lcd.width//sz_to_w(3) - mt_l = len(self.d["media_title"]) > mt_cs - if (mt_l): - if (self.m_t + mt_cs > len(self.d["media_title"])): - self.m_t = 0 + mins = int(self.d["media_duration"] // 60) + secs = int(self.d["media_duration"] % 60) + rght_st(lcd, f"{mins}:{secs:02}", lcd.width, lcd.height - 16, 1, 180, 180, 180) + + txts = [ + { + "s": "S" + str(self.d["media_season"]) + " E" + str(self.d["media_episode"]) if self.d["media_content_type"] == "tvshow" else self.d["media_album_name"], + "sz": 2, + "o": 106 + }, + { + "s": self.d["media_series_title"] if self.d["media_content_type"] == "tvshow" else self.d["media_artist"], + "sz": 2, + "o": 82 + }, + { + "s": self.d["media_title"], + "sz": 3, + "o": 56 + } + ] + scroll = False + for i, txt in enumerate(txts): + cs = lcd.width//sz_to_w(txt["sz"]) + if (len(txt["s"]) > cs): + scroll = True + if (self.str_start_i[i] + cs >= len(txt["s"])): + self.str_start_i[i] = 0 + else: + self.str_start_i[i] += 1 + s = txt["s"][self.str_start_i[i]:self.str_start_i[i] + cs] else: - self.m_t += 1 - cntr_st(lcd, lcd.width, self.d["media_title"][self.m_t:self.m_t + mt_cs], lcd.height - 72, 3, 255, 255, 255) - else: - self.m_t = -1 - cntr_st(lcd, lcd.width, self.d["media_title"], lcd.height - 72, 3, 255, 255, 255) - ma_cs = lcd.width//sz_to_w(2) - ma_l = len(self.d["media_artist"]) > ma_cs - if (ma_l): - if (self.m_a + ma_cs > len(self.d["media_artist"])): - self.m_a = 0 - else: - self.m_a += 1 - cntr_st(lcd, lcd.width, self.d["media_artist"][self.m_a:self.m_a + ma_cs], lcd.height - 98, 2, 255, 255, 255) - else: - cntr_st(lcd, lcd.width, self.d["media_artist"], lcd.height - 98, 2, 255, 255, 255) + self.str_start_i[i] = -1 + s = txt["s"] + cntr_st(lcd, lcd.width, s, lcd.height - txt["o"], txt["sz"], 255, 255, 255) + lcd.show() - if (mt_l or ma_l): + if (scroll): self.d = {} return True return False