udpate for no data
This commit is contained in:
parent
9b444554e5
commit
b88749b0c9
@ -9,12 +9,16 @@ from datetime import datetime
|
|||||||
|
|
||||||
async def current_track():
|
async def current_track():
|
||||||
mopidy = await MopidyClient().connect()
|
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()
|
current_track_data = await mopidy.playback.get_current_track()
|
||||||
time_position = 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 current_track_data["uri"]:
|
if "ytmusic" in current_track_data["uri"]:
|
||||||
|
if "album" in current_track_data:
|
||||||
totalTime = current_track_data["length"]
|
totalTime = current_track_data["length"]
|
||||||
track_total_length = datetime.fromtimestamp(totalTime / 1000.0).strftime(
|
track_total_length = datetime.fromtimestamp(totalTime / 1000.0).strftime(
|
||||||
"%M:%S"
|
"%M:%S"
|
||||||
@ -25,9 +29,24 @@ async def current_track():
|
|||||||
"Song": current_track_data["name"],
|
"Song": current_track_data["name"],
|
||||||
"TrackTime": time_position + "/" + track_total_length,
|
"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:
|
else:
|
||||||
|
try:
|
||||||
stream_title = await mopidy.playback.get_stream_title()
|
stream_title = await mopidy.playback.get_stream_title()
|
||||||
artist_and_song = stream_title.split(" - ")
|
artist_and_song = stream_title.split(" - ")
|
||||||
|
except:
|
||||||
|
stream_title = "None"
|
||||||
|
artist_and_song = ['None','None']
|
||||||
current_data = {
|
current_data = {
|
||||||
"Artist": current_track_data["name"],
|
"Artist": current_track_data["name"],
|
||||||
"Album": artist_and_song[0],
|
"Album": artist_and_song[0],
|
||||||
@ -56,7 +75,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(10)
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user