Fixed some issues
This commit is contained in:
parent
742a7db02e
commit
342121a315
1 changed files with 24 additions and 24 deletions
48
main.py
48
main.py
|
|
@ -37,10 +37,10 @@ async def broadcastMusicStatus():
|
||||||
author = thchStatusJson['artist']
|
author = thchStatusJson['artist']
|
||||||
videoProgress = int(thchStatusJson['elapsedSeconds'])
|
videoProgress = int(thchStatusJson['elapsedSeconds'])
|
||||||
duration = int(thchStatusJson['songDuration'])
|
duration = int(thchStatusJson['songDuration'])
|
||||||
ads = "False"
|
paused = "False"
|
||||||
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{ads}"
|
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{paused}"
|
||||||
print(formattedData)
|
await asyncio.sleep(.5)
|
||||||
await asyncio.sleep(.1)
|
|
||||||
if appVer == "2":
|
if appVer == "2":
|
||||||
ytdm_status = ytmd.get_state()
|
ytdm_status = ytmd.get_state()
|
||||||
ytdm_statusJson = ytdm_status.json()
|
ytdm_statusJson = ytdm_status.json()
|
||||||
|
|
@ -48,10 +48,10 @@ async def broadcastMusicStatus():
|
||||||
author = ytdm_statusJson["video"]["author"]
|
author = ytdm_statusJson["video"]["author"]
|
||||||
videoProgress = int(ytdm_statusJson["player"]["videoProgress"])
|
videoProgress = int(ytdm_statusJson["player"]["videoProgress"])
|
||||||
duration = int(ytdm_statusJson["video"]["durationSeconds"])
|
duration = int(ytdm_statusJson["video"]["durationSeconds"])
|
||||||
ads = bool(ytdm_statusJson["player"]["adPlaying"])
|
paused = bool(ytdm_statusJson["player"]["adPlaying"])
|
||||||
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{ads}"
|
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{paused}"
|
||||||
print(formattedData)
|
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
if appVer == "3":
|
if appVer == "3":
|
||||||
eddyStatus = requests.get(eddy_statusUrl)
|
eddyStatus = requests.get(eddy_statusUrl)
|
||||||
eddyStatusJson = eddyStatus.json()
|
eddyStatusJson = eddyStatus.json()
|
||||||
|
|
@ -60,35 +60,35 @@ async def broadcastMusicStatus():
|
||||||
authorNameList = [names['name'] for names in authorNames]
|
authorNameList = [names['name'] for names in authorNames]
|
||||||
if len(authorNameList) == 1:
|
if len(authorNameList) == 1:
|
||||||
author = authorNameList[0]
|
author = authorNameList[0]
|
||||||
print(author)
|
elif len(authorNameList) == 2:
|
||||||
elif len(authorNameList)== 2:
|
|
||||||
author = (" & ".join(authorNameList))
|
author = (" & ".join(authorNameList))
|
||||||
print(author)
|
|
||||||
else:
|
else:
|
||||||
author = (", ".join(authorNameList[:-1]) + " & " + authorNameList[-1])
|
author = (", ".join(authorNameList[:-1]) + " & " + authorNameList[-1])
|
||||||
print(author)
|
|
||||||
author = author
|
author = author
|
||||||
videoProgress = int(eddyStatusJson["position"])
|
|
||||||
duration = int(eddyStatusJson["duration"])
|
duration = int(eddyStatusJson["duration"])
|
||||||
ads = "false"
|
paused = bool(eddyStatusJson["paused"])
|
||||||
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{ads}"
|
if paused == False:
|
||||||
print(formattedData)
|
videoProgress = int(eddyStatusJson["position"])
|
||||||
await asyncio.sleep(2)
|
lastVideoProgress = int(eddyStatusJson["lastUpdatedPosition"])
|
||||||
|
else:
|
||||||
|
videoProgress = lastVideoProgress
|
||||||
|
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{paused}"
|
||||||
|
await asyncio.sleep(.5)
|
||||||
|
|
||||||
for clients in wsClients:
|
for clients in wsClients:
|
||||||
try:
|
await clients.send(formattedData)
|
||||||
await clients.send(formattedData)
|
|
||||||
except:
|
|
||||||
print("ERROR ON SENDING MESSAGE! CLIENT DROPPED BEFORE RECIVING MESSAGE!")
|
|
||||||
# If ads are programmed to be false, it might be because A: There's no function to detect it or B: It's a subscription service (like Tidal or YTM Premium)
|
|
||||||
|
|
||||||
|
|
||||||
async def websocketMessages(websocket):
|
async def websocketMessages(websocket):
|
||||||
print("Client connected")
|
print("Client connected")
|
||||||
wsClients.add(websocket)
|
wsClients.add(websocket)
|
||||||
async for message in websocket:
|
try:
|
||||||
await websocket.send(message)
|
async for message in websocket:
|
||||||
|
await websocket.send(message)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
wsClients.remove(websocket)
|
wsClients.remove(websocket)
|
||||||
print("Client disconnected")
|
print("Client disconnected.")
|
||||||
|
|
||||||
async def websocketMain():
|
async def websocketMain():
|
||||||
print(f"Hello! Hosting at:\nws://{HOST}:{PORT}")
|
print(f"Hello! Hosting at:\nws://{HOST}:{PORT}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue