Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Release

env:
YARN_INSTALL_NOPT: yarn add --ignore-platform --ignore-optional
YARN_INSTALL_NOPT: yarn add --ignore-platform --ignore-optional --ignore-engines
ELECTRON_MIRROR: https://npmmirror.com/mirrors/electron/
ELECTRON_BUILDER_BINARIES_MIRROR: https://npmmirror.com/mirrors/electron-builder-binaries/

on:
push:
Expand Down Expand Up @@ -48,7 +50,7 @@ jobs:
- id: get_unm_version
name: Get the installed UNM version
run: |
yarn --ignore-optional
npx yarn@1.22.22 --ignore-engines --frozen-lockfile install --ignore-optional
unm_version=$(node -e "console.log(require('./node_modules/@unblockneteasemusic/rust-napi/package.json').version)")
echo "::set-output name=unmver::${unm_version}"
shell: bash
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pnpm-debug.log*

#Electron-builder output
/dist_electron
out
NeteaseCloudMusicApi-master
NeteaseCloudMusicApi-master.zip

Expand All @@ -40,4 +41,4 @@ devenv.local.nix
.direnv

# pre-commit
.pre-commit-config.yaml
.pre-commit-config.yaml
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ COPY --from=build /app/package.json /usr/local/lib/
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
&& apk add --no-cache libuv nodejs npm \
&& npm config set registry https://registry.npmmirror.com \
&& npm i -g $(awk -F \" '{if($2=="@neteaseapireborn/api@latest") print $2"@"$4}' /usr/local/lib/package.json) \
&& npm i -g $(awk -F \" '{if($2=="@neteasecloudmusicapienhanced/api@latest") print $2"@"$4}' /usr/local/lib/package.json) \
&& rm -f /usr/local/lib/package.json

COPY --from=build /app/docker/nginx.conf.example /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html

CMD ["sh", "-c", "nginx && exec npx @neteaseapireborn/api@latest"]
CMD ["sh", "-c", "nginx && exec npx @neteasecloudmusicapienhanced/api@latest"]
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps",
"prettier": "npx prettier --write ./src",
"netease_api:run": "npx @neteaseapireborn/api"
"netease_api:run": "npx @neteasecloudmusicapienhanced/api"
},
"main": "background.js",
"engines": {
"node": "14 || 16"
},
"dependencies": {
"@neteaseapireborn/api": "^4.29.7",
"@neteasecloudmusicapienhanced/api": "^4.29.7",
"@unblockneteasemusic/rust-napi": "^0.4.0",
"axios": "^0.26.1",
"change-case": "^4.1.2",
Expand Down
19 changes: 19 additions & 0 deletions src/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ export function userAccount() {
},
});
}
/**
* 通过 Cookie 获取账号详情(网页登录)
* 说明 : 登录后调用此接口 ,可获取用户账号信息
* - cookie: 网易云 Cookie 字符串
* @param {string} cookie
*/
export function userAccountWithCookie(cookie) {
const data = new URLSearchParams();
data.set('cookie', cookie);

return request({
url: '/user/account',
method: 'post',
params: {
timestamp: new Date().getTime(),
},
data,
});
}

