cleanup
This commit is contained in:
parent
45d5316b82
commit
44d44c44d3
@ -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 asyncio
|
||||||
import time
|
import time
|
||||||
import board
|
import board
|
||||||
import digitalio
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
|
||||||
import adafruit_ssd1306
|
import adafruit_ssd1306
|
||||||
|
|
||||||
from mopidy_async_client import MopidyClient
|
from mopidy_async_client import MopidyClient
|
||||||
@ -22,27 +9,29 @@ from datetime import datetime
|
|||||||
|
|
||||||
async def current_track():
|
async def current_track():
|
||||||
mopidy = await MopidyClient().connect()
|
mopidy = await MopidyClient().connect()
|
||||||
res = await mopidy.playback.get_current_track()
|
current_track_data = await mopidy.playback.get_current_track()
|
||||||
b = datetime.fromtimestamp(
|
time_position = datetime.fromtimestamp(
|
||||||
await mopidy.playback.get_time_position() / 1000.0
|
await mopidy.playback.get_time_position() / 1000.0
|
||||||
).strftime("%M:%S")
|
).strftime("%M:%S")
|
||||||
|
|
||||||
if "ytmusic" in res["uri"]:
|
if "ytmusic" in current_track_data["uri"]:
|
||||||
totalTime = res["length"]
|
totalTime = current_track_data["length"]
|
||||||
a = datetime.fromtimestamp(totalTime / 1000.0).strftime("%M:%S")
|
track_total_length = datetime.fromtimestamp(totalTime / 1000.0).strftime(
|
||||||
|
"%M:%S"
|
||||||
|
)
|
||||||
current_data = {
|
current_data = {
|
||||||
"Artist": res["artists"][0]["name"],
|
"Artist": current_track_data["artists"][0]["name"],
|
||||||
"Album": res["album"]["name"],
|
"Album": current_track_data["album"]["name"],
|
||||||
"Song": res["name"],
|
"Song": current_track_data["name"],
|
||||||
"TrackTime": b + "/" + a,
|
"TrackTime": time_position + "/" + track_total_length,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
a = await mopidy.playback.get_stream_title()
|
stream_title = await mopidy.playback.get_stream_title()
|
||||||
data = a.split(" - ")
|
artist_and_song = stream_title.split(" - ")
|
||||||
current_data = {
|
current_data = {
|
||||||
"Artist": res["name"],
|
"Artist": current_track_data["name"],
|
||||||
"Album": data[0],
|
"Album": artist_and_song[0],
|
||||||
"Song": data[1],
|
"Song": artist_and_song[1],
|
||||||
"TrackTime": "",
|
"TrackTime": "",
|
||||||
}
|
}
|
||||||
await mopidy.disconnect()
|
await mopidy.disconnect()
|
||||||
@ -53,18 +42,12 @@ async def current_track():
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
# Define the Reset Pin
|
|
||||||
oled_reset = digitalio.DigitalInOut(board.D4)
|
|
||||||
|
|
||||||
# Change these
|
|
||||||
# to the right size for your display!
|
|
||||||
WIDTH = 128
|
WIDTH = 128
|
||||||
HEIGHT = 64 # Change to 64 if needed
|
HEIGHT = 64
|
||||||
BORDER = 0
|
|
||||||
|
|
||||||
# Use for I2C.
|
# Use for I2C.
|
||||||
i2c = board.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():
|
async def main():
|
||||||
@ -73,7 +56,7 @@ async def main():
|
|||||||
oled.text("Floppy Player", 26, 0, 1)
|
oled.text("Floppy Player", 26, 0, 1)
|
||||||
await current_track()
|
await current_track()
|
||||||
oled.show()
|
oled.show()
|
||||||
time.sleep(5)
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user