mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Add lumiastream beta plugin
This commit is contained in:
@ -81,6 +81,7 @@ const defaultConfig = {
|
|||||||
},
|
},
|
||||||
'album-color-theme': {},
|
'album-color-theme': {},
|
||||||
'ambient-mode': {},
|
'ambient-mode': {},
|
||||||
|
'lumiastream': {},
|
||||||
// Disabled plugins
|
// Disabled plugins
|
||||||
'shortcuts': {
|
'shortcuts': {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|||||||
14
menu.ts
14
menu.ts
@ -16,6 +16,8 @@ export type MenuTemplate = (Electron.MenuItemConstructorOptions | Electron.MenuI
|
|||||||
// True only if in-app-menu was loaded on launch
|
// True only if in-app-menu was loaded on launch
|
||||||
const inAppMenuActive = config.plugins.isEnabled('in-app-menu');
|
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 => ({
|
const pluginEnabledMenu = (plugin: string, label = '', hasSubmenu = false, refreshMenu: (() => void ) | undefined = undefined): Electron.MenuItemConstructorOptions => ({
|
||||||
label: label || plugin,
|
label: label || plugin,
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
@ -46,13 +48,13 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
|
|||||||
label: 'Plugins',
|
label: 'Plugins',
|
||||||
submenu:
|
submenu:
|
||||||
getAllPlugins().map((plugin) => {
|
getAllPlugins().map((plugin) => {
|
||||||
|
let pluginLabel = plugin;
|
||||||
|
if (betaPlugins.includes(plugin)) {
|
||||||
|
pluginLabel += ' [beta]';
|
||||||
|
}
|
||||||
|
|
||||||
const pluginPath = path.join(__dirname, 'plugins', plugin, 'menu.js');
|
const pluginPath = path.join(__dirname, 'plugins', plugin, 'menu.js');
|
||||||
if (existsSync(pluginPath)) {
|
if (existsSync(pluginPath)) {
|
||||||
let pluginLabel = plugin;
|
|
||||||
if (pluginLabel === 'crossfade') {
|
|
||||||
pluginLabel = 'crossfade [beta]';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config.plugins.isEnabled(plugin)) {
|
if (!config.plugins.isEnabled(plugin)) {
|
||||||
return pluginEnabledMenu(plugin, pluginLabel, true, refreshMenu);
|
return pluginEnabledMenu(plugin, pluginLabel, true, refreshMenu);
|
||||||
}
|
}
|
||||||
@ -71,7 +73,7 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
|
|||||||
} satisfies Electron.MenuItemConstructorOptions;
|
} satisfies Electron.MenuItemConstructorOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pluginEnabledMenu(plugin);
|
return pluginEnabledMenu(plugin, pluginLabel);
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
82
plugins/lumiastream/back.ts
Normal file
82
plugins/lumiastream/back.ts
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user