diff --git a/screen_output.py b/screen_output.py index eee537b..a58aa4d 100644 --- a/screen_output.py +++ b/screen_output.py @@ -1,19 +1,6 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# SPDX-License-Identifier: MIT - -""" -This demo will fill the screen with white, draw a black box on top -and then print Hello World! in the center of the display - -This example is for use on (Linux) computers that are using CPython with -Adafruit Blinka to support CircuitPython libraries. CircuitPython does -not support PIL/pillow (python imaging library)! -""" import asyncio import time import board -import digitalio -from PIL import Image, ImageDraw, ImageFont import adafruit_ssd1306 from mopidy_async_client import MopidyClient @@ -22,27 +9,29 @@ from datetime import datetime async def current_track(): mopidy = await MopidyClient().connect() - res = await mopidy.playback.get_current_track() - b = datetime.fromtimestamp( + current_track_data = await mopidy.playback.get_current_track() + time_position = datetime.fromtimestamp( await mopidy.playback.get_time_position() / 1000.0 ).strftime("%M:%S") - if "ytmusic" in res["uri"]: - totalTime = res["length"] - a = datetime.fromtimestamp(totalTime / 1000.0).strftime("%M:%S") + if "ytmusic" in current_track_data["uri"]: + totalTime = current_track_data["length"] + track_total_length = datetime.fromtimestamp(totalTime / 1000.0).strftime( + "%M:%S" + ) current_data = { - "Artist": res["artists"][0]["name"], - "Album": res["album"]["name"], - "Song": res["name"], - "TrackTime": b + "/" + a, + "Artist": current_track_data["artists"][0]["name"], + "Album": current_track_data["album"]["name"], + "Song": current_track_data["name"], + "TrackTime": time_position + "/" + track_total_length, } else: - a = await mopidy.playback.get_stream_title() - data = a.split(" - ") + stream_title = await mopidy.playback.get_stream_title() + artist_and_song = stream_title.split(" - ") current_data = { - "Artist": res["name"], - "Album": data[0], - "Song": data[1], + "Artist": current_track_data["name"], + "Album": artist_and_song[0], + "Song": artist_and_song[1], "TrackTime": "", } await mopidy.disconnect() @@ -53,18 +42,12 @@ async def current_track(): return -# Define the Reset Pin -oled_reset = digitalio.DigitalInOut(board.D4) - -# Change these -# to the right size for your display! WIDTH = 128 -HEIGHT = 64 # Change to 64 if needed -BORDER = 0 +HEIGHT = 64 # Use for I2C. i2c = board.I2C() -oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3C, reset=oled_reset) +oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3C) async def main(): @@ -73,7 +56,7 @@ async def main(): oled.text("Floppy Player", 26, 0, 1) await current_track() oled.show() - time.sleep(5) + time.sleep(10) asyncio.run(main())