added and removed several code
This commit is contained in:
parent
f00dfde33c
commit
2197697e16
2 changed files with 26 additions and 24 deletions
|
|
@ -1 +1,2 @@
|
||||||
# YtmdToWebsocket
|
# YtmdToWebsocket
|
||||||
|
### An easy way to connect to [th-ch's YoutubeMusic](https://google.com) and [YTMDesktop](google.com)
|
||||||
47
main.py
47
main.py
|
|
@ -13,27 +13,20 @@ key = 'null'
|
||||||
|
|
||||||
# Websocket Config
|
# Websocket Config
|
||||||
HOST = "localhost"
|
HOST = "localhost"
|
||||||
PORT = 8081
|
PORT = 8080
|
||||||
wsClients = set()
|
wsClients = set()
|
||||||
|
|
||||||
# YTDM CONFIG
|
# YTDM CONFIG
|
||||||
appId = "tojg"
|
appId = "tojg"
|
||||||
code = '0000'
|
|
||||||
ytdm_baseUrl = "http://localhost:9863"
|
ytdm_baseUrl = "http://localhost:9863"
|
||||||
ytdm_apiBase = ytdm_baseUrl + "/api/v1"
|
ytdm_apiBase = ytdm_baseUrl + "/api/v1"
|
||||||
|
ytdm_authRequest = ytdm_baseUrl + "/auth/request"
|
||||||
ytdmJsonConfig = {
|
|
||||||
"appId": appId,
|
|
||||||
"appName": "ytmToWeb",
|
|
||||||
"appVersion": "0.0.1"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# THYTM CONFIG
|
# THYTM CONFIG
|
||||||
thytm_baseUrl = "http://localhost:26538/api/v1"
|
thytm_baseUrl = "http://localhost:26538/api/v1"
|
||||||
thytm_statusUrl = thytm_baseUrl + '/song'
|
thytm_statusUrl = thytm_baseUrl + '/song'
|
||||||
|
|
||||||
# JSON config for the app
|
# JSON config for the py app
|
||||||
importantJson = {
|
importantJson = {
|
||||||
"appVer": appVer,
|
"appVer": appVer,
|
||||||
"key": key
|
"key": key
|
||||||
|
|
@ -44,37 +37,44 @@ importantJson = {
|
||||||
def ytdm_getAuth():
|
def ytdm_getAuth():
|
||||||
print("Getting Auth...")
|
print("Getting Auth...")
|
||||||
|
|
||||||
|
|
||||||
# th-ch's YTM Logic
|
|
||||||
|
|
||||||
def thYtm_getStatus():
|
|
||||||
print("ass")
|
|
||||||
|
|
||||||
# Websocket Logic
|
# Websocket Logic
|
||||||
async def broadcastMusicStatus():
|
async def broadcastMusicStatus():
|
||||||
while True:
|
while True:
|
||||||
thch_status = requests.get(thytm_statusUrl)
|
global appVer
|
||||||
print(thch_status.json())
|
if appVer == "1":
|
||||||
|
thch_status = requests.get(thytm_statusUrl)
|
||||||
|
thchStatusJson = thch_status.json()
|
||||||
|
song_name = thchStatusJson['alternativeTitle']
|
||||||
|
author = thchStatusJson['artist']
|
||||||
|
videoProgress = int(thchStatusJson['elapsedSeconds'])
|
||||||
|
duration = int(thchStatusJson['songDuration'])
|
||||||
|
ads = "False" # Keep this false! This bool is only used in YTMD but is here for sake of not breaking
|
||||||
|
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{ads}"
|
||||||
|
print(formattedData)
|
||||||
|
else:
|
||||||
|
formattedData = f"Sorry mate! We are working on one thing..."
|
||||||
for clients in wsClients:
|
for clients in wsClients:
|
||||||
try:
|
try:
|
||||||
await clients.send(thch_status.json())
|
await clients.send(formattedData)
|
||||||
except:
|
except:
|
||||||
print("ERROR ON SENDING MESSAGES!")
|
print("ERROR ON SENDING MESSAGE! CLIENT DROPPED BEFORE RECIVING MESSAGE!")
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(5) # YTDM only allows clients to look at its API every 5 seconds, so it limits thch.
|
||||||
|
|
||||||
|
|
||||||
async def websocketMessages(websocket):
|
async def websocketMessages(websocket):
|
||||||
print("Client connected")
|
print("Client connected")
|
||||||
|
wsClients.add(websocket)
|
||||||
|
# Stupid me forgot to add the client to the set
|
||||||
async for message in websocket:
|
async for message in websocket:
|
||||||
await websocket.send(message)
|
await websocket.send(message)
|
||||||
|
wsClients.remove(websocket)
|
||||||
|
# Also stupid me forgot to remove the client
|
||||||
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}")
|
||||||
wsServer = await websockets.serve(websocketMessages, HOST, PORT)
|
wsServer = await websockets.serve(websocketMessages, HOST, PORT)
|
||||||
await asyncio.gather(broadcastMusicStatus())
|
await asyncio.gather(broadcastMusicStatus())
|
||||||
# async with serve(broadcastMusicStatus, host, port) as server:
|
|
||||||
# await server.serve_forever()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if(os.path.exists("key.json")):
|
if(os.path.exists("key.json")):
|
||||||
|
|
@ -88,6 +88,7 @@ if __name__ == "__main__":
|
||||||
asyncio.run(websocketMain())
|
asyncio.run(websocketMain())
|
||||||
elif appVer == "2":
|
elif appVer == "2":
|
||||||
print("yay")
|
print("yay")
|
||||||
|
asyncio.run(websocketMain())
|
||||||
else:
|
else:
|
||||||
print("Who the fuck asked? Go to github and open an issue!") # Just thought this was funny - Jckl
|
print("Who the fuck asked? Go to github and open an issue!") # Just thought this was funny - Jckl
|
||||||
exit
|
exit
|
||||||
Loading…
Reference in a new issue