Added YTMD and TidaLuna via eddyapi support
This commit is contained in:
parent
2197697e16
commit
b7f3558d90
3 changed files with 62 additions and 35 deletions
|
|
@ -1,2 +1,2 @@
|
||||||
# YtmdToWebsocket
|
# YtmdToWebsocket
|
||||||
### An easy way to connect to [th-ch's YoutubeMusic](https://google.com) and [YTMDesktop](google.com)
|
### An easy way to connect to [th-ch's YoutubeMusic](https://github.com/th-ch/youtube-music), [YTMDesktop](https://github.com/ytmdesktop/ytmdesktop), and [Tidal via TidaLuna and eddyapi](https://github.com/Inrixia/TidaLuna) (Must have a valid subscription for any of these, I am not responsible if you break the TOS of any of these platforms.)
|
||||||
92
main.py
92
main.py
|
|
@ -4,38 +4,27 @@ import websockets
|
||||||
import asyncio
|
import asyncio
|
||||||
from websockets import serve
|
from websockets import serve
|
||||||
import requests
|
import requests
|
||||||
|
from ytmd_sdk import Events, YTMD, Parser
|
||||||
#import re: We don't need this right now
|
|
||||||
|
|
||||||
# Variable init
|
|
||||||
appVer = 0
|
|
||||||
key = 'null'
|
|
||||||
|
|
||||||
# Websocket Config
|
# Websocket Config
|
||||||
HOST = "localhost"
|
HOST = "localhost"
|
||||||
PORT = 8080
|
PORT = 8080
|
||||||
wsClients = set()
|
wsClients = set()
|
||||||
|
|
||||||
# YTDM CONFIG
|
# YTMD Config
|
||||||
appId = "tojg"
|
ytmd = YTMD("tojg", "MusicToWebsocket", "1.0.0")
|
||||||
ytdm_baseUrl = "http://localhost:9863"
|
|
||||||
ytdm_apiBase = ytdm_baseUrl + "/api/v1"
|
|
||||||
ytdm_authRequest = ytdm_baseUrl + "/auth/request"
|
|
||||||
|
|
||||||
# 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 py app
|
# EddyAPI Config
|
||||||
importantJson = {
|
eddy_baseUrl = "http://localhost:3665"
|
||||||
"appVer": appVer,
|
eddy_statusUrl = eddy_baseUrl + "/now-playing"
|
||||||
"key": key
|
|
||||||
}
|
|
||||||
|
|
||||||
# YTDM Logic
|
# YTDM Logic
|
||||||
|
def ytdm_logic():
|
||||||
def ytdm_getAuth():
|
key = ytmd.authenticate()
|
||||||
print("Getting Auth...")
|
|
||||||
|
|
||||||
# Websocket Logic
|
# Websocket Logic
|
||||||
async def broadcastMusicStatus():
|
async def broadcastMusicStatus():
|
||||||
|
|
@ -48,27 +37,57 @@ 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" # Keep this false! This bool is only used in YTMD but is here for sake of not breaking
|
ads = "False"
|
||||||
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{ads}"
|
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{ads}"
|
||||||
print(formattedData)
|
print(formattedData)
|
||||||
else:
|
await asyncio.sleep(.1)
|
||||||
formattedData = f"Sorry mate! We are working on one thing..."
|
if appVer == "2":
|
||||||
|
ytdm_status = ytmd.get_state()
|
||||||
|
ytdm_statusJson = ytdm_status.json()
|
||||||
|
song_name = ytdm_statusJson["video"]["title"]
|
||||||
|
author = ytdm_statusJson["video"]["author"]
|
||||||
|
videoProgress = int(ytdm_statusJson["player"]["videoProgress"])
|
||||||
|
duration = int(ytdm_statusJson["video"]["durationSeconds"])
|
||||||
|
ads = bool(ytdm_statusJson["player"]["adPlaying"])
|
||||||
|
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{ads}"
|
||||||
|
print(formattedData)
|
||||||
|
await asyncio.sleep(5)
|
||||||
|
if appVer == "3":
|
||||||
|
eddyStatus = requests.get(eddy_statusUrl)
|
||||||
|
eddyStatusJson = eddyStatus.json()
|
||||||
|
song_name = eddyStatusJson["item"]["title"]
|
||||||
|
authorNames = eddyStatusJson.get("item", {}).get("artists", {})
|
||||||
|
authorNameList = [names['name'] for names in authorNames]
|
||||||
|
if len(authorNameList) == 1:
|
||||||
|
author = authorNameList[0]
|
||||||
|
print(author)
|
||||||
|
elif len(authorNameList)== 2:
|
||||||
|
author = (" & ".join(authorNameList))
|
||||||
|
print(author)
|
||||||
|
else:
|
||||||
|
author = (", ".join(authorNameList[:-1]) + " & " + authorNameList[-1])
|
||||||
|
print(author)
|
||||||
|
author = author
|
||||||
|
videoProgress = int(eddyStatusJson["position"])
|
||||||
|
duration = int(eddyStatusJson["duration"])
|
||||||
|
ads = "false"
|
||||||
|
formattedData = f"{song_name} - {author}|{videoProgress}|{duration}|{ads}"
|
||||||
|
print(formattedData)
|
||||||
|
await asyncio.sleep(2)
|
||||||
for clients in wsClients:
|
for clients in wsClients:
|
||||||
try:
|
try:
|
||||||
await clients.send(formattedData)
|
await clients.send(formattedData)
|
||||||
except:
|
except:
|
||||||
print("ERROR ON SENDING MESSAGE! CLIENT DROPPED BEFORE RECIVING MESSAGE!")
|
print("ERROR ON SENDING MESSAGE! CLIENT DROPPED BEFORE RECIVING MESSAGE!")
|
||||||
await asyncio.sleep(5) # YTDM only allows clients to look at its API every 5 seconds, so it limits thch.
|
# 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)
|
||||||
# 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)
|
wsClients.remove(websocket)
|
||||||
# Also stupid me forgot to remove the client
|
|
||||||
print("Client disconnected")
|
print("Client disconnected")
|
||||||
|
|
||||||
async def websocketMain():
|
async def websocketMain():
|
||||||
|
|
@ -79,16 +98,21 @@ async def websocketMain():
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if(os.path.exists("key.json")):
|
if(os.path.exists("key.json")):
|
||||||
print("Skipping some stuff...")
|
print("Skipping some stuff...")
|
||||||
# If we find key.json, we load it into memory and execute the program
|
# TODO: If we find key.json, we load it into memory and execute the program
|
||||||
print("Hello World!")
|
print("Hello World!")
|
||||||
appVer = input("Please enter a number for the following:\n1. th-ch's YoutubeMusic\n2. YTMDesktop\n")
|
appVer = input("Please enter a number for the following:\n\n1. th-ch's YoutubeMusic\n2. YTMDesktop\n3. TIDAL via TIDALuna and eddyapi\n\nYour Choice: ")
|
||||||
if appVer == "1":
|
if appVer == "1":
|
||||||
print("ughh")
|
|
||||||
#thytm_status()
|
|
||||||
asyncio.run(websocketMain())
|
asyncio.run(websocketMain())
|
||||||
elif appVer == "2":
|
if appVer == "2":
|
||||||
print("yay")
|
ytdm_logic()
|
||||||
|
print("FOR THE TIME BEING: I haven't done the key implementation, so you must remove the companion and enable authorization again once you exit out of this program!")
|
||||||
asyncio.run(websocketMain())
|
asyncio.run(websocketMain())
|
||||||
|
if appVer == "3":
|
||||||
|
asyncio.run(websocketMain())
|
||||||
else:
|
else:
|
||||||
print("Who the fuck asked? Go to github and open an issue!") # Just thought this was funny - Jckl
|
print("This isn't a valid request... Go to github and open an issue!")
|
||||||
exit
|
exit
|
||||||
|
|
||||||
|
|
||||||
|
if appVer == "2":
|
||||||
|
ytmd.connect()
|
||||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
requests
|
||||||
|
websockets
|
||||||
|
ytmd-sdk
|
||||||
Loading…
Reference in a new issue