-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DEPRECATED] Feature: Adds integration of topik/youtube-music-obs-widget as plugin #1120
base: master
Are you sure you want to change the base?
Conversation
This looks extremely similar to https://github.com/th-ch/youtube-music/blob/master/plugins/tuna-obs/back.js Could you give a quick explanation why a new plugin is needed? |
I took some inspiration from tuna-obs because I'm not a Node.js developer. Tuna-obs sends requests to the OBS plugin itself, which means you have to install the OBS (and the OBS plugin) for the whole thing to work. However, my plugin works the opposite way. It creates a webserver and serves JSON data about the current song, so you don't need to install anything. Just open the plugin's webpage and it will work. You can add the webpage as a source to OBS. Additionally, my plugin has a different design. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: You should use a formatter on your code :^)
by @ArjixWasTaken Co-authored-by: Angelos Bouklis <[email protected]>
You are absolutely right, no idea why i didn't do that. I would do it in any other language :| ... Also thanks for pointing out wrong variable type. |
@topik |
If you are still interested, this may be helpful: https://github.com/th-ch/youtube-music/pull/2723/files |
One solution would be to fake compatibility with the ytmd API, and only implement the endpoints used, but do we want that? |
I will not be making a PR on this, because I do not really want it merged. import { createPlugin } from '@/utils';
import { t } from '@/i18n';
import { Hono } from 'hono';
import { logger } from 'hono/logger';
import { serve } from '@hono/node-server';
import { Server as SocketIO } from 'socket.io';
import registerCallback, { SongInfo } from '@/providers/song-info';
let server: ServerType | null = null;
const port = 9863;
export default createPlugin({
name: () => t('plugins.obs-widget.name'),
description: () => t('plugins.obs-widget.description'),
authors: ['ArjixWasTaken'],
restartNeeded: false,
backend: {
start() {
let songInfo: SongInfo | null = null;
const app = new Hono().use(logger());
app.use(async (ctx, next) => {
await next();
ctx.res.headers.set('Access-Control-Allow-Origin', '*');
});
app.options('/api/v1/*', async (ctx) => {
ctx.res.headers.set('Access-Control-Allow-Methods', 'GET, POST');
ctx.res.headers.set('Access-Control-Allow-Headers', 'Content-Type');
return ctx.text('');
});
app.post('/api/v1/auth/requestcode', async (ctx) => {
return ctx.json({ statusCode: 200, code: 'lmao' });
});
app.post('/api/v1/auth/request', async (ctx) => {
return ctx.json({ token: 'lmao' });
});
app.get('/api/v1/state', async (ctx) => {
return ctx.json({
player: {
trackState: songInfo ? (songInfo.isPaused ? 0 : 1) : -1,
volume: 1,
},
video: {
author: songInfo?.artist ?? '',
channelId: '',
title: songInfo?.title ?? '',
album: songInfo?.album,
albumId: null,
likeStatus: -1,
thumbnails: [
{
url: songInfo?.imageSrc,
width: 100,
height: 100,
},
],
durationSeconds: songInfo?.songDuration ?? 0,
id: songInfo?.videoId,
},
});
});
server = serve({ fetch: app.fetch, port });
const ws = new SocketIO(server, {
serveClient: false,
transports: ['websocket'],
});
ws.of('/api/v1/realtime').on('connection', (socket) => {
console.log('Connected to OBS');
});
registerCallback((info) => {
songInfo = info;
ws.of('/api/v1/realtime').emit('state-update', {
player: {
trackState: songInfo ? (songInfo.isPaused ? 0 : 1) : -1,
videoProgress: songInfo.elapsedSeconds,
volume: 1,
},
video: {
author: songInfo?.artist ?? '',
channelId: '',
title: songInfo?.title ?? '',
album: songInfo?.album,
albumId: null,
likeStatus: -1,
thumbnails: [
{
url: songInfo?.imageSrc,
width: 100,
height: 100,
},
],
durationSeconds: songInfo?.songDuration ?? 0,
id: songInfo?.videoId,
},
});
});
},
stop() {
server?.close();
server = null;
},
},
}); Honestly, I'd suggest we make our own realtime websocket using hono's websocket helper. PS: I did try faking socket.io compatibility, but their documentation doesn't explain shit, so I gave up and used their library. |
If there is an accessible endpoint, I can change the widget so it works with both programs, so there will be no authentication for https://github.com/th-ch/youtube-music/tree/master. The question is, who's gonna make the endpoint and how. PS: good job 😂 |
we do not currently have websockets, but the plugin here is the schema of the response, and here is the route I do see that having websockets would be useful, so enhancing the |
Then I can just use the plugin that already exists 🙂 I think that would be the easiest solution. |
you'll have to deal with authentication there as well 😔, although it is optional iirc |
since I'm invested in this topic already, leave it to me, I'll make a PR to your widget |
Hello,
I got a request to add a plugin for my obs widget so here it is.
Plugin makes a simple http server and give a info about current song in JSON. The JSON structure is the same as in other YT music software that is being used so the obs widget is compatible.
Feel free to rename the plugin.
Thanks