mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6901713036 | |||
| 1d5b2997bd | |||
| 572a023aaa | |||
| 9187f1e240 | |||
| df13d7d0f3 | |||
| 85228fd7d2 | |||
| 17ba071057 | |||
| d7df4d7d10 | |||
| 7aa970cebc | |||
| f08f003cf4 | |||
| 9f99eded9e | |||
| c512f13009 | |||
| b475f780ff | |||
| 2294102006 | |||
| d69a07d025 | |||
| 4f4995c20c | |||
| b6894dca29 | |||
| 73f14e581d | |||
| 2f2e64af4a | |||
| 5710307ddc | |||
| 52ba2dc9ff | |||
| 926b9fb5e6 | |||
| a6c9b3381a | |||
| 5dc13a4698 | |||
| a69085c591 | |||
| a22f7fed21 | |||
| 8b7045fb1b | |||
| efd1b92514 | |||
| 969f6d7bba | |||
| 4f7c92d6a0 | |||
| 24d4a50574 | |||
| 7693a3ba4a | |||
| 7ca4dc5c85 | |||
| 21ff09b605 | |||
| fbf4b3b8b5 | |||
| 5812eb0147 |
24
changelog.md
24
changelog.md
@ -2,8 +2,32 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
|
||||
|
||||
#### [v2.0.3](https://github.com/th-ch/youtube-music/compare/v2.0.2...v2.0.3)
|
||||
|
||||
- feat(discord): add `Hide GitHub link Button` [`#1293`](https://github.com/th-ch/youtube-music/pull/1293)
|
||||
- feat(deps): bundle `youtubei.js` (temporary solution) [`#1292`](https://github.com/th-ch/youtube-music/pull/1292)
|
||||
- fix(mpris): fixed an issue where MPRIS information was incorrect [`#1291`](https://github.com/th-ch/youtube-music/pull/1291)
|
||||
- fix(discord): fixed an issue where `timeChanged` was not being applied to Discord activities [`#1290`](https://github.com/th-ch/youtube-music/pull/1290)
|
||||
- Fix: typo in README [`#1286`](https://github.com/th-ch/youtube-music/pull/1286)
|
||||
- fix: chore(deps): update dependency @jellybrick/mpris-service to 2.1.4 (fix #971) [`#971`](https://github.com/th-ch/youtube-music/issues/971)
|
||||
- chore(deps): Bump `@cliqz/adblocker-electron` to 1.26.8 (fix #1269) [`#1269`](https://github.com/th-ch/youtube-music/issues/1269)
|
||||
- fix: missing icons taskbar-mediacontrol [`fbf4b3b`](https://github.com/th-ch/youtube-music/commit/fbf4b3b8b5e39c61975e67efc990c45f62de76d8)
|
||||
- remove: migration scripts [`52ba2dc`](https://github.com/th-ch/youtube-music/commit/52ba2dc9ffd8e235251d1279686f55e33b3fa3bb)
|
||||
- feat: add migration script [`926b9fb`](https://github.com/th-ch/youtube-music/commit/926b9fb5e6db69b69935ec5d7be9a76a84e54ceb)
|
||||
|
||||
#### [v2.0.2](https://github.com/th-ch/youtube-music/compare/v2.0.1...v2.0.2)
|
||||
|
||||
> 8 October 2023
|
||||
|
||||
- fix: discord-rpc [`#1278`](https://github.com/th-ch/youtube-music/pull/1278)
|
||||
- Bump version to 2.0.2 [`b5dbfaf`](https://github.com/th-ch/youtube-music/commit/b5dbfaf68691a546d72f5c1818fd3a44802eb0fa)
|
||||
- Merge pull request #1272 from th-ch/feat/resolves-1265 [`6b7fd5b`](https://github.com/th-ch/youtube-music/commit/6b7fd5ba630888de08004105179c059c6d93e028)
|
||||
- Merge pull request #1279 from th-ch/fix/1274 [`73a049a`](https://github.com/th-ch/youtube-music/commit/73a049a7bc5161f0d53c252cf510f1e2a6f6eeb3)
|
||||
|
||||
#### [v2.0.1](https://github.com/th-ch/youtube-music/compare/v2.0.0...v2.0.1)
|
||||
|
||||
> 8 October 2023
|
||||
|
||||
- Update changelog for v2.0.0 [`2d69dfd`](https://github.com/th-ch/youtube-music/commit/2d69dfd333c3223ecc7de13a0abc98fd99aa3a2b)
|
||||
- hotfix: hotfix for #1267 [`c002263`](https://github.com/th-ch/youtube-music/commit/c002263c3bdd51890b8ffb431283afb60405d8fe)
|
||||
- Bump version to 2.0.1 [`a1f025e`](https://github.com/th-ch/youtube-music/commit/a1f025e23c599fe5eb63b32ea38ee81200d232d6)
|
||||
|
||||
@ -74,7 +74,7 @@ const defaultConfig = {
|
||||
'adblocker': {
|
||||
enabled: true,
|
||||
cache: true,
|
||||
blocker: blockers.InPlayer as string,
|
||||
blocker: blockers.WithBlocklists as string,
|
||||
additionalBlockLists: [], // Additional list of filters, e.g "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt"
|
||||
disableDefaultLists: false,
|
||||
},
|
||||
@ -106,6 +106,7 @@ const defaultConfig = {
|
||||
activityTimoutEnabled: true, // If enabled, the discord rich presence gets cleared when music paused after the time specified below
|
||||
activityTimoutTime: 10 * 60 * 1000, // 10 minutes
|
||||
listenAlong: true, // Add a "listen along" button to rich presence
|
||||
hideGitHubButton: false, // Disable the "View App On GitHub" button
|
||||
hideDurationLeft: false, // Hides the start and end time of the song to rich presence
|
||||
},
|
||||
'downloader': {
|
||||
|
||||
37
index.ts
37
index.ts
@ -1,16 +1,14 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { BrowserWindow, app, screen, globalShortcut, session, shell, dialog, ipcMain } from 'electron';
|
||||
import enhanceWebRequest from 'electron-better-web-request';
|
||||
import enhanceWebRequest, { BetterSession } from '@jellybrick/electron-better-web-request';
|
||||
import is from 'electron-is';
|
||||
import unhandled from 'electron-unhandled';
|
||||
import { autoUpdater } from 'electron-updater';
|
||||
import electronDebug from 'electron-debug';
|
||||
|
||||
import { BetterWebRequest } from 'electron-better-web-request/lib/electron-better-web-request';
|
||||
|
||||
import config from './config';
|
||||
import { setApplicationMenu } from './menu';
|
||||
import { refreshMenu, setApplicationMenu } from './menu';
|
||||
import { fileExists, injectCSS, injectCSSAsFile } from './plugins/utils';
|
||||
import { isTesting } from './utils/testing';
|
||||
import { setUpTray } from './tray';
|
||||
@ -144,7 +142,7 @@ if (is.windows()) {
|
||||
|
||||
ipcMain.handle('get-main-plugin-names', () => Object.keys(mainPlugins));
|
||||
|
||||
function loadPlugins(win: BrowserWindow) {
|
||||
async function loadPlugins(win: BrowserWindow) {
|
||||
injectCSS(win.webContents, youtubeMusicCSS);
|
||||
// Load user CSS
|
||||
const themes: string[] = config.get('options.themes');
|
||||
@ -175,7 +173,7 @@ function loadPlugins(win: BrowserWindow) {
|
||||
console.log('Loaded plugin - ' + plugin);
|
||||
const handler = mainPlugins[plugin as keyof typeof mainPlugins];
|
||||
if (handler) {
|
||||
handler(win, options as never);
|
||||
await handler(win, options as never);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@ -184,7 +182,7 @@ function loadPlugins(win: BrowserWindow) {
|
||||
}
|
||||
}
|
||||
|
||||
function createMainWindow() {
|
||||
async function createMainWindow() {
|
||||
const windowSize = config.get('window-size');
|
||||
const windowMaximized = config.get('window-maximized');
|
||||
const windowPosition: Electron.Point = config.get('window-position');
|
||||
@ -223,7 +221,7 @@ function createMainWindow() {
|
||||
: 'default'),
|
||||
autoHideMenuBar: config.get('options.hideMenu'),
|
||||
});
|
||||
loadPlugins(win);
|
||||
await loadPlugins(win);
|
||||
|
||||
if (windowPosition) {
|
||||
const { x: windowX, y: windowY } = windowPosition;
|
||||
@ -258,7 +256,6 @@ function createMainWindow() {
|
||||
const urlToLoad = config.get('options.resumeOnStart')
|
||||
? config.get('url')
|
||||
: config.defaultConfig.url;
|
||||
win.webContents.loadURL(urlToLoad);
|
||||
win.on('closed', onClosed);
|
||||
|
||||
type PiPOptions = typeof config.defaultConfig.plugins['picture-in-picture'];
|
||||
@ -338,6 +335,8 @@ function createMainWindow() {
|
||||
|
||||
removeContentSecurityPolicy();
|
||||
|
||||
win.webContents.loadURL(urlToLoad);
|
||||
|
||||
return win;
|
||||
}
|
||||
|
||||
@ -394,7 +393,7 @@ app.once('browser-window-created', (event, win) => {
|
||||
console.log(log);
|
||||
}
|
||||
|
||||
if (!(config.plugins.isEnabled('in-app-menu') && errorCode === -3)) { // -3 is a false positive with in-app-menu
|
||||
if (errorCode !== -3) { // -3 is a false positive
|
||||
win.webContents.send('log', log);
|
||||
win.webContents.loadFile(path.join(__dirname, 'error.html'));
|
||||
}
|
||||
@ -414,17 +413,17 @@ app.on('window-all-closed', () => {
|
||||
globalShortcut.unregisterAll();
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
app.on('activate', async () => {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (mainWindow === null) {
|
||||
mainWindow = createMainWindow();
|
||||
mainWindow = await createMainWindow();
|
||||
} else if (!mainWindow.isVisible()) {
|
||||
mainWindow.show();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('ready', () => {
|
||||
app.on('ready', async () => {
|
||||
if (config.get('options.autoResetAppCache')) {
|
||||
// Clear cache after 20s
|
||||
const clearCacheTimeout = setTimeout(() => {
|
||||
@ -469,8 +468,9 @@ app.on('ready', () => {
|
||||
}
|
||||
}
|
||||
|
||||
mainWindow = createMainWindow();
|
||||
mainWindow = await createMainWindow();
|
||||
setApplicationMenu(mainWindow);
|
||||
refreshMenu(mainWindow);
|
||||
setUpTray(app, mainWindow);
|
||||
|
||||
setupProtocolHandler(mainWindow);
|
||||
@ -602,8 +602,6 @@ function showUnresponsiveDialog(win: BrowserWindow, details: Electron.RenderProc
|
||||
});
|
||||
}
|
||||
|
||||
// HACK: electron-better-web-request's typing is wrong
|
||||
type BetterSession = Omit<Electron.Session, 'webRequest'> & { webRequest: BetterWebRequest & Electron.WebRequest };
|
||||
function removeContentSecurityPolicy(
|
||||
betterSession: BetterSession = session.defaultSession as BetterSession,
|
||||
) {
|
||||
@ -623,11 +621,10 @@ function removeContentSecurityPolicy(
|
||||
callback({ cancel: false, responseHeaders: details.responseHeaders });
|
||||
});
|
||||
|
||||
type ResolverListener = { apply: () => Promise<Record<string, unknown>>; context: unknown };
|
||||
// When multiple listeners are defined, apply them all
|
||||
betterSession.webRequest.setResolver('onHeadersReceived', async (listeners: ResolverListener[]) => {
|
||||
return listeners.reduce<Promise<Record<string, unknown>>>(
|
||||
async (accumulator: Promise<Record<string, unknown>>, listener: ResolverListener) => {
|
||||
betterSession.webRequest.setResolver('onHeadersReceived', async (listeners) => {
|
||||
return listeners.reduce(
|
||||
async (accumulator, listener) => {
|
||||
const acc = await accumulator;
|
||||
if (acc.cancel) {
|
||||
return acc;
|
||||
|
||||
20
menu.ts
20
menu.ts
@ -62,13 +62,15 @@ const pluginEnabledMenu = (plugin: string, label = '', hasSubmenu = false, refre
|
||||
},
|
||||
});
|
||||
|
||||
export const refreshMenu = (win: BrowserWindow) => {
|
||||
setApplicationMenu(win);
|
||||
if (inAppMenuActive) {
|
||||
win.webContents.send('refreshMenu');
|
||||
}
|
||||
};
|
||||
|
||||
export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
|
||||
const refreshMenu = () => {
|
||||
setApplicationMenu(win);
|
||||
if (inAppMenuActive) {
|
||||
win.webContents.send('refreshMenu');
|
||||
}
|
||||
};
|
||||
const innerRefreshMenu = () => refreshMenu(win);
|
||||
|
||||
return [
|
||||
{
|
||||
@ -84,15 +86,15 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
|
||||
const getPluginMenu = pluginMenus[pluginName as keyof typeof pluginMenus];
|
||||
|
||||
if (!config.plugins.isEnabled(pluginName)) {
|
||||
return pluginEnabledMenu(pluginName, pluginLabel, true, refreshMenu);
|
||||
return pluginEnabledMenu(pluginName, pluginLabel, true, innerRefreshMenu);
|
||||
}
|
||||
|
||||
return {
|
||||
label: pluginLabel,
|
||||
submenu: [
|
||||
pluginEnabledMenu(pluginName, 'Enabled', true, refreshMenu),
|
||||
pluginEnabledMenu(pluginName, 'Enabled', true, innerRefreshMenu),
|
||||
{ type: 'separator' },
|
||||
...getPluginMenu(win, config.plugins.getOptions(pluginName), refreshMenu),
|
||||
...getPluginMenu(win, config.plugins.getOptions(pluginName), innerRefreshMenu),
|
||||
],
|
||||
} satisfies Electron.MenuItemConstructorOptions;
|
||||
}
|
||||
|
||||
822
package-lock.json
generated
822
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
48
package.json
48
package.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "youtube-music",
|
||||
"productName": "YouTube Music",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.4",
|
||||
"description": "YouTube Music Desktop App - including custom plugins",
|
||||
"main": "./dist/index.js",
|
||||
"license": "MIT",
|
||||
@ -20,24 +20,7 @@
|
||||
"license",
|
||||
"!node_modules",
|
||||
"node_modules/custom-electron-prompt/**",
|
||||
"node_modules/youtubei.js/**",
|
||||
"node_modules/undici/**",
|
||||
"node_modules/@fastify/busboy/**",
|
||||
"node_modules/jintr/**",
|
||||
"node_modules/acorn/**",
|
||||
"node_modules/tslib/**",
|
||||
"node_modules/semver/**",
|
||||
"node_modules/lru-cache/**",
|
||||
"node_modules/detect-libc/**",
|
||||
"node_modules/color/**",
|
||||
"node_modules/color-convert/**",
|
||||
"node_modules/color-string/**",
|
||||
"node_modules/color-name/**",
|
||||
"node_modules/simple-swizzle/**",
|
||||
"node_modules/is-arrayish/**",
|
||||
"node_modules/@cliqz/adblocker-electron-preload/**",
|
||||
"node_modules/@cliqz/adblocker-content/**",
|
||||
"node_modules/@cliqz/adblocker-extended-selectors/**",
|
||||
"node_modules/@ffmpeg.wasm/core-mt/**",
|
||||
"!node_modules/**/*.map",
|
||||
"!node_modules/**/*.ts"
|
||||
@ -111,8 +94,7 @@
|
||||
"build": "npm run rollup:preload && npm run rollup:main",
|
||||
"start": "npm run build && electron ./dist/index.js",
|
||||
"start:debug": "ELECTRON_ENABLE_LOGGING=1 npm run start",
|
||||
"generate:package": "node utils/generate-package-json.js",
|
||||
"postinstall": "npm run plugins && npm run clean",
|
||||
"postinstall": "patch-package",
|
||||
"clean": "del-cli dist && del-cli pack",
|
||||
"dist": "npm run clean && npm run build && electron-builder --win --mac --linux -p never",
|
||||
"dist:linux": "npm run clean && npm run build && electron-builder --linux -p never",
|
||||
@ -122,8 +104,6 @@
|
||||
"dist:win:x64": "npm run clean && npm run build && electron-builder --win nsis-web:x64 -p never",
|
||||
"lint": "eslint .",
|
||||
"changelog": "auto-changelog",
|
||||
"plugins": "npm run plugin:bypass-age-restrictions",
|
||||
"plugin:bypass-age-restrictions": "del-cli node_modules/simple-youtube-age-restriction-bypass/package.json && npm run generate:package simple-youtube-age-restriction-bypass",
|
||||
"release:linux": "npm run clean && npm run build && electron-builder --linux -p always -c.snap.publish=github",
|
||||
"release:mac": "npm run clean && npm run build && electron-builder --mac -p always",
|
||||
"release:win": "npm run clean && npm run build && electron-builder --win -p always",
|
||||
@ -133,17 +113,18 @@
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cliqz/adblocker-electron": "1.26.7",
|
||||
"@cliqz/adblocker-electron": "1.26.8",
|
||||
"@ffmpeg.wasm/core-mt": "0.12.0",
|
||||
"@ffmpeg.wasm/main": "0.12.0",
|
||||
"@foobar404/wave": "2.0.4",
|
||||
"@jellybrick/electron-better-web-request": "1.0.4",
|
||||
"@jellybrick/mpris-service": "2.1.4",
|
||||
"@xhayper/discord-rpc": "1.0.23",
|
||||
"async-mutex": "0.4.0",
|
||||
"butterchurn": "2.6.7",
|
||||
"butterchurn-presets": "2.4.7",
|
||||
"butterchurn": "3.0.0-beta.4",
|
||||
"butterchurn-presets": "3.0.0-beta.4",
|
||||
"conf": "10.2.0",
|
||||
"custom-electron-prompt": "1.5.7",
|
||||
"electron-better-web-request": "1.0.1",
|
||||
"electron-debug": "3.2.0",
|
||||
"electron-is": "3.0.0",
|
||||
"electron-localshortcut": "3.2.1",
|
||||
@ -156,9 +137,8 @@
|
||||
"html-to-text": "9.0.5",
|
||||
"keyboardevent-from-electron-accelerator": "2.0.0",
|
||||
"keyboardevents-areequal": "0.2.2",
|
||||
"mpris-service": "2.1.2",
|
||||
"node-id3": "0.2.6",
|
||||
"simple-youtube-age-restriction-bypass": "git+https://github.com/MiepHD/Simple-YouTube-Age-Restriction-Bypass.git#v2.5.5",
|
||||
"simple-youtube-age-restriction-bypass": "git+https://github.com/organization/Simple-YouTube-Age-Restriction-Bypass.git#v2.5.8",
|
||||
"vudio": "2.1.1",
|
||||
"x11": "2.3.0",
|
||||
"youtubei.js": "6.4.1",
|
||||
@ -168,17 +148,16 @@
|
||||
"rollup": "4.0.2",
|
||||
"node-gyp": "9.4.0",
|
||||
"xml2js": "0.6.2",
|
||||
"dbus-next": "0.10.2",
|
||||
"node-fetch": "2.7.0",
|
||||
"@electron/universal": "1.4.2",
|
||||
"electron": "27.0.0-beta.9"
|
||||
"@babel/runtime": "7.23.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "1.38.1",
|
||||
"@rollup/plugin-commonjs": "25.0.5",
|
||||
"@rollup/plugin-image": "3.0.3",
|
||||
"@rollup/plugin-json": "6.0.1",
|
||||
"@rollup/plugin-node-resolve": "15.2.2",
|
||||
"@rollup/plugin-node-resolve": "15.2.3",
|
||||
"@rollup/plugin-terser": "0.4.4",
|
||||
"@rollup/plugin-typescript": "11.1.5",
|
||||
"@rollup/plugin-wasm": "6.2.2",
|
||||
@ -186,16 +165,17 @@
|
||||
"@types/electron-localshortcut": "3.1.1",
|
||||
"@types/howler": "2.2.9",
|
||||
"@types/html-to-text": "9.0.2",
|
||||
"@typescript-eslint/eslint-plugin": "6.7.4",
|
||||
"@typescript-eslint/eslint-plugin": "6.7.5",
|
||||
"auto-changelog": "2.4.0",
|
||||
"del-cli": "5.1.0",
|
||||
"electron": "27.0.0-beta.9",
|
||||
"electron": "27.0.0",
|
||||
"electron-builder": "24.6.4",
|
||||
"electron-devtools-installer": "3.2.0",
|
||||
"eslint": "8.51.0",
|
||||
"eslint-plugin-import": "2.28.1",
|
||||
"eslint-plugin-prettier": "5.0.0",
|
||||
"eslint-plugin-prettier": "5.0.1",
|
||||
"node-gyp": "9.4.0",
|
||||
"patch-package": "8.0.0",
|
||||
"playwright": "1.38.1",
|
||||
"rollup": "4.0.2",
|
||||
"rollup-plugin-copy": "3.5.0",
|
||||
|
||||
38
patches/youtubei.js+6.4.1.patch
Normal file
38
patches/youtubei.js+6.4.1.patch
Normal file
@ -0,0 +1,38 @@
|
||||
diff --git a/node_modules/youtubei.js/bundle/node.cjs b/node_modules/youtubei.js/bundle/node.cjs
|
||||
index 7e3072e..bf5be6a 100644
|
||||
--- a/node_modules/youtubei.js/bundle/node.cjs
|
||||
+++ b/node_modules/youtubei.js/bundle/node.cjs
|
||||
@@ -16969,7 +16969,13 @@ var _Cache_createCache;
|
||||
var meta_url = import_meta.url;
|
||||
var is_cjs = !meta_url;
|
||||
var __dirname__ = is_cjs ? __dirname : import_path.default.dirname((0, import_url.fileURLToPath)(meta_url));
|
||||
-var package_json = JSON.parse((0, import_fs.readFileSync)(import_path.default.resolve(__dirname__, is_cjs ? "../package.json" : "../../package.json"), "utf-8"));
|
||||
+var package_json = {
|
||||
+ homepage: "https://github.com/LuanRT/YouTube.js#readme",
|
||||
+ version: "6.4.1",
|
||||
+ bugs: {
|
||||
+ url: "https://github.com/LuanRT/YouTube.js/issues"
|
||||
+ }
|
||||
+};
|
||||
var repo_url = (_a3 = package_json.homepage) === null || _a3 === void 0 ? void 0 : _a3.split("#")[0];
|
||||
var Cache = class {
|
||||
constructor(persistent = false, persistent_directory) {
|
||||
diff --git a/node_modules/youtubei.js/dist/src/platform/node.js b/node_modules/youtubei.js/dist/src/platform/node.js
|
||||
index 0e1b2ca..17b437c 100644
|
||||
--- a/node_modules/youtubei.js/dist/src/platform/node.js
|
||||
+++ b/node_modules/youtubei.js/dist/src/platform/node.js
|
||||
@@ -16,7 +16,13 @@ import evaluate from './jsruntime/jinter.js';
|
||||
const meta_url = import.meta.url;
|
||||
const is_cjs = !meta_url;
|
||||
const __dirname__ = is_cjs ? __dirname : path.dirname(fileURLToPath(meta_url));
|
||||
-const package_json = JSON.parse(readFileSync(path.resolve(__dirname__, is_cjs ? '../package.json' : '../../package.json'), 'utf-8'));
|
||||
+const package_json = {
|
||||
+ homepage: "https://github.com/LuanRT/YouTube.js#readme",
|
||||
+ version: "6.4.1",
|
||||
+ bugs: {
|
||||
+ url: "https://github.com/LuanRT/YouTube.js/issues"
|
||||
+ }
|
||||
+};
|
||||
const repo_url = (_a = package_json.homepage) === null || _a === void 0 ? void 0 : _a.split('#')[0];
|
||||
class Cache {
|
||||
constructor(persistent = false, persistent_directory) {
|
||||
@ -8,8 +8,8 @@ import type { ConfigType } from '../../config/dynamic';
|
||||
type AdBlockOptions = ConfigType<'adblocker'>;
|
||||
|
||||
export default async (win: BrowserWindow, options: AdBlockOptions) => {
|
||||
if (await shouldUseBlocklists()) {
|
||||
loadAdBlockerEngine(
|
||||
if (shouldUseBlocklists()) {
|
||||
await loadAdBlockerEngine(
|
||||
win.webContents.session,
|
||||
options.cache,
|
||||
options.additionalBlockLists,
|
||||
|
||||
@ -3,7 +3,7 @@ import path from 'node:path';
|
||||
import fs, { promises } from 'node:fs';
|
||||
|
||||
import { ElectronBlocker } from '@cliqz/adblocker-electron';
|
||||
import { app } from 'electron';
|
||||
import { app, net } from 'electron';
|
||||
|
||||
const SOURCES = [
|
||||
'https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt',
|
||||
@ -17,7 +17,7 @@ const SOURCES = [
|
||||
'https://secure.fanboy.co.nz/fanboy-annoyance_ubo.txt',
|
||||
];
|
||||
|
||||
export const loadAdBlockerEngine = (
|
||||
export const loadAdBlockerEngine = async (
|
||||
session: Electron.Session | undefined = undefined,
|
||||
cache = true,
|
||||
additionalBlockLists = [],
|
||||
@ -49,25 +49,24 @@ export const loadAdBlockerEngine = (
|
||||
...additionalBlockLists,
|
||||
];
|
||||
|
||||
ElectronBlocker.fromLists(
|
||||
fetch,
|
||||
lists,
|
||||
{
|
||||
// When generating the engine for caching, do not load network filters
|
||||
// So that enhancing the session works as expected
|
||||
// Allowing to define multiple webRequest listeners
|
||||
loadNetworkFilters: session !== undefined,
|
||||
},
|
||||
cachingOptions,
|
||||
)
|
||||
.then((blocker) => {
|
||||
if (session) {
|
||||
blocker.enableBlockingInSession(session);
|
||||
} else {
|
||||
console.log('Successfully generated adBlocker engine.');
|
||||
}
|
||||
})
|
||||
.catch((error) => console.log('Error loading adBlocker engine', error));
|
||||
try {
|
||||
const blocker = await ElectronBlocker.fromLists(
|
||||
(url: string) => net.fetch(url),
|
||||
lists,
|
||||
{
|
||||
// When generating the engine for caching, do not load network filters
|
||||
// So that enhancing the session works as expected
|
||||
// Allowing to define multiple webRequest listeners
|
||||
loadNetworkFilters: session !== undefined,
|
||||
},
|
||||
cachingOptions,
|
||||
);
|
||||
if (session) {
|
||||
blocker.enableBlockingInSession(session);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('Error loading adBlocker engine', error);
|
||||
}
|
||||
};
|
||||
|
||||
export default { loadAdBlockerEngine };
|
||||
|
||||
@ -7,7 +7,7 @@ import { PluginConfig } from '../../config/dynamic';
|
||||
|
||||
const config = new PluginConfig('adblocker', { enableFront: true });
|
||||
|
||||
export const shouldUseBlocklists = async () => await config.get('blocker') !== blockers.InPlayer;
|
||||
export const shouldUseBlocklists = () => config.get('blocker') !== blockers.InPlayer;
|
||||
|
||||
export default Object.assign(config, {
|
||||
shouldUseBlocklists,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
export default () => {
|
||||
const path = '@cliqz/adblocker-electron-preload'; // prevent require hoisting
|
||||
require(path);
|
||||
export default async () => {
|
||||
await import('@cliqz/adblocker-electron-preload');
|
||||
};
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import config from './config';
|
||||
import config, { shouldUseBlocklists } from './config';
|
||||
import inject from './inject';
|
||||
import injectCliqzPreload from './inject-cliqz-preload';
|
||||
|
||||
import { blockers } from './blocker-types';
|
||||
|
||||
export default async () => {
|
||||
if (await config.shouldUseBlocklists()) {
|
||||
if (shouldUseBlocklists()) {
|
||||
// Preload adblocker to inject scripts/styles
|
||||
injectCliqzPreload();
|
||||
await injectCliqzPreload();
|
||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||
} else if ((await config.get('blocker')) === blockers.InPlayer) {
|
||||
} else if ((config.get('blocker')) === blockers.InPlayer) {
|
||||
inject();
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export default () => {
|
||||
export default async () => {
|
||||
// See https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass#userscript
|
||||
require('simple-youtube-age-restriction-bypass/dist/Simple-YouTube-Age-Restriction-Bypass.user.js');
|
||||
await import('simple-youtube-age-restriction-bypass');
|
||||
};
|
||||
|
||||
4
plugins/bypass-age-restrictions/simple-youtube-age-restriction-bypass.d.ts
vendored
Normal file
4
plugins/bypass-age-restrictions/simple-youtube-age-restriction-bypass.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
declare module 'simple-youtube-age-restriction-bypass' {
|
||||
const nothing: never;
|
||||
export default nothing;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
import { app, dialog } from 'electron';
|
||||
import { app, dialog, ipcMain } from 'electron';
|
||||
import { Client as DiscordClient } from '@xhayper/discord-rpc';
|
||||
import { dev } from 'electron-is';
|
||||
|
||||
@ -163,7 +163,7 @@ export default (
|
||||
largeImageText: songInfo.album ?? '',
|
||||
buttons: [
|
||||
...(options.listenAlong ? [{ label: 'Listen Along', url: songInfo.url ?? '' }] : []),
|
||||
{ label: 'View App On GitHub', url: 'https://github.com/th-ch/youtube-music' },
|
||||
...(options.hideGitHubButton ? [] : [{ label: 'View App On GitHub', url: 'https://github.com/th-ch/youtube-music' }]),
|
||||
],
|
||||
};
|
||||
|
||||
@ -188,8 +188,22 @@ export default (
|
||||
|
||||
// If the page is ready, register the callback
|
||||
win.once('ready-to-show', () => {
|
||||
registerCallback(updateActivity);
|
||||
let lastSongInfo: SongInfo;
|
||||
registerCallback((songInfo) => {
|
||||
lastSongInfo = songInfo;
|
||||
updateActivity(songInfo);
|
||||
});
|
||||
connect();
|
||||
let lastSent = Date.now();
|
||||
ipcMain.on('timeChanged', (_, t: number) => {
|
||||
const currentTime = Date.now();
|
||||
// if lastSent is more than 5 seconds ago, send the new time
|
||||
if (currentTime - lastSent > 5000) {
|
||||
lastSent = currentTime;
|
||||
lastSongInfo.elapsedSeconds = t;
|
||||
updateActivity(lastSongInfo);
|
||||
}
|
||||
});
|
||||
});
|
||||
app.on('window-all-closed', clear);
|
||||
};
|
||||
|
||||
@ -55,6 +55,15 @@ export default (win: Electron.BrowserWindow, options: DiscordOptions, refreshMen
|
||||
setMenuOptions('discord', options);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Hide GitHub link Button',
|
||||
type: 'checkbox',
|
||||
checked: options.hideGitHubButton,
|
||||
click(item: Electron.MenuItem) {
|
||||
options.hideGitHubButton = item.checked;
|
||||
setMenuOptions('discord', options);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Hide duration left',
|
||||
type: 'checkbox',
|
||||
|
||||
@ -3,23 +3,14 @@ import { join } from 'node:path';
|
||||
import { randomBytes } from 'node:crypto';
|
||||
|
||||
import { app, BrowserWindow, dialog, ipcMain, net } from 'electron';
|
||||
import { ClientType, Innertube, UniversalCache, Utils } from 'youtubei.js';
|
||||
import { ClientType, Innertube, UniversalCache, Utils, YTNodes } from 'youtubei.js';
|
||||
import is from 'electron-is';
|
||||
import ytpl from 'ytpl';
|
||||
// REPLACE with youtubei getplaylist https://github.com/LuanRT/YouTube.js#getplaylistid
|
||||
import filenamify from 'filenamify';
|
||||
import { Mutex } from 'async-mutex';
|
||||
import { createFFmpeg } from '@ffmpeg.wasm/main';
|
||||
|
||||
import NodeID3, { TagConstants } from 'node-id3';
|
||||
|
||||
import PlayerErrorMessage from 'youtubei.js/dist/src/parser/classes/PlayerErrorMessage';
|
||||
import { FormatOptions } from 'youtubei.js/dist/src/types/FormatUtils';
|
||||
|
||||
import TrackInfo from 'youtubei.js/dist/src/parser/ytmusic/TrackInfo';
|
||||
|
||||
import { VideoInfo } from 'youtubei.js/dist/src/parser/youtube';
|
||||
|
||||
import { cropMaxWidth, getFolder, presets, sendFeedback as sendFeedback_, setBadge } from './utils';
|
||||
|
||||
import config from './config';
|
||||
@ -32,8 +23,13 @@ import { cleanupName, getImage, SongInfo } from '../../providers/song-info';
|
||||
import { injectCSS } from '../utils';
|
||||
import { cache } from '../../providers/decorators';
|
||||
|
||||
import type { GetPlayerResponse } from '../../types/get-player-response';
|
||||
import type { FormatOptions } from 'youtubei.js/dist/src/types/FormatUtils';
|
||||
import type PlayerErrorMessage from 'youtubei.js/dist/src/parser/classes/PlayerErrorMessage';
|
||||
import type { Playlist } from 'youtubei.js/dist/src/parser/ytmusic';
|
||||
import type { VideoInfo } from 'youtubei.js/dist/src/parser/youtube';
|
||||
import type TrackInfo from 'youtubei.js/dist/src/parser/ytmusic/TrackInfo';
|
||||
|
||||
import type { GetPlayerResponse } from '../../types/get-player-response';
|
||||
|
||||
type CustomSongInfo = SongInfo & { trackId?: string };
|
||||
|
||||
@ -69,16 +65,19 @@ const sendError = (error: Error, source?: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const getCookieFromWindow = async (win: BrowserWindow) => {
|
||||
return (await win.webContents.session.cookies.get({ url: 'https://music.youtube.com' })).map((it) =>
|
||||
it.name + '=' + it.value + ';'
|
||||
).join('');
|
||||
};
|
||||
|
||||
export default async (win_: BrowserWindow) => {
|
||||
win = win_;
|
||||
injectCSS(win.webContents, style);
|
||||
|
||||
const cookie = (await win.webContents.session.cookies.get({ url: 'https://music.youtube.com' })).map((it) =>
|
||||
it.name + '=' + it.value + ';'
|
||||
).join('');
|
||||
yt = await Innertube.create({
|
||||
cache: new UniversalCache(false),
|
||||
cookie,
|
||||
cookie: await getCookieFromWindow(win),
|
||||
generate_session_locally: true,
|
||||
fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url =
|
||||
@ -118,6 +117,7 @@ export async function downloadSong(
|
||||
let resolvedName;
|
||||
try {
|
||||
await downloadSongUnsafe(
|
||||
false,
|
||||
url,
|
||||
(name: string) => resolvedName = name,
|
||||
playlistFolder,
|
||||
@ -129,8 +129,31 @@ export async function downloadSong(
|
||||
}
|
||||
}
|
||||
|
||||
export async function downloadSongFromId(
|
||||
id: string,
|
||||
playlistFolder: string | undefined = undefined,
|
||||
trackId: string | undefined = undefined,
|
||||
increasePlaylistProgress: (value: number) => void = () => {
|
||||
},
|
||||
) {
|
||||
let resolvedName;
|
||||
try {
|
||||
await downloadSongUnsafe(
|
||||
true,
|
||||
id,
|
||||
(name: string) => resolvedName = name,
|
||||
playlistFolder,
|
||||
trackId,
|
||||
increasePlaylistProgress,
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
sendError(error as Error, resolvedName || id);
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadSongUnsafe(
|
||||
url: string,
|
||||
isId: boolean,
|
||||
idOrUrl: string,
|
||||
setName: (name: string) => void,
|
||||
playlistFolder: string | undefined = undefined,
|
||||
trackId: string | undefined = undefined,
|
||||
@ -147,8 +170,13 @@ async function downloadSongUnsafe(
|
||||
|
||||
sendFeedback('Downloading...', 2);
|
||||
|
||||
const id = getVideoId(url);
|
||||
if (typeof id !== 'string') throw new Error('Video not found');
|
||||
let id: string | null;
|
||||
if (isId) {
|
||||
id = idOrUrl;
|
||||
} else {
|
||||
id = getVideoId(idOrUrl);
|
||||
if (typeof id !== 'string') throw new Error('Video not found');
|
||||
}
|
||||
|
||||
let info: TrackInfo | VideoInfo = await yt.music.getInfo(id);
|
||||
|
||||
@ -199,10 +227,13 @@ async function downloadSongUnsafe(
|
||||
presetSetting = presets[preset];
|
||||
}
|
||||
|
||||
const filename = filenamify(`${name}.${presetSetting?.extension ?? 'mp3'}`, {
|
||||
let filename = filenamify(`${name}.${presetSetting?.extension ?? 'mp3'}`, {
|
||||
replacement: '_',
|
||||
maxLength: 255,
|
||||
});
|
||||
if (!is.macOS()) {
|
||||
filename = filename.normalize('NFC');
|
||||
}
|
||||
const filePath = join(dir, filename);
|
||||
|
||||
if (config.get('skipExisting') && existsSync(filePath)) {
|
||||
@ -414,11 +445,9 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
|
||||
|
||||
console.log(`trying to get playlist ID: '${playlistId}'`);
|
||||
sendFeedback('Getting playlist info…');
|
||||
let playlist: ytpl.Result;
|
||||
let playlist: Playlist;
|
||||
try {
|
||||
playlist = await ytpl(playlistId, {
|
||||
limit: config.get('playlistMaxItems') || Number.POSITIVE_INFINITY,
|
||||
});
|
||||
playlist = await yt.music.getPlaylist(playlistId);
|
||||
} catch (error: unknown) {
|
||||
sendError(
|
||||
Error(`Error getting playlist info: make sure it isn't a private or "Mixed for you" playlist\n\n${String(error)}`),
|
||||
@ -426,22 +455,27 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (playlist.items.length === 0) {
|
||||
if (!playlist || !playlist.items || playlist.items.length === 0) {
|
||||
sendError(new Error('Playlist is empty'));
|
||||
}
|
||||
|
||||
if (playlist.items.length === 1) {
|
||||
const items = playlist.items!.as(YTNodes.MusicResponsiveListItem);
|
||||
if (items.length === 1) {
|
||||
sendFeedback('Playlist has only one item, downloading it directly');
|
||||
await downloadSong(playlist.items[0].url);
|
||||
await downloadSongFromId(items.at(0)!.id!);
|
||||
return;
|
||||
}
|
||||
|
||||
const isAlbum = playlist.title.startsWith('Album - ');
|
||||
let playlistTitle = playlist.header?.title?.text ?? '';
|
||||
const isAlbum = playlistTitle?.startsWith('Album - ');
|
||||
if (isAlbum) {
|
||||
playlist.title = playlist.title.slice(8);
|
||||
playlistTitle = playlistTitle.slice(8);
|
||||
}
|
||||
|
||||
const safePlaylistTitle = filenamify(playlist.title, { replacement: ' ' });
|
||||
let safePlaylistTitle = filenamify(playlistTitle, { replacement: ' ' });
|
||||
if (!is.macOS()) {
|
||||
safePlaylistTitle = safePlaylistTitle.normalize('NFC');
|
||||
}
|
||||
|
||||
const folder = getFolder(config.get('downloadFolder') ?? '');
|
||||
const playlistFolder = join(folder, safePlaylistTitle);
|
||||
@ -458,47 +492,47 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
|
||||
type: 'info',
|
||||
buttons: ['OK'],
|
||||
title: 'Started Download',
|
||||
message: `Downloading Playlist "${playlist.title}"`,
|
||||
detail: `(${playlist.items.length} songs)`,
|
||||
message: `Downloading Playlist "${playlistTitle}"`,
|
||||
detail: `(${items.length} songs)`,
|
||||
});
|
||||
|
||||
if (is.dev()) {
|
||||
console.log(
|
||||
`Downloading playlist "${playlist.title}" - ${playlist.items.length} songs (${playlistId})`,
|
||||
`Downloading playlist "${playlistTitle}" - ${items.length} songs (${playlistId})`,
|
||||
);
|
||||
}
|
||||
|
||||
win.setProgressBar(2); // Starts with indefinite bar
|
||||
|
||||
setBadge(playlist.items.length);
|
||||
setBadge(items.length);
|
||||
|
||||
let counter = 1;
|
||||
|
||||
const progressStep = 1 / playlist.items.length;
|
||||
const progressStep = 1 / items.length;
|
||||
|
||||
const increaseProgress = (itemPercentage: number) => {
|
||||
const currentProgress = (counter - 1) / (playlist.items.length ?? 1);
|
||||
const currentProgress = (counter - 1) / (items.length ?? 1);
|
||||
const newProgress = currentProgress + (progressStep * itemPercentage);
|
||||
win.setProgressBar(newProgress);
|
||||
};
|
||||
|
||||
try {
|
||||
for (const song of playlist.items) {
|
||||
sendFeedback(`Downloading ${counter}/${playlist.items.length}...`);
|
||||
for (const song of items) {
|
||||
sendFeedback(`Downloading ${counter}/${items.length}...`);
|
||||
const trackId = isAlbum ? counter : undefined;
|
||||
await downloadSong(
|
||||
song.url,
|
||||
await downloadSongFromId(
|
||||
song.id!,
|
||||
playlistFolder,
|
||||
trackId?.toString(),
|
||||
increaseProgress,
|
||||
).catch((error) =>
|
||||
sendError(
|
||||
new Error(`Error downloading "${song.author.name} - ${song.title}":\n ${error}`)
|
||||
new Error(`Error downloading "${song.author!.name} - ${song.title!}":\n ${error}`)
|
||||
),
|
||||
);
|
||||
|
||||
win.setProgressBar(counter / playlist.items.length);
|
||||
setBadge(playlist.items.length - counter);
|
||||
win.setProgressBar(counter / items.length);
|
||||
setBadge(items.length - counter);
|
||||
counter++;
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
|
||||
@ -2,14 +2,14 @@ import path from 'node:path';
|
||||
|
||||
import { app, BrowserWindow, ipcMain, Notification } from 'electron';
|
||||
|
||||
import { icons, notificationImage, saveTempIcon, secondsToMinutes, ToastStyles } from './utils';
|
||||
import { notificationImage, secondsToMinutes, ToastStyles } from './utils';
|
||||
import config from './config';
|
||||
|
||||
import getSongControls from '../../providers/song-controls';
|
||||
import registerCallback, { SongInfo } from '../../providers/song-info';
|
||||
import { changeProtocolHandler } from '../../providers/protocol-handler';
|
||||
import { setTrayOnClick, setTrayOnDoubleClick } from '../../tray';
|
||||
import { getMediaIconLocation } from '../utils';
|
||||
import { getMediaIconLocation, mediaIcons, saveMediaIcon } from '../utils';
|
||||
|
||||
let songControls: ReturnType<typeof getSongControls>;
|
||||
let savedNotification: Notification | undefined;
|
||||
@ -23,7 +23,7 @@ export default (win: BrowserWindow) => {
|
||||
ipcMain.on('timeChanged', (_, t: number) => currentSeconds = t);
|
||||
|
||||
if (app.isPackaged) {
|
||||
saveTempIcon();
|
||||
saveMediaIcon();
|
||||
}
|
||||
|
||||
let savedSongInfo: SongInfo;
|
||||
@ -152,9 +152,9 @@ const getXml = (songInfo: SongInfo, iconSrc: string) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
const display = (kind: keyof typeof icons) => {
|
||||
const display = (kind: keyof typeof mediaIcons) => {
|
||||
if (config.get('toastStyle') === ToastStyles.legacy) {
|
||||
return `content="${icons[kind]}"`;
|
||||
return `content="${mediaIcons[kind]}"`;
|
||||
}
|
||||
|
||||
return `\
|
||||
@ -163,7 +163,7 @@ const display = (kind: keyof typeof icons) => {
|
||||
`;
|
||||
};
|
||||
|
||||
const getButton = (kind: keyof typeof icons) =>
|
||||
const getButton = (kind: keyof typeof mediaIcons) =>
|
||||
`<action ${display(kind)} activationType="protocol" arguments="youtubemusic://${kind}"/>`;
|
||||
|
||||
const getButtons = (isPaused: boolean) => `\
|
||||
|
||||
@ -9,7 +9,7 @@ import { cache } from '../../providers/decorators';
|
||||
import { SongInfo } from '../../providers/song-info';
|
||||
import { getAssetsDirectoryLocation } from '../utils';
|
||||
|
||||
const icon = 'assets/youtube-music.png';
|
||||
const defaultIcon = path.join(getAssetsDirectoryLocation(), 'youtube-music.png');
|
||||
const userData = app.getPath('userData');
|
||||
const temporaryIcon = path.join(userData, 'tempIcon.png');
|
||||
const temporaryBanner = path.join(userData, 'tempBanner.png');
|
||||
@ -25,13 +25,6 @@ export const ToastStyles = {
|
||||
legacy: 7,
|
||||
};
|
||||
|
||||
export const icons = {
|
||||
play: '\u{1405}', // ᐅ
|
||||
pause: '\u{2016}', // ‖
|
||||
next: '\u{1433}', // ᐳ
|
||||
previous: '\u{1438}', // ᐸ
|
||||
};
|
||||
|
||||
export const urgencyLevels = [
|
||||
{ name: 'Low', value: 'low' },
|
||||
{ name: 'Normal', value: 'normal' },
|
||||
@ -52,7 +45,7 @@ const nativeImageToLogo = cache((nativeImage: NativeImage) => {
|
||||
|
||||
export const notificationImage = (songInfo: SongInfo) => {
|
||||
if (!songInfo.image) {
|
||||
return icon;
|
||||
return defaultIcon;
|
||||
}
|
||||
|
||||
if (!config.get('interactive')) {
|
||||
@ -76,25 +69,12 @@ export const saveImage = cache((img: NativeImage, savePath: string) => {
|
||||
fs.writeFileSync(savePath, img.toPNG());
|
||||
} catch (error: unknown) {
|
||||
console.log(`Error writing song icon to disk:\n${String(error)}`);
|
||||
return icon;
|
||||
return defaultIcon;
|
||||
}
|
||||
|
||||
return savePath;
|
||||
});
|
||||
|
||||
export const saveTempIcon = () => {
|
||||
for (const kind of Object.keys(icons)) {
|
||||
const destinationPath = path.join(userData, 'icons', `${kind}.png`);
|
||||
if (fs.existsSync(destinationPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const iconPath = path.resolve(path.resolve(getAssetsDirectoryLocation(), 'media-icons-black'), `${kind}.png`);
|
||||
fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
|
||||
fs.copyFile(iconPath, destinationPath, () => {});
|
||||
}
|
||||
};
|
||||
|
||||
export const snakeToCamel = (string_: string) => string_.replaceAll(/([-_][a-z]|^[a-z])/g, (group) =>
|
||||
group.toUpperCase()
|
||||
.replace('-', ' ')
|
||||
|
||||
4
plugins/shortcuts/mpris-service.d.ts
vendored
4
plugins/shortcuts/mpris-service.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
declare module 'mpris-service' {
|
||||
declare module '@jellybrick/mpris-service' {
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
import dbus from 'dbus-next';
|
||||
@ -75,6 +75,8 @@ declare module 'mpris-service' {
|
||||
|
||||
objectPath(subpath?: string): string;
|
||||
|
||||
getPosition(): number;
|
||||
|
||||
seeked(position: number): void;
|
||||
|
||||
getTrackIndex(trackId: string): number;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { BrowserWindow, ipcMain } from 'electron';
|
||||
|
||||
import mpris, { Track } from 'mpris-service';
|
||||
import mpris, { Track } from '@jellybrick/mpris-service';
|
||||
|
||||
import registerCallback from '../../providers/song-info';
|
||||
import getSongControls from '../../providers/song-controls';
|
||||
@ -50,18 +50,13 @@ function registerMPRIS(win: BrowserWindow) {
|
||||
player.loopStatus = mpris.LOOP_STATUS_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'ONE': {
|
||||
player.loopStatus = mpris.LOOP_STATUS_PLAYLIST;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'ALL': {
|
||||
{
|
||||
player.loopStatus = mpris.LOOP_STATUS_TRACK;
|
||||
// No default
|
||||
}
|
||||
|
||||
player.loopStatus = mpris.LOOP_STATUS_TRACK;
|
||||
// No default
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -76,6 +71,7 @@ function registerMPRIS(win: BrowserWindow) {
|
||||
const delta = (targetIndex - currentIndex + 3) % 3;
|
||||
songControls.switchRepeat(delta);
|
||||
});
|
||||
player.getPosition = () => secToMicro(currentSeconds);
|
||||
|
||||
player.on('raise', () => {
|
||||
win.setSkipTaskbar(false);
|
||||
@ -110,7 +106,7 @@ function registerMPRIS(win: BrowserWindow) {
|
||||
shuffle();
|
||||
}
|
||||
});
|
||||
player.on('open', (args: { uri: string}) => { win.loadURL(args.uri); });
|
||||
player.on('open', (args: { uri: string }) => { win.loadURL(args.uri); });
|
||||
|
||||
let mprisVolNewer = false;
|
||||
let autoUpdate = false;
|
||||
|
||||
@ -1,16 +1,20 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { BrowserWindow, nativeImage } from 'electron';
|
||||
import { app, BrowserWindow, nativeImage } from 'electron';
|
||||
|
||||
import getSongControls from '../../providers/song-controls';
|
||||
import registerCallback, { SongInfo } from '../../providers/song-info';
|
||||
import { getMediaIconLocation } from '../utils';
|
||||
import { getMediaIconLocation, saveMediaIcon } from '../utils';
|
||||
|
||||
export default (win: BrowserWindow) => {
|
||||
let currentSongInfo: SongInfo;
|
||||
|
||||
const { playPause, next, previous } = getSongControls(win);
|
||||
|
||||
if (app.isPackaged) {
|
||||
saveMediaIcon();
|
||||
}
|
||||
|
||||
const setThumbar = (win: BrowserWindow, songInfo: SongInfo) => {
|
||||
// Wait for song to start before setting thumbar
|
||||
if (!songInfo?.title) {
|
||||
|
||||
@ -2,7 +2,6 @@ import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
import { app, ipcMain, ipcRenderer } from 'electron';
|
||||
|
||||
import is from 'electron-is';
|
||||
|
||||
import { ValueOf } from '../utils/type-utils';
|
||||
@ -15,6 +14,26 @@ export const getMediaIconLocation = () =>
|
||||
? path.resolve(app.getPath('userData'), 'icons')
|
||||
: path.resolve(getAssetsDirectoryLocation(), 'media-icons-black');
|
||||
|
||||
export const mediaIcons = {
|
||||
play: '\u{1405}', // ᐅ
|
||||
pause: '\u{2016}', // ‖
|
||||
next: '\u{1433}', // ᐳ
|
||||
previous: '\u{1438}', // ᐸ
|
||||
} as const;
|
||||
|
||||
export const saveMediaIcon = () => {
|
||||
for (const kind of Object.keys(mediaIcons)) {
|
||||
const destinationPath = path.join(getMediaIconLocation(), `${kind}.png`);
|
||||
if (fs.existsSync(destinationPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const iconPath = path.resolve(path.resolve(getAssetsDirectoryLocation(), 'media-icons-black'), `${kind}.png`);
|
||||
fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
|
||||
fs.copyFile(iconPath, destinationPath, () => {});
|
||||
}
|
||||
};
|
||||
|
||||
// Creates a DOM element from an HTML string
|
||||
export const ElementFromHtml = (html: string): HTMLElement => {
|
||||
const template = document.createElement('template');
|
||||
|
||||
4
plugins/visualizer/butterchurn.d.ts
vendored
4
plugins/visualizer/butterchurn.d.ts
vendored
@ -49,5 +49,7 @@ declare module 'butterchurn' {
|
||||
}
|
||||
|
||||
declare module 'butterchurn-presets' {
|
||||
export function getPresets(): Record<string, unknown>;
|
||||
const presets: Record<string, unknown>;
|
||||
|
||||
export default presets;
|
||||
}
|
||||
|
||||
@ -5,8 +5,6 @@ import { Visualizer } from './visualizer';
|
||||
|
||||
import { ConfigType } from '../../../config/dynamic';
|
||||
|
||||
const presets = ButterchurnPresets.getPresets();
|
||||
|
||||
class ButterchurnVisualizer extends Visualizer<Butterchurn> {
|
||||
name = 'butterchurn';
|
||||
|
||||
@ -41,7 +39,7 @@ class ButterchurnVisualizer extends Visualizer<Butterchurn> {
|
||||
}
|
||||
);
|
||||
|
||||
const preset = presets[options.butterchurn.preset];
|
||||
const preset = ButterchurnPresets[options.butterchurn.preset];
|
||||
this.visualizer.loadPreset(preset, options.butterchurn.blendTimeInSeconds);
|
||||
|
||||
this.visualizer.connectAudio(audioNode);
|
||||
|
||||
@ -187,7 +187,7 @@ function onApiLoaded() {
|
||||
// Remove upgrade button
|
||||
if (config.get('options.removeUpgradeButton')) {
|
||||
const styles = document.createElement('style');
|
||||
styles.innerHTML = `ytmusic-guide-section-renderer #items ytmusic-guide-entry-renderer:last-child {
|
||||
styles.innerHTML = `ytmusic-guide-section-renderer #items ytmusic-guide-entry-renderer:nth-child(4) {
|
||||
display: none;
|
||||
}`;
|
||||
document.head.appendChild(styles);
|
||||
|
||||
@ -62,8 +62,8 @@ export const setupRepeatChangedListener = singleton(() => {
|
||||
ipcRenderer.send(
|
||||
'repeatChanged',
|
||||
$<HTMLElement & {
|
||||
GetState: () => GetState;
|
||||
}>('ytmusic-player-bar')?.GetState().queue.repeatMode,
|
||||
getState: () => GetState;
|
||||
}>('ytmusic-player-bar')?.getState().queue.repeatMode,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
11
readme.md
11
readme.md
@ -104,8 +104,7 @@ winget install th-ch.YouTubeMusic
|
||||
slider [exponential](https://greasyfork.org/en/scripts/397686-youtube-music-fix-volume-ratio/) so it's easier to
|
||||
select lower volumes.
|
||||
|
||||
- **In-App Menu
|
||||
**: [gives bars a fancy, dark look](https://user-images.githubusercontent.com/78568641/112215894-923dbf00-8c29-11eb-95c3-3ce15db27eca.png)
|
||||
- **In-App Menu**: [gives bars a fancy, dark look](https://user-images.githubusercontent.com/78568641/112215894-923dbf00-8c29-11eb-95c3-3ce15db27eca.png)
|
||||
|
||||
> (see [this post](https://github.com/th-ch/youtube-music/issues/410#issuecomment-952060709) if you have problem
|
||||
accessing the menu after enabling this plugin and hide-menu option)
|
||||
@ -179,7 +178,7 @@ Some predefined themes are available in https://github.com/kerichdev/themes-for-
|
||||
```bash
|
||||
git clone https://github.com/th-ch/youtube-music
|
||||
cd youtube-music
|
||||
npm
|
||||
npm ci
|
||||
npm run start
|
||||
```
|
||||
|
||||
@ -270,9 +269,9 @@ export default () => {
|
||||
2. Run `npm i` to install dependencies
|
||||
3. Run `npm run build:OS`
|
||||
|
||||
- `npm run build:win` - Windows
|
||||
- `npm run build:linux` - Linux
|
||||
- `npm run build:mac` - MacOS
|
||||
- `npm run dist:win` - Windows
|
||||
- `npm run dist:linux` - Linux
|
||||
- `npm run dist:mac` - MacOS
|
||||
|
||||
Builds the app for macOS, Linux, and Windows,
|
||||
using [electron-builder](https://github.com/electron-userland/electron-builder).
|
||||
|
||||
@ -59,7 +59,6 @@ export default defineConfig({
|
||||
external: [
|
||||
'electron',
|
||||
'custom-electron-prompt',
|
||||
'youtubei.js', // https://github.com/LuanRT/YouTube.js/pull/509
|
||||
...builtinModules,
|
||||
],
|
||||
});
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { existsSync, writeFile } = require('node:fs');
|
||||
const { join } = require('node:path');
|
||||
const { promisify } = require('node:util');
|
||||
|
||||
/**
|
||||
* Generates a fake package.json for given packages that don't have any.
|
||||
* Allows electron-builder to resolve them
|
||||
*/
|
||||
|
||||
const generatePackageJson = async (packageName) => {
|
||||
const packageFolder = join('node_modules', packageName);
|
||||
if (!existsSync(packageFolder)) {
|
||||
console.log(
|
||||
`${packageName} module not found, exiting…`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const filepath = join(packageFolder, 'package.json');
|
||||
if (!existsSync(filepath)) {
|
||||
console.log(
|
||||
`No package.json found for ${packageName} module, generating one…`,
|
||||
);
|
||||
let pkg = {
|
||||
name: packageName,
|
||||
version: '0.0.0',
|
||||
description: '-',
|
||||
repository: { type: 'git', url: '-' },
|
||||
readme: '-',
|
||||
};
|
||||
const writeFileAsync = promisify(writeFile);
|
||||
await writeFileAsync(filepath, JSON.stringify(pkg, null, 2));
|
||||
}
|
||||
};
|
||||
|
||||
if (require.main === module) {
|
||||
process.argv.slice(2).forEach(async (packageName) => {
|
||||
await generatePackageJson(packageName);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user