mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-13 11:21:46 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e07cac2406 | |||
| fd97576611 | |||
| 6ab01056e0 | |||
| 4dcbd2e7f0 | |||
| b94d0d4e8b | |||
| 7b20b9339d | |||
| 4d4a1f038b | |||
| e5ec79e345 | |||
| f4fe5c2a58 | |||
| a5130c1d3f | |||
| 8ab2da0482 |
38
config/defaults.js
Normal file
38
config/defaults.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
const defaultConfig = {
|
||||||
|
"window-size": {
|
||||||
|
width: 1100,
|
||||||
|
height: 550,
|
||||||
|
},
|
||||||
|
url: "https://music.youtube.com",
|
||||||
|
options: {
|
||||||
|
tray: false,
|
||||||
|
appVisible: true,
|
||||||
|
autoUpdates: true,
|
||||||
|
hideMenu: false,
|
||||||
|
startAtLogin: false,
|
||||||
|
disableHardwareAcceleration: false,
|
||||||
|
restartOnConfigChanges: false,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
// Enabled plugins
|
||||||
|
navigation: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
shortcuts: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
adblocker: {
|
||||||
|
enabled: true,
|
||||||
|
cache: true,
|
||||||
|
additionalBlockLists: [], // Additional list of filters, e.g "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt"
|
||||||
|
},
|
||||||
|
// Disabled plugins
|
||||||
|
downloader: {
|
||||||
|
enabled: false,
|
||||||
|
ffmpegArgs: [], // e.g. ["-b:a", "192k"] for an audio bitrate of 192kb/s
|
||||||
|
downloadFolder: undefined, // Custom download folder (absolute path)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = defaultConfig;
|
||||||
21
config/index.js
Normal file
21
config/index.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
const plugins = require("./plugins");
|
||||||
|
const store = require("./store");
|
||||||
|
|
||||||
|
const set = (key, value) => {
|
||||||
|
store.set(key, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const get = (key) => {
|
||||||
|
return store.get(key);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
get,
|
||||||
|
set,
|
||||||
|
edit: () => store.openInEditor(),
|
||||||
|
watch: (cb) => {
|
||||||
|
store.onDidChange("options", cb);
|
||||||
|
store.onDidChange("plugins", cb);
|
||||||
|
},
|
||||||
|
plugins,
|
||||||
|
};
|
||||||
41
config/plugins.js
Normal file
41
config/plugins.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
const store = require("./store");
|
||||||
|
|
||||||
|
function getEnabled() {
|
||||||
|
const plugins = store.get("plugins");
|
||||||
|
const enabledPlugins = Object.entries(plugins).filter(([plugin, options]) =>
|
||||||
|
isEnabled(plugin)
|
||||||
|
);
|
||||||
|
return enabledPlugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEnabled(plugin) {
|
||||||
|
const pluginConfig = store.get("plugins")[plugin];
|
||||||
|
return pluginConfig !== undefined && pluginConfig.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setOptions(plugin, options) {
|
||||||
|
const plugins = store.get("plugins");
|
||||||
|
store.set("plugins", {
|
||||||
|
...plugins,
|
||||||
|
[plugin]: {
|
||||||
|
...plugins[plugin],
|
||||||
|
...options,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function enable(plugin) {
|
||||||
|
setOptions(plugin, { enabled: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function disable(plugin) {
|
||||||
|
setOptions(plugin, { enabled: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
isEnabled,
|
||||||
|
getEnabled,
|
||||||
|
enable,
|
||||||
|
disable,
|
||||||
|
setOptions,
|
||||||
|
};
|
||||||
40
config/store.js
Normal file
40
config/store.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
const Store = require("electron-store");
|
||||||
|
|
||||||
|
const defaults = require("./defaults");
|
||||||
|
|
||||||
|
const migrations = {
|
||||||
|
">=1.7.0": (store) => {
|
||||||
|
const enabledPlugins = store.get("plugins");
|
||||||
|
if (!Array.isArray(enabledPlugins)) {
|
||||||
|
console.warn("Plugins are not in array format, cannot migrate");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include custom options
|
||||||
|
const plugins = {
|
||||||
|
adblocker: {
|
||||||
|
enabled: true,
|
||||||
|
cache: true,
|
||||||
|
additionalBlockLists: [],
|
||||||
|
},
|
||||||
|
downloader: {
|
||||||
|
enabled: false,
|
||||||
|
ffmpegArgs: [], // e.g. ["-b:a", "192k"] for an audio bitrate of 192kb/s
|
||||||
|
downloadFolder: undefined, // Custom download folder (absolute path)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
enabledPlugins.forEach((enabledPlugin) => {
|
||||||
|
plugins[enabledPlugin] = {
|
||||||
|
...plugins[enabledPlugin],
|
||||||
|
enabled: true,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
store.set("plugins", plugins);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = new Store({
|
||||||
|
defaults,
|
||||||
|
clearInvalidConfig: false,
|
||||||
|
migrations,
|
||||||
|
});
|
||||||
55
index.js
55
index.js
@ -5,18 +5,8 @@ const electron = require("electron");
|
|||||||
const is = require("electron-is");
|
const is = require("electron-is");
|
||||||
const { autoUpdater } = require("electron-updater");
|
const { autoUpdater } = require("electron-updater");
|
||||||
|
|
||||||
|
const config = require("./config");
|
||||||
const { setApplicationMenu } = require("./menu");
|
const { setApplicationMenu } = require("./menu");
|
||||||
const {
|
|
||||||
autoUpdate,
|
|
||||||
disableHardwareAcceleration,
|
|
||||||
getEnabledPlugins,
|
|
||||||
hideMenu,
|
|
||||||
isAppVisible,
|
|
||||||
isTrayEnabled,
|
|
||||||
setOptions,
|
|
||||||
store,
|
|
||||||
startAtLogin,
|
|
||||||
} = require("./store");
|
|
||||||
const { fileExists, injectCSS } = require("./plugins/utils");
|
const { fileExists, injectCSS } = require("./plugins/utils");
|
||||||
const { isTesting } = require("./utils/testing");
|
const { isTesting } = require("./utils/testing");
|
||||||
const { setUpTray } = require("./tray");
|
const { setUpTray } = require("./tray");
|
||||||
@ -28,7 +18,7 @@ app.commandLine.appendSwitch(
|
|||||||
"--experimental-wasm-threads --experimental-wasm-bulk-memory"
|
"--experimental-wasm-threads --experimental-wasm-bulk-memory"
|
||||||
);
|
);
|
||||||
app.allowRendererProcessReuse = true; // https://github.com/electron/electron/issues/18397
|
app.allowRendererProcessReuse = true; // https://github.com/electron/electron/issues/18397
|
||||||
if (disableHardwareAcceleration()) {
|
if (config.get("options.disableHardwareAcceleration")) {
|
||||||
if (is.dev()) {
|
if (is.dev()) {
|
||||||
console.log("Disabling hardware acceleration");
|
console.log("Disabling hardware acceleration");
|
||||||
}
|
}
|
||||||
@ -64,19 +54,19 @@ function loadPlugins(win) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
getEnabledPlugins().forEach((plugin) => {
|
config.plugins.getEnabled().forEach(([plugin, options]) => {
|
||||||
console.log("Loaded plugin - " + plugin);
|
console.log("Loaded plugin - " + plugin);
|
||||||
const pluginPath = path.join(__dirname, "plugins", plugin, "back.js");
|
const pluginPath = path.join(__dirname, "plugins", plugin, "back.js");
|
||||||
fileExists(pluginPath, () => {
|
fileExists(pluginPath, () => {
|
||||||
const handle = require(pluginPath);
|
const handle = require(pluginPath);
|
||||||
handle(win);
|
handle(win, options);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMainWindow() {
|
function createMainWindow() {
|
||||||
const windowSize = store.get("window-size");
|
const windowSize = config.get("window-size");
|
||||||
const windowMaximized = store.get("window-maximized");
|
const windowMaximized = config.get("window-maximized");
|
||||||
|
|
||||||
const win = new electron.BrowserWindow({
|
const win = new electron.BrowserWindow({
|
||||||
icon: icon,
|
icon: icon,
|
||||||
@ -94,31 +84,34 @@ function createMainWindow() {
|
|||||||
},
|
},
|
||||||
frame: !is.macOS(),
|
frame: !is.macOS(),
|
||||||
titleBarStyle: is.macOS() ? "hiddenInset" : "default",
|
titleBarStyle: is.macOS() ? "hiddenInset" : "default",
|
||||||
autoHideMenuBar: hideMenu(),
|
autoHideMenuBar: config.get("options.hideMenu"),
|
||||||
});
|
});
|
||||||
if (windowMaximized) {
|
if (windowMaximized) {
|
||||||
win.maximize();
|
win.maximize();
|
||||||
}
|
}
|
||||||
|
|
||||||
win.webContents.loadURL(store.get("url"));
|
win.webContents.loadURL(config.get("url"));
|
||||||
win.on("closed", onClosed);
|
win.on("closed", onClosed);
|
||||||
|
|
||||||
win.on("move", () => {
|
win.on("move", () => {
|
||||||
let position = win.getPosition();
|
let position = win.getPosition();
|
||||||
store.set("window-position", { x: position[0], y: position[1] });
|
config.set("window-position", { x: position[0], y: position[1] });
|
||||||
});
|
});
|
||||||
|
|
||||||
win.on("resize", () => {
|
win.on("resize", () => {
|
||||||
const windowSize = win.getSize();
|
const windowSize = win.getSize();
|
||||||
|
|
||||||
store.set("window-maximized", win.isMaximized());
|
config.set("window-maximized", win.isMaximized());
|
||||||
if (!win.isMaximized()) {
|
if (!win.isMaximized()) {
|
||||||
store.set("window-size", { width: windowSize[0], height: windowSize[1] });
|
config.set("window-size", {
|
||||||
|
width: windowSize[0],
|
||||||
|
height: windowSize[1],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
win.once("ready-to-show", () => {
|
win.once("ready-to-show", () => {
|
||||||
if (isAppVisible()) {
|
if (config.get("options.appVisible")) {
|
||||||
win.show();
|
win.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -143,7 +136,7 @@ app.on("browser-window-created", (event, win) => {
|
|||||||
win.webContents.on("did-navigate-in-page", () => {
|
win.webContents.on("did-navigate-in-page", () => {
|
||||||
const url = win.webContents.getURL();
|
const url = win.webContents.getURL();
|
||||||
if (url.startsWith("https://music.youtube.com")) {
|
if (url.startsWith("https://music.youtube.com")) {
|
||||||
store.set("url", url);
|
config.set("url", url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -196,14 +189,20 @@ app.on("activate", () => {
|
|||||||
app.on("ready", () => {
|
app.on("ready", () => {
|
||||||
mainWindow = createMainWindow();
|
mainWindow = createMainWindow();
|
||||||
setApplicationMenu(mainWindow);
|
setApplicationMenu(mainWindow);
|
||||||
|
if (config.get("options.restartOnConfigChanges")) {
|
||||||
|
config.watch(() => {
|
||||||
|
app.relaunch();
|
||||||
|
app.exit();
|
||||||
|
});
|
||||||
|
}
|
||||||
setUpTray(app, mainWindow);
|
setUpTray(app, mainWindow);
|
||||||
|
|
||||||
// Autostart at login
|
// Autostart at login
|
||||||
app.setLoginItemSettings({
|
app.setLoginItemSettings({
|
||||||
openAtLogin: startAtLogin(),
|
openAtLogin: config.get("options.startAtLogin"),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!is.dev() && autoUpdate()) {
|
if (!is.dev() && config.get("options.autoUpdates")) {
|
||||||
autoUpdater.checkForUpdatesAndNotify();
|
autoUpdater.checkForUpdatesAndNotify();
|
||||||
autoUpdater.on("update-available", () => {
|
autoUpdater.on("update-available", () => {
|
||||||
const downloadLink =
|
const downloadLink =
|
||||||
@ -223,7 +222,7 @@ app.on("ready", () => {
|
|||||||
break;
|
break;
|
||||||
// Disable updates
|
// Disable updates
|
||||||
case 2:
|
case 2:
|
||||||
setOptions({ autoUpdates: false });
|
config.set("options.autoUpdates", false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -234,7 +233,7 @@ app.on("ready", () => {
|
|||||||
|
|
||||||
// Optimized for Mac OS X
|
// Optimized for Mac OS X
|
||||||
if (is.macOS()) {
|
if (is.macOS()) {
|
||||||
if (!isAppVisible()) {
|
if (!config.get("options.appVisible")) {
|
||||||
app.dock.hide();
|
app.dock.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,7 +243,7 @@ app.on("ready", () => {
|
|||||||
forceQuit = true;
|
forceQuit = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (is.macOS() || isTrayEnabled()) {
|
if (is.macOS() || config.get("options.tray")) {
|
||||||
mainWindow.on("close", (event) => {
|
mainWindow.on("close", (event) => {
|
||||||
// Hide the window instead of quitting (quit is available in tray options)
|
// Hide the window instead of quitting (quit is available in tray options)
|
||||||
if (!forceQuit) {
|
if (!forceQuit) {
|
||||||
|
|||||||
102
menu.js
102
menu.js
@ -2,36 +2,34 @@ const { app, Menu } = require("electron");
|
|||||||
const is = require("electron-is");
|
const is = require("electron-is");
|
||||||
|
|
||||||
const { getAllPlugins } = require("./plugins/utils");
|
const { getAllPlugins } = require("./plugins/utils");
|
||||||
const {
|
const config = require("./config");
|
||||||
isPluginEnabled,
|
|
||||||
enablePlugin,
|
|
||||||
disablePlugin,
|
|
||||||
autoUpdate,
|
|
||||||
hideMenu,
|
|
||||||
isAppVisible,
|
|
||||||
isTrayEnabled,
|
|
||||||
setOptions,
|
|
||||||
startAtLogin,
|
|
||||||
disableHardwareAcceleration,
|
|
||||||
} = require("./store");
|
|
||||||
|
|
||||||
const mainMenuTemplate = (win) => [
|
const mainMenuTemplate = (win) => [
|
||||||
{
|
{
|
||||||
label: "Plugins",
|
label: "Plugins",
|
||||||
submenu: getAllPlugins().map((plugin) => {
|
submenu: [
|
||||||
return {
|
...getAllPlugins().map((plugin) => {
|
||||||
label: plugin,
|
return {
|
||||||
type: "checkbox",
|
label: plugin,
|
||||||
checked: isPluginEnabled(plugin),
|
type: "checkbox",
|
||||||
click: (item) => {
|
checked: config.plugins.isEnabled(plugin),
|
||||||
if (item.checked) {
|
click: (item) => {
|
||||||
enablePlugin(plugin);
|
if (item.checked) {
|
||||||
} else {
|
config.plugins.enable(plugin);
|
||||||
disablePlugin(plugin);
|
} else {
|
||||||
}
|
config.plugins.disable(plugin);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
{ type: "separator" },
|
||||||
|
{
|
||||||
|
label: "Advanced options",
|
||||||
|
click: () => {
|
||||||
|
config.edit();
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
}),
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Options",
|
label: "Options",
|
||||||
@ -39,17 +37,25 @@ const mainMenuTemplate = (win) => [
|
|||||||
{
|
{
|
||||||
label: "Auto-update",
|
label: "Auto-update",
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: autoUpdate(),
|
checked: config.get("options.autoUpdates"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
setOptions({ autoUpdates: item.checked });
|
config.set("options.autoUpdates", item.checked);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Disable hardware acceleration",
|
label: "Disable hardware acceleration",
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: disableHardwareAcceleration(),
|
checked: config.get("options.disableHardwareAcceleration"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
setOptions({ disableHardwareAcceleration: item.checked });
|
config.set("options.disableHardwareAcceleration", item.checked);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Restart on config changes",
|
||||||
|
type: "checkbox",
|
||||||
|
checked: config.get("options.restartOnConfigChanges"),
|
||||||
|
click: (item) => {
|
||||||
|
config.set("options.restartOnConfigChanges", item.checked);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
...(is.windows() || is.linux()
|
...(is.windows() || is.linux()
|
||||||
@ -57,9 +63,9 @@ const mainMenuTemplate = (win) => [
|
|||||||
{
|
{
|
||||||
label: "Hide menu",
|
label: "Hide menu",
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: hideMenu(),
|
checked: config.get("options.hideMenu"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
setOptions({ hideMenu: item.checked });
|
config.set("options.hideMenu", item.checked);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -71,9 +77,9 @@ const mainMenuTemplate = (win) => [
|
|||||||
{
|
{
|
||||||
label: "Start at login",
|
label: "Start at login",
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: startAtLogin(),
|
checked: config.get("options.startAtLogin"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
setOptions({ startAtLogin: item.checked });
|
config.set("options.startAtLogin", item.checked);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -84,23 +90,35 @@ const mainMenuTemplate = (win) => [
|
|||||||
{
|
{
|
||||||
label: "Disabled",
|
label: "Disabled",
|
||||||
type: "radio",
|
type: "radio",
|
||||||
checked: !isTrayEnabled(),
|
checked: !config.get("options.tray"),
|
||||||
click: () => setOptions({ tray: false, appVisible: true }),
|
click: () => {
|
||||||
|
config.set("options.tray", false);
|
||||||
|
config.set("options.appVisible", true);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Enabled + app visible",
|
label: "Enabled + app visible",
|
||||||
type: "radio",
|
type: "radio",
|
||||||
checked: isTrayEnabled() && isAppVisible(),
|
checked:
|
||||||
click: () => setOptions({ tray: true, appVisible: true }),
|
config.get("options.tray") && config.get("options.appVisible"),
|
||||||
|
click: () => {
|
||||||
|
config.set("options.tray", true);
|
||||||
|
config.set("options.appVisible", true);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Enabled + app hidden",
|
label: "Enabled + app hidden",
|
||||||
type: "radio",
|
type: "radio",
|
||||||
checked: isTrayEnabled() && !isAppVisible(),
|
checked:
|
||||||
click: () => setOptions({ tray: true, appVisible: false }),
|
config.get("options.tray") && !config.get("options.appVisible"),
|
||||||
|
click: () => {
|
||||||
|
config.set("options.tray", true);
|
||||||
|
config.set("options.appVisible", false);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{ type: "separator" },
|
||||||
{
|
{
|
||||||
label: "Toggle DevTools",
|
label: "Toggle DevTools",
|
||||||
// Cannot use "toggleDevTools" role in MacOS
|
// Cannot use "toggleDevTools" role in MacOS
|
||||||
@ -114,6 +132,12 @@ const mainMenuTemplate = (win) => [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Advanced options",
|
||||||
|
click: () => {
|
||||||
|
config.edit();
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "youtube-music",
|
"name": "youtube-music",
|
||||||
"productName": "YouTube Music",
|
"productName": "YouTube Music",
|
||||||
"version": "1.6.5",
|
"version": "1.7.1",
|
||||||
"description": "YouTube Music Desktop App - including custom plugins",
|
"description": "YouTube Music Desktop App - including custom plugins",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "th-ch/youtube-music",
|
"repository": "th-ch/youtube-music",
|
||||||
|
|||||||
@ -1,2 +1,7 @@
|
|||||||
const { loadAdBlockerEngine } = require("./blocker");
|
const { loadAdBlockerEngine } = require("./blocker");
|
||||||
module.exports = (win) => loadAdBlockerEngine(win.webContents.session);
|
module.exports = (win, options) =>
|
||||||
|
loadAdBlockerEngine(
|
||||||
|
win.webContents.session,
|
||||||
|
options.cache,
|
||||||
|
options.additionalBlockLists
|
||||||
|
);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { promises } = require("fs"); // used for caching
|
const { existsSync, promises, unlinkSync } = require("fs"); // used for caching
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
|
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
|
||||||
@ -8,16 +8,28 @@ const SOURCES = [
|
|||||||
"https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt",
|
"https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt",
|
||||||
];
|
];
|
||||||
|
|
||||||
const loadAdBlockerEngine = (session = undefined) =>
|
const loadAdBlockerEngine = (
|
||||||
|
session = undefined,
|
||||||
|
cache = true,
|
||||||
|
additionalBlockLists = []
|
||||||
|
) => {
|
||||||
|
const adBlockerCache = path.resolve(__dirname, "ad-blocker-engine.bin");
|
||||||
|
if (!cache && existsSync(adBlockerCache)) {
|
||||||
|
unlinkSync(adBlockerCache);
|
||||||
|
}
|
||||||
|
const cachingOptions = cache
|
||||||
|
? {
|
||||||
|
path: adBlockerCache,
|
||||||
|
read: promises.readFile,
|
||||||
|
write: promises.writeFile,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
ElectronBlocker.fromLists(
|
ElectronBlocker.fromLists(
|
||||||
fetch,
|
fetch,
|
||||||
SOURCES,
|
[...SOURCES, ...additionalBlockLists],
|
||||||
{},
|
{},
|
||||||
{
|
cachingOptions
|
||||||
path: path.resolve(__dirname, "ad-blocker-engine.bin"),
|
|
||||||
read: promises.readFile,
|
|
||||||
write: promises.writeFile,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
.then((blocker) => {
|
.then((blocker) => {
|
||||||
if (session) {
|
if (session) {
|
||||||
@ -27,6 +39,7 @@ const loadAdBlockerEngine = (session = undefined) =>
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => console.log("Error loading adBlocker engine", err));
|
.catch((err) => console.log("Error loading adBlocker engine", err));
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = { loadAdBlockerEngine };
|
module.exports = { loadAdBlockerEngine };
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ let progress = null;
|
|||||||
const downloadButton = ElementFromFile(
|
const downloadButton = ElementFromFile(
|
||||||
templatePath(__dirname, "download.html")
|
templatePath(__dirname, "download.html")
|
||||||
);
|
);
|
||||||
|
let pluginOptions = {};
|
||||||
|
|
||||||
const observer = new MutationObserver((mutations, observer) => {
|
const observer = new MutationObserver((mutations, observer) => {
|
||||||
if (!menu) {
|
if (!menu) {
|
||||||
@ -43,11 +44,13 @@ global.download = () => {
|
|||||||
triggerAction(CHANNEL, ACTIONS.ERROR, error);
|
triggerAction(CHANNEL, ACTIONS.ERROR, error);
|
||||||
reinit();
|
reinit();
|
||||||
},
|
},
|
||||||
reinit
|
reinit,
|
||||||
|
pluginOptions
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function observeMenu() {
|
function observeMenu(options) {
|
||||||
|
pluginOptions = { ...pluginOptions, ...options };
|
||||||
observer.observe(document, {
|
observer.observe(document, {
|
||||||
childList: true,
|
childList: true,
|
||||||
subtree: true,
|
subtree: true,
|
||||||
|
|||||||
@ -19,7 +19,13 @@ const ffmpeg = createFFmpeg({
|
|||||||
progress: () => {}, // console.log,
|
progress: () => {}, // console.log,
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloadVideoToMP3 = (videoUrl, sendFeedback, sendError, reinit) => {
|
const downloadVideoToMP3 = (
|
||||||
|
videoUrl,
|
||||||
|
sendFeedback,
|
||||||
|
sendError,
|
||||||
|
reinit,
|
||||||
|
options
|
||||||
|
) => {
|
||||||
sendFeedback("Downloading…");
|
sendFeedback("Downloading…");
|
||||||
|
|
||||||
let videoName = "YouTube Music - Unknown title";
|
let videoName = "YouTube Music - Unknown title";
|
||||||
@ -54,11 +60,18 @@ const downloadVideoToMP3 = (videoUrl, sendFeedback, sendError, reinit) => {
|
|||||||
.on("error", sendError)
|
.on("error", sendError)
|
||||||
.on("end", () => {
|
.on("end", () => {
|
||||||
const buffer = Buffer.concat(chunks);
|
const buffer = Buffer.concat(chunks);
|
||||||
toMP3(videoName, buffer, sendFeedback, sendError, reinit);
|
toMP3(videoName, buffer, sendFeedback, sendError, reinit, options);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const toMP3 = async (videoName, buffer, sendFeedback, sendError, reinit) => {
|
const toMP3 = async (
|
||||||
|
videoName,
|
||||||
|
buffer,
|
||||||
|
sendFeedback,
|
||||||
|
sendError,
|
||||||
|
reinit,
|
||||||
|
options
|
||||||
|
) => {
|
||||||
const safeVideoName = randomBytes(32).toString("hex");
|
const safeVideoName = randomBytes(32).toString("hex");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -71,11 +84,17 @@ const toMP3 = async (videoName, buffer, sendFeedback, sendError, reinit) => {
|
|||||||
ffmpeg.FS("writeFile", safeVideoName, buffer);
|
ffmpeg.FS("writeFile", safeVideoName, buffer);
|
||||||
|
|
||||||
sendFeedback("Converting…");
|
sendFeedback("Converting…");
|
||||||
await ffmpeg.run("-i", safeVideoName, safeVideoName + ".mp3");
|
await ffmpeg.run(
|
||||||
|
"-i",
|
||||||
|
safeVideoName,
|
||||||
|
...options.ffmpegArgs,
|
||||||
|
safeVideoName + ".mp3"
|
||||||
|
);
|
||||||
|
|
||||||
|
const folder = options.downloadFolder || downloadsFolder();
|
||||||
const filename = filenamify(videoName + ".mp3", { replacement: "_" });
|
const filename = filenamify(videoName + ".mp3", { replacement: "_" });
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
join(downloadsFolder(), filename),
|
join(folder, filename),
|
||||||
ffmpeg.FS("readFile", safeVideoName + ".mp3")
|
ffmpeg.FS("readFile", safeVideoName + ".mp3")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
16
preload.js
16
preload.js
@ -2,31 +2,31 @@ const path = require("path");
|
|||||||
|
|
||||||
const { remote } = require("electron");
|
const { remote } = require("electron");
|
||||||
|
|
||||||
const { getEnabledPlugins, store } = require("./store");
|
const config = require("./config");
|
||||||
const { fileExists } = require("./plugins/utils");
|
const { fileExists } = require("./plugins/utils");
|
||||||
|
|
||||||
const plugins = getEnabledPlugins();
|
const plugins = config.plugins.getEnabled();
|
||||||
|
|
||||||
plugins.forEach(plugin => {
|
plugins.forEach(([plugin, options]) => {
|
||||||
const pluginPath = path.join(__dirname, "plugins", plugin, "actions.js");
|
const pluginPath = path.join(__dirname, "plugins", plugin, "actions.js");
|
||||||
fileExists(pluginPath, () => {
|
fileExists(pluginPath, () => {
|
||||||
const actions = require(pluginPath).global || {};
|
const actions = require(pluginPath).global || {};
|
||||||
Object.keys(actions).forEach(actionName => {
|
Object.keys(actions).forEach((actionName) => {
|
||||||
global[actionName] = actions[actionName];
|
global[actionName] = actions[actionName];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
plugins.forEach(plugin => {
|
plugins.forEach(([plugin, options]) => {
|
||||||
const pluginPath = path.join(__dirname, "plugins", plugin, "front.js");
|
const pluginPath = path.join(__dirname, "plugins", plugin, "front.js");
|
||||||
fileExists(pluginPath, () => {
|
fileExists(pluginPath, () => {
|
||||||
const run = require(pluginPath);
|
const run = require(pluginPath);
|
||||||
run();
|
run(options);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add action for reloading
|
// Add action for reloading
|
||||||
global.reload = () =>
|
global.reload = () =>
|
||||||
remote.getCurrentWindow().webContents.loadURL(store.get("url"));
|
remote.getCurrentWindow().webContents.loadURL(config.get("url"));
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,40 +0,0 @@
|
|||||||
const Store = require("electron-store");
|
|
||||||
const plugins = require("./plugins");
|
|
||||||
|
|
||||||
const store = new Store({
|
|
||||||
defaults: {
|
|
||||||
"window-size": {
|
|
||||||
width: 1100,
|
|
||||||
height: 550,
|
|
||||||
},
|
|
||||||
url: "https://music.youtube.com",
|
|
||||||
plugins: ["navigation", "shortcuts", "adblocker"],
|
|
||||||
options: {
|
|
||||||
tray: false,
|
|
||||||
appVisible: true,
|
|
||||||
autoUpdates: true,
|
|
||||||
hideMenu: false,
|
|
||||||
startAtLogin: false,
|
|
||||||
disableHardwareAcceleration: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
store: store,
|
|
||||||
// Plugins
|
|
||||||
isPluginEnabled: plugin => plugins.isEnabled(store, plugin),
|
|
||||||
getEnabledPlugins: () => plugins.getEnabledPlugins(store),
|
|
||||||
enablePlugin: plugin => plugins.enablePlugin(store, plugin),
|
|
||||||
disablePlugin: plugin => plugins.disablePlugin(store, plugin),
|
|
||||||
// Options
|
|
||||||
setOptions: options =>
|
|
||||||
store.set("options", { ...store.get("options"), ...options }),
|
|
||||||
isTrayEnabled: () => store.get("options.tray"),
|
|
||||||
isAppVisible: () => store.get("options.appVisible"),
|
|
||||||
autoUpdate: () => store.get("options.autoUpdates"),
|
|
||||||
hideMenu: () => store.get("options.hideMenu"),
|
|
||||||
startAtLogin: () => store.get("options.startAtLogin"),
|
|
||||||
disableHardwareAcceleration: () =>
|
|
||||||
store.get("options.disableHardwareAcceleration"),
|
|
||||||
};
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
function getEnabledPlugins(store) {
|
|
||||||
return store.get("plugins");
|
|
||||||
}
|
|
||||||
|
|
||||||
function isEnabled(store, plugin) {
|
|
||||||
return store.get("plugins").indexOf(plugin) > -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function enablePlugin(store, plugin) {
|
|
||||||
let plugins = getEnabledPlugins(store);
|
|
||||||
if (plugins.indexOf(plugin) === -1) {
|
|
||||||
plugins.push(plugin);
|
|
||||||
store.set("plugins", plugins);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function disablePlugin(store, plugin) {
|
|
||||||
let plugins = getEnabledPlugins(store);
|
|
||||||
let index = plugins.indexOf(plugin);
|
|
||||||
if (index > -1) {
|
|
||||||
plugins.splice(index, 1);
|
|
||||||
store.set("plugins", plugins);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
isEnabled : isEnabled,
|
|
||||||
getEnabledPlugins: getEnabledPlugins,
|
|
||||||
enablePlugin : enablePlugin,
|
|
||||||
disablePlugin : disablePlugin
|
|
||||||
};
|
|
||||||
4
tray.js
4
tray.js
@ -2,15 +2,15 @@ const path = require("path");
|
|||||||
|
|
||||||
const { Menu, nativeImage, Tray } = require("electron");
|
const { Menu, nativeImage, Tray } = require("electron");
|
||||||
|
|
||||||
|
const config = require("./config");
|
||||||
const { mainMenuTemplate } = require("./menu");
|
const { mainMenuTemplate } = require("./menu");
|
||||||
const { isTrayEnabled } = require("./store");
|
|
||||||
const { clickInYoutubeMusic } = require("./utils/youtube-music");
|
const { clickInYoutubeMusic } = require("./utils/youtube-music");
|
||||||
|
|
||||||
// Prevent tray being garbage collected
|
// Prevent tray being garbage collected
|
||||||
let tray;
|
let tray;
|
||||||
|
|
||||||
module.exports.setUpTray = (app, win) => {
|
module.exports.setUpTray = (app, win) => {
|
||||||
if (!isTrayEnabled()) {
|
if (!config.get("options.tray")) {
|
||||||
tray = undefined;
|
tray = undefined;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user