Browse Source

YouTube Music Support

tags/v4.6.0
Samuel Attard 2 years ago
parent
commit
61fb9ba98a
No known key found for this signature in database GPG Key ID: 273DC1869D8F13EF
9 changed files with 118 additions and 43 deletions
  1. +3
    -2
      package.json
  2. +3
    -1
      src/_locales/en-US.json
  3. +21
    -0
      src/main/features/core/tray.js
  4. +1
    -0
      src/main/utils/_initialSettings.js
  5. +28
    -10
      src/renderer/ui/pages/PlayerPage.js
  6. +38
    -14
      src/renderer/windows/GPMWebView/index.js
  7. +15
    -11
      src/renderer/windows/GPMWebView/playback/audioSelection.js
  8. +2
    -2
      src/renderer/windows/main.js
  9. +7
    -3
      yarn.lock

+ 3
- 2
package.json View File

@@ -61,7 +61,7 @@
"archiver": "^1.0.1",
"auto-launch": "^4.0.0",
"discord-rich-presence": "^0.0.5",
"electron": "2.0.1",
"electron": "2.0.2",
"electron-chromecast": "^1.1.0",
"gmusic-mini-player.js": "^2.0.10",
"gmusic-theme.js": "^2.1.16",
@@ -89,7 +89,8 @@
"uuid": "^2.0.2",
"winston": "^2.2.0",
"ws": "^1.1.0",
"xss": "^0.2.13"
"xss": "^0.2.13",
"ytmusic.js": "6.1.7"
},
"devDependencies": {
"babel-eslint": "^6.1.2",


+ 3
- 1
src/_locales/en-US.json View File

@@ -143,5 +143,7 @@
"title-settings-style": "Custom Styles",

"tray-label-audio-device": "Audio Device",
"tray-label-show": "Show"
"tray-label-show": "Show",
"tray-label-gpm": "Google Play Music",
"tray-label-ytm": "YouTube Music (alpha, please use the dark theme)"
}

+ 21
- 0
src/main/features/core/tray.js View File

