|
@@ -9,25 +9,44 @@ from datetime import datetime
|
|
|
|
|
|
async def current_track():
|
|
|
mopidy = await MopidyClient().connect()
|
|
|
+ if await mopidy.playback.get_state() == "stopped":
|
|
|
+ oled.text("Nothing", 32, 26, 1)
|
|
|
+ oled.text("Playing", 32, 36, 1)
|
|
|
+ return
|
|
|
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 current_track_data["uri"]:
|
|
|
- totalTime = current_track_data["length"]
|
|
|
- track_total_length = datetime.fromtimestamp(totalTime / 1000.0).strftime(
|
|
|
- "%M:%S"
|
|
|
- )
|
|
|
- current_data = {
|
|
|
- "Artist": current_track_data["artists"][0]["name"],
|
|
|
- "Album": current_track_data["album"]["name"],
|
|
|
- "Song": current_track_data["name"],
|
|
|
- "TrackTime": time_position + "/" + track_total_length,
|
|
|
- }
|
|
|
+ if "album" in current_track_data:
|
|
|
+ totalTime = current_track_data["length"]
|
|
|
+ track_total_length = datetime.fromtimestamp(totalTime / 1000.0).strftime(
|
|
|
+ "%M:%S"
|
|
|
+ )
|
|
|
+ current_data = {
|
|
|
+ "Artist": current_track_data["artists"][0]["name"],
|
|
|
+ "Album": current_track_data["album"]["name"],
|
|
|
+ "Song": current_track_data["name"],
|
|
|
+ "TrackTime": time_position + "/" + track_total_length,
|
|
|
+ }
|
|
|
+ elif "ytmusic:track" in current_track_data["uri"]:
|
|
|
+ totalTime = current_track_data["length"]
|
|
|
+ track_total_length = datetime.fromtimestamp(totalTime / 1000.0).strftime(
|
|
|
+ "%M:%S"
|
|
|
+ )
|
|
|
+ current_data = {
|
|
|
+ "Artist": "-",
|
|
|
+ "Album": current_track_data["artists"][0]["name"],
|
|
|
+ "Song": current_track_data["name"],
|
|
|
+ "TrackTime": time_position + "/" + track_total_length,
|
|
|
+ }
|
|
|
else:
|
|
|
- stream_title = await mopidy.playback.get_stream_title()
|
|
|
- artist_and_song = stream_title.split(" - ")
|
|
|
+ try:
|
|
|
+ stream_title = await mopidy.playback.get_stream_title()
|
|
|
+ artist_and_song = stream_title.split(" - ")
|
|
|
+ except:
|
|
|
+ stream_title = "None"
|
|
|
+ artist_and_song = ['None','None']
|
|
|
current_data = {
|
|
|
"Artist": current_track_data["name"],
|
|
|
"Album": artist_and_song[0],
|
|
@@ -56,7 +75,7 @@ async def main():
|
|
|
oled.text("Floppy Player", 26, 0, 1)
|
|
|
await current_track()
|
|
|
oled.show()
|
|
|
- time.sleep(10)
|
|
|
+ time.sleep(5)
|
|
|
|
|
|
|
|
|
asyncio.run(main())
|