/**
* 获取用户歌单
Expand Down
2 changes: 1 addition & 1 deletion src/assets/icons/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vue from 'vue';
import SvgIcon from '@/components/SvgIcon';

Vue.component('svg-icon', SvgIcon);
Vue.component('SvgIcon', SvgIcon);
const requireAll = requireContext => requireContext.keys().map(requireContext);
const req = require.context('./', true, /\.svg$/);
requireAll(req);
2 changes: 1 addition & 1 deletion src/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<img
class="avatar"
:src="avatarUrl"
@click="showUserProfileMenu"
loading="lazy"
@click="showUserProfileMenu"
/>
</div>
</nav>
Expand Down
86 changes: 85 additions & 1 deletion src/electron/ipcMain.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { app, dialog, globalShortcut, ipcMain } from 'electron';
import {
app,
BrowserWindow,
dialog,
globalShortcut,
ipcMain,
session,
} from 'electron';
import UNM from '@unblockneteasemusic/rust-napi';
import { registerGlobalShortcut } from '@/electron/globalShortcut';
import cloneDeep from 'lodash/cloneDeep';
Expand Down Expand Up @@ -133,6 +140,14 @@ function parseSourceStringToList(executor, sourceString) {
});
}

const getNeteaseCookieString = async loginSession => {
const cookies = await loginSession.cookies.get({
domain: 'music.163.com',
});

return cookies.map(cookie => `${cookie.name}=${cookie.value}`).join('; ');
};

export function initIpcMain(win, store, trayEventEmitter) {
// WIP: Do not enable logging as it has some issues in non-blocking I/O environment.
// UNM.enableLogging(UNM.LoggingType.ConsoleEnv);
Expand Down Expand Up @@ -198,6 +213,75 @@ export function initIpcMain(win, store, trayEventEmitter) {
}
);

ipcMain.handle('open-netease-web-login', async () => {
const loginSession = session.fromPartition('persist:netease-web-login');
const existingCookieString = await getNeteaseCookieString(loginSession);
if (existingCookieString.includes('MUSIC_U=')) {
return existingCookieString;
}

return new Promise((resolve, reject) => {
let settled = false;
const loginWindow = new BrowserWindow({
width: 960,
height: 720,
parent: win,
title: 'NetEase Web Login',
webPreferences: {
partition: 'persist:netease-web-login',
nodeIntegration: false,
contextIsolation: true,
},
});

const cleanup = () => {
loginSession.cookies.removeListener('changed', handleCookieChanged);
loginWindow.removeListener('closed', handleClosed);
};

const finish = cookieString => {
if (settled) return;
settled = true;
cleanup();
if (!loginWindow.isDestroyed()) loginWindow.close();
resolve(cookieString);
};

const fail = error => {
if (settled) return;
settled = true;
cleanup();
reject(error);
};

const checkLoginCookie = async () => {
try {
const cookieString = await getNeteaseCookieString(loginSession);
if (cookieString.includes('MUSIC_U=')) finish(cookieString);
} catch (error) {
fail(error);
}
};

const handleCookieChanged = (_event, cookie) => {
if (cookie.domain && cookie.domain.includes('music.163.com')) {
checkLoginCookie();
}
};

const handleClosed = () => {
if (!settled) {
cleanup();
resolve('');
}
};

loginSession.cookies.on('changed', handleCookieChanged);
loginWindow.on('closed', handleClosed);
loginWindow.loadURL('https://music.163.com/#/login').catch(fail);
});
});

ipcMain.on('close', e => {
if (isMac) {
win.hide();
Expand Down
8 changes: 6 additions & 2 deletions src/electron/mpris.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ export function createMpris(window) {

ipcMain.on('playerCurrentTrackTime', (e, position) => {
player.getPosition = () => position * 1000 * 1000;
try { player.seeked(position * 1000 * 1000); } catch {}
try {
player.seeked(position * 1000 * 1000);
} catch {}
});

ipcMain.on('seeked', (e, position) => {
try { player.seeked(position * 1000 * 1000); } catch {}
try {
player.seeked(position * 1000 * 1000);
} catch {}
});

ipcMain.on('switchRepeatMode', (e, mode) => {
Expand Down
2 changes: 1 addition & 1 deletion src/electron/services.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import clc from 'cli-color';
import checkAuthToken from '../utils/checkAuthToken';
import server from '@neteaseapireborn/api/server';
import server from '@neteasecloudmusicapienhanced/api/server';

export async function startNeteaseMusicApi() {
// Let user know that the service is starting
Expand Down
7 changes: 7 additions & 0 deletions src/locale/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export default {
login: 'Login',
loginWithEmail: 'Login with Email',
loginWithPhone: 'Login with Phone',
webLogin: 'Web Login',
openWebLogin: 'Open NetEase Web Login',
webLoginTip:
'After logging in on the NetEase page, copy that page Cookie and paste it below.',
cookiePlaceholder: 'Paste NetEase Cookie such as MUSIC_U=...; __csrf=...',
cookieTip:
'MUSIC_U is required. Cookies are only stored in this browser and localStorage.',
notice: `YesPlayMusic promises not to save any of your account information to the cloud.<br />
Your password will be MD5 encrypted locally and then transmitted to NetEase Music API.<br />
YesPlayMusic is not the official website of NetEase Music, please consider carefully before entering account information. You can also go to <a href="https://github.com/qier222/YesPlayMusic">YesPlayMusic's GitHub repository</a> to build and use the self-hosted NetEase Music API.`,
Expand Down
8 changes: 8 additions & 0 deletions src/locale/lang/tr.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ export default {
login: 'Giriş Yap',
loginWithEmail: 'Email ile giriş yap',
loginWithPhone: 'Phone ile giriş yap',
webLogin: 'Web ile giriş yap',
openWebLogin: 'NetEase web girişini aç',
webLoginTip:
'NetEase sayfasında giriş yaptıktan sonra sayfanın Cookie bilgisini kopyalayıp aşağıya yapıştır.',
cookiePlaceholder:
'MUSIC_U=...; __csrf=... gibi NetEase Cookie bilgisini yapıştır',
cookieTip:
'MUSIC_U gereklidir. Cookie yalnızca bu tarayıcıda ve localStorage içinde saklanır.',
notice: `YesPlayMusic hesabınızın hiçbir bilgisini kaydetmeyeceğine dair söz veriyor<br />
Şifren MD5 şifreleme ile yerel olarak şifrelenir ve daha sonra NetEase Müzik API'sine gönderilir<br />
YesPlayMusic, NetEase Music'in resmi websitesi değildir, lütfen hesap bilgilerinizi girmeden önce dikkatlice düşününüz. Aynı zamanda, Kendi NetEase Musix API'nızı host etmek için <a href="https://github.com/qier222/YesPlayMusic">YesPlayMusic'in GitHub Repo'suna</a> gidebilirsiniz.`,
Expand Down
6 changes: 6 additions & 0 deletions src/locale/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ export default {
login: '登录',
loginWithEmail: '邮箱登录',
loginWithPhone: '手机号登录',
webLogin: '网页登录',
openWebLogin: '打开网易云网页登录',
webLoginTip:
'在打开的网易云页面完成登录后,复制该页面的 Cookie 并粘贴到下方。',
cookiePlaceholder: '粘贴 MUSIC_U=...; __csrf=... 等网易云 Cookie',
cookieTip: '至少需要 MUSIC_U。Cookie 只会保存在本机浏览器和 localStorage。',
notice: `YesPlayMusic 承诺不会保存你的任何账号信息到云端。<br />
你的密码会在本地进行 MD5 加密后再传输到网易云 API。<br />
YesPlayMusic 并非网易云官方网站,输入账号信息前请慎重考虑。 你也可以前往
Expand Down
6 changes: 6 additions & 0 deletions src/locale/lang/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export default {
login: '登入',
loginWithEmail: '信箱登入',
loginWithPhone: '手機號碼登入',
webLogin: '網頁登入',
openWebLogin: '打開網易雲網頁登入',
webLoginTip:
'在打開的網易雲頁面完成登入後,複製該頁面的 Cookie 並貼到下方。',
cookiePlaceholder: '貼上 MUSIC_U=...; __csrf=... 等網易雲 Cookie',
cookieTip: '至少需要 MUSIC_U。Cookie 只會保存在本機瀏覽器和 localStorage。',
notice: `YesPlayMusic 承諾不會保存您的任何帳戶資訊到雲端。<br />
您的密碼會在本地進行 MD5 加密後再傳輸到網易雲 API。<br />
YesPlayMusic 並非網易雲官方網站,輸入帳戶資訊前請慎重考慮。 您也可以前往
Expand Down
16 changes: 9 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ console.log(
'background:unset;color:unset;'
);

Vue.use(
VueGtag,
{
config: { id: 'G-KMJJCFZDKF' },
},
router
);
if (process.env.NODE_ENV === 'production') {
Vue.use(
VueGtag,
{
config: { id: 'G-KMJJCFZDKF' },
},
router
);
}
Vue.config.productionTip = false;

NProgress.configure({ showSpinner: false, trickleSpeed: 100 });
Expand Down
Loading