@@ -81,6 +81,27 @@ Emitter.on('playback:isStopped', () => {

const setContextMenu = (track) => {
const contextMenu = Menu.buildFromTemplate([
{
label: 'Service',
enabled: false,
},
{
label: TranslationProvider.query('tray-label-gpm'),
click: () => {
Settings.set('service', 'google-play-music');
mainWindow.hide();
mainWindow.reload();
},
},
{
label: TranslationProvider.query('tray-label-ytm'),
click: () => {
Settings.set('service', 'youtube-music');
mainWindow.hide();
mainWindow.reload();
},
},
{ type: 'separator' },
{ label: TranslationProvider.query('tray-label-show'),
click: () => {
mainWindow.setSkipTaskbar(false);


+ 1
- 0
src/main/utils/_initialSettings.js View File

@@ -15,4 +15,5 @@ export default {
enableWin10MediaService: false,
enableWin10MediaServiceTrackInfo: true,
lastFMMapThumbToHeart: true,
service: 'google-play-music',
};

+ 28
- 10
src/renderer/ui/pages/PlayerPage.js View File

@@ -23,14 +23,25 @@ export default class PlayerPage extends Component {
super(...args);

this.once = true;
this.targetPage = Settings.get('savePage', true) ?
Settings.get('lastPage', 'https://play.google.com/music/listen')
: 'https://play.google.com/music/listen';
const service = Settings.get('service');
this.ready = false;
this.state = {
webviewTarget: 'https://play.google.com/music/listen#/wmp',
title: 'Google Play Music Desktop Player',
};
if (service === 'youtube-music') {
this.targetPage = Settings.get('savePage', true) ?
Settings.get('lastYTMPage', 'https://music.youtube.com/')
: 'https://music.youtube.com/';
this.state = {
webviewTarget: 'https://music.youtube.com/',
title: 'Youtube Music Desktop Player',
};
} else if (service === 'google-play-music' || true) {
this.targetPage = Settings.get('savePage', true) ?
Settings.get('lastPage', 'https://play.google.com/music/listen')
: 'https://play.google.com/music/listen';
this.state = {
webviewTarget: 'https://play.google.com/music/listen#/wmp',
title: 'Google Play Music Desktop Player',
};
}
}

componentDidMount() {
@@ -61,7 +72,7 @@ export default class PlayerPage extends Component {
this.ready = true;

const focusWebview = () => {
document.querySelector('webview::shadow object').focus();
document.querySelector('webview').focus();
};
window.addEventListener('beforeunload', () => {
remote.getCurrentWindow().removeListener('focus', focusWebview);
@@ -95,8 +106,15 @@ export default class PlayerPage extends Component {

_savePage = (param) => {
const url = param.url || param;
if (!/https?:\/\/play\.google\.com\/music/g.test(url)) return;
Settings.set('lastPage', url);

const service = Settings.get('service');
if (service === 'youtube-music') {
if (!/https?:\/\/music\.youtube\.com\//g.test(url)) return;
Settings.set('lastYTMPage', url);
} else if (service === 'google-play-music' || true) {
if (!/https?:\/\/play\.google\.com\/music/g.test(url)) return;
Settings.set('lastPage', url);
}
}

render() {


+ 38
- 14
src/renderer/windows/GPMWebView/index.js View File

@@ -28,29 +28,52 @@ require('./interface');
require('./chromecast');
require('./runtime');

const service = Settings.get('service');
const serviceReady = () => {
if (service === 'youtube-music') {
return document.querySelector('.ytmusic-player-bar') && document.querySelector('video');
}
// Google Play Music
return document.querySelector('#material-vslider') && document.querySelectorAll('audio')[1];
};

// DEV: We need to wait for the page to load sufficiently before we can load
// gmusic.js and its child libraries
const waitForExternal = setInterval(() => {
if (document.querySelector('#material-vslider') && document.querySelectorAll('audio')[1]) {
if (serviceReady()) {
clearInterval(waitForExternal);
const GMusic = require('gmusic.js');
require('gmusic-ui.js')(GMusic);
require('gmusic-mini-player.js')(GMusic);
const GMusicTheme = require('gmusic-theme.js');

window.GMusic = GMusic;
window.GMusicTheme = GMusicTheme;
if (service === 'youtube-music') {
const YTMusic = require('ytmusic.js');
window.GMusic = YTMusic;
window.GPM = new YTMusic();
// TODO: Implement theming support
window.GPMTheme = {
updateTheme() {},
enable() {},
disable() {},
};
} else {
const GMusic = require('gmusic.js');
window.GMusic = GMusic;
// Google Play Music
require('gmusic-ui.js')(GMusic);
require('gmusic-mini-player.js')(GMusic);
const GMusicTheme = require('gmusic-theme.js');

window.GPM = new GMusic();
window.GPMTheme = new window.GMusicTheme();
window.GPM = new GMusic();
window.GPMTheme = new GMusicTheme();
}

/*
Move to magical file
*/
window.GPM.search.performSearchAndPlayResult = (searchText, result) => {
window.GPM.search.performSearch(searchText)
.then(() => window.GPM.search.playResult(result));
};
if (window.GPM.search) {
window.GPM.search.performSearchAndPlayResult = (searchText, result) => {
window.GPM.search.performSearch(searchText)
.then(() => window.GPM.search.playResult(result));
};
}

/*
Fix scrollbars
@@ -67,7 +90,8 @@ const waitForExternal = setInterval(() => {
Logger.error('Emitter fn() threw exception.', e.stack);
}
});
Settings.set('gpmdp_connect_email', window.gbar._CONFIG[0][10][5]);
// TODO: This never took off, comment out for now
// Settings.set('gpmdp_connect_email', window.gbar._CONFIG[0][10][5]);
}
}, 10);



+ 15
- 11
src/renderer/windows/GPMWebView/playback/audioSelection.js View File

@@ -21,16 +21,20 @@ export const setAudioDevice = (audioElem, id, count = 0) =>
});

Emitter.on('audiooutput:set', (event, deviceId) => {
Array.prototype.forEach.call(document.querySelectorAll('audio:not(.offscreen)'), (audioElem) => {
let once = true;
if (audioElem.paused) {
audioElem.addEventListener('playing', () => {
if (!once) return;
once = false;
const setForElems = (elems) => {
Array.prototype.forEach.call(elems, (audioElem) => {
let once = true;
if (audioElem.paused) {
audioElem.addEventListener('playing', () => {
if (!once) return;
once = false;
setAudioDevice(audioElem, deviceId);
});
} else {
setAudioDevice(audioElem, deviceId);
});
} else {
setAudioDevice(audioElem, deviceId);
}
});
}
});
};
setForElems(document.querySelectorAll('audio:not(.offscreen)'));
setForElems(document.querySelectorAll('video'));
});

+ 2
- 2
src/renderer/windows/main.js View File

@@ -1,4 +1,4 @@
import { remote, app } from 'electron';
import { remote } from 'electron';
import React from 'react';
import ReactDOM from 'react-dom';
import injectTapEventPlugin from 'react-tap-event-plugin';
@@ -10,7 +10,7 @@ injectTapEventPlugin();
ReactDOM.render(<PlayerPage />, document.querySelector('#main-window'));

// minimize if 'start minimized' is on.
if (Settings.get('startMinimized', false) || app.getLoginItemSettings().wasOpenedAsHidden) {
if (Settings.get('startMinimized', false) || remote.app.getLoginItemSettings().wasOpenedAsHidden) {
if (Settings.get('minToTray', false)) {
// .minimize will show on the windows taskbar even if minToTray is true
// Since, minToTray is on we can safely close without killing


+ 7
- 3
yarn.lock View File

@@ -2215,9 +2215,9 @@ electron-windows-store@^0.9.3:
multiline "^1.0.2"
path-exists "^3.0.0"

electron@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/electron/-/electron-2.0.1.tgz#d9defcc187862143b9027378be78490eddbfabf4"
electron@2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/electron/-/electron-2.0.2.tgz#b77e05f83419cc5ec921a2d21f35b55e4bfc3d68"
dependencies:
"@types/node" "^8.0.24"
electron-download "^3.0.1"
@@ -8197,6 +8197,10 @@ yauzl@2.4.1:
dependencies:
fd-slicer "~1.0.1"

ytmusic.js@6.1.7:
version "6.1.7"
resolved "https://registry.yarnpkg.com/ytmusic.js/-/ytmusic.js-6.1.7.tgz#5c6af7c6dc404b9696ff251b5b6b062ea121d530"

zip-stream@^1.1.0, zip-stream@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/zip-stream/-/zip-stream-1.2.0.tgz#a8bc45f4c1b49699c6b90198baacaacdbcd4ba04"


Loading…
Cancel
Save