Skip to content

Commit

Permalink
Add lumiastream beta plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
th-ch committed Oct 6, 2023
1 parent 22acaf6 commit da9cb8e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const defaultConfig = {
},
'album-color-theme': {},
'ambient-mode': {},
'lumiastream': {},
// Disabled plugins
'shortcuts': {
enabled: false,
Expand Down
14 changes: 8 additions & 6 deletions menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type MenuTemplate = (Electron.MenuItemConstructorOptions | Electron.MenuI
// True only if in-app-menu was loaded on launch
const inAppMenuActive = config.plugins.isEnabled('in-app-menu');

const betaPlugins = ['crossfade', 'lumiastream'];

const pluginEnabledMenu = (plugin: string, label = '', hasSubmenu = false, refreshMenu: (() => void ) | undefined = undefined): Electron.MenuItemConstructorOptions => ({
label: label || plugin,
type: 'checkbox',
Expand Down Expand Up @@ -46,13 +48,13 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
label: 'Plugins',
submenu:
getAllPlugins().map((plugin) => {
let pluginLabel = plugin;
if (betaPlugins.includes(plugin)) {
pluginLabel += ' [beta]';
}

const pluginPath = path.join(__dirname, 'plugins', plugin, 'menu.js');
if (existsSync(pluginPath)) {
let pluginLabel = plugin;
if (pluginLabel === 'crossfade') {
pluginLabel = 'crossfade [beta]';
}

if (!config.plugins.isEnabled(plugin)) {
return pluginEnabledMenu(plugin, pluginLabel, true, refreshMenu);
}
Expand All @@ -71,7 +73,7 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
} satisfies Electron.MenuItemConstructorOptions;
}

return pluginEnabledMenu(plugin);
return pluginEnabledMenu(plugin, pluginLabel);
}),
},
{
Expand Down
82 changes: 82 additions & 0 deletions plugins/lumiastream/back.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { BrowserWindow , net } from 'electron';

import registerCallback from '../../providers/song-info';

const secToMilisec = (t?: number) => t ? Math.round(Number(t) * 1e3) : undefined;
const previousStatePaused = null;

type LumiaData = {
origin: string;
eventType: string;
url?: string;
videoId?: string;
playlistId?: string;
cover?: string|null;
cover_url?: string|null;
title?: string;
artists?: string[];
status?: string;
progress?: number;
duration?: number;
album_url?: string|null;
album?: string|null;
views?: number;
isPaused?: boolean;
}
const data: LumiaData = {
origin: 'youtubemusic',
eventType: 'switchSong',
};


const post = (data: LumiaData) => {
const port = 39231;
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
};
const url = `http://localhost:${port}/api/media`;

net.fetch(url, { method: 'POST', body: JSON.stringify({ token: 'lsmedia_ytmsI7812', data }), headers })
.catch((error: { code: number, errno: number }) => {
console.log(
`Error: '${
error.code || error.errno
}' - when trying to access lumiastream webserver at port ${port}`
);
});
};

export default (_: BrowserWindow) => {
registerCallback((songInfo) => {
if (!songInfo.title && !songInfo.artist) {
return;
}

if (previousStatePaused === null) {
data.eventType = 'switchSong';
} else if (previousStatePaused !== songInfo.isPaused) {
data.eventType = 'playPause';
}

data.duration = secToMilisec(songInfo.songDuration);
data.progress = secToMilisec(songInfo.elapsedSeconds);
data.url = songInfo.url;
data.videoId = songInfo.videoId;
data.playlistId = songInfo.playlistId;
data.cover = songInfo.imageSrc;
data.cover_url = songInfo.imageSrc;
data.album_url = songInfo.imageSrc;
data.title = songInfo.title;
data.artists = [songInfo.artist];
data.status = songInfo.isPaused ? 'stopped' : 'playing';
data.isPaused = songInfo.isPaused;
data.album = songInfo.album;
data.views = songInfo.views;
post(data);
});
};


0 comments on commit da9cb8e

Please sign in to comment.