Skip to content

Commit

Permalink
get localmusic lyrics and cover on runtime (#1104)
Browse files Browse the repository at this point in the history
* get localmusic lyrics and cover on runtime
up deps

* up pnpm version in ci

* fix tsc

* pass ci

* fix read img

* chore: up deps
  • Loading branch information
mikelxk authored Jun 21, 2023
1 parent 359a72a commit 56b4a6e
Show file tree
Hide file tree
Showing 21 changed files with 1,290 additions and 760 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/Extension Check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8
- uses: actions/setup-node@v3
with:
node-version: 16
Expand All @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8
- uses: actions/setup-node@v3
with:
node-version: 16
Expand All @@ -50,7 +50,7 @@ jobs:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8
- uses: actions/setup-node@v3
with:
node-version: 16
Expand All @@ -68,7 +68,7 @@ jobs:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8
- uses: actions/setup-node@v3
with:
node-version: 16
Expand Down
8 changes: 3 additions & 5 deletions electron_src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ipcMain.on('setCookie', async (e, cookie) => {
ipcMain.handle('getCookie', async (e, request) => {
return session.defaultSession.cookies.get(request);
});

ipcMain.handle('readTag', async (e, fp) => readAudioTags(fp));
ipcMain.on('removeCookie', async (e, url, name) => {
await session.defaultSession.cookies.remove(url, name);
});
Expand Down Expand Up @@ -269,7 +269,6 @@ ipcMain.on('chooseLocalFile', async (event, listId) => {
const tracks = [];
for (const fp of result.filePaths) {
const md = await readAudioTags(fp);
const imgBase64 = md.common.picture?.[0]?.data?.toString('base64');
const track = {
id: `lmtrack_${fp}`,
title: md.common.title,
Expand All @@ -278,9 +277,7 @@ ipcMain.on('chooseLocalFile', async (event, listId) => {
album: md.common.album,
album_id: `lmalbum_${md.common.album}`,
source: 'localmusic',
source_url: '',
img_url: imgBase64 ? `data:${md.common.picture?.[0].format};base64,${imgBase64}` : 'images/mycover.jpg',
lyrics: md.common.lyrics,
source_url: fp,
// url: "lmtrack_"+fp,
sound_url: `file://${fp}`,
bitrate: `${(md.format.bitrate / 1000).toFixed(0)}kbps`
Expand All @@ -290,6 +287,7 @@ ipcMain.on('chooseLocalFile', async (event, listId) => {

mainWindow.webContents.send('chooseLocalFile', { tracks, id: listId });
});

ipcMain.on('updateTheme', (event, { color, symbolColor }) => {
mainWindow.setTitleBarOverlay({ color, symbolColor, height: 50 });
});
Expand Down
2 changes: 2 additions & 0 deletions electron_src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const sendControl = (args, params) => ipcRenderer.send('control', args, params);
const sendLyric = (args, params) => ipcRenderer.send('currentLyric', args, params);
const sendTrackPlayingNow = (args, params) => ipcRenderer.send('trackPlayingNow', args, params);
const sendFloatWindowMoving = (args, params) => ipcRenderer.send('floatWindowMoving', args, params);
const readTag = (fp) => ipcRenderer.invoke('readTag', fp);
const onLyric = (fn) => {
ipcRenderer.on('currentLyric', (event, ...args) => fn(...args));
};
Expand All @@ -46,6 +47,7 @@ contextBridge.exposeInMainWorld('api', {
session,
ipcRenderer,
platform: process.platform,
readTag,
onLyric,
onTranslLyric,
onLyricWindow,
Expand Down
7 changes: 5 additions & 2 deletions electron_src/readtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const { basename, extname, parse, format } = require('path');

module.exports = {
async readAudioTags(filePath) {
const { detect } = require('chardet');
const { parseFile } = require('music-metadata');
const { detect } = await import('chardet');
const { parseFile } = await import('music-metadata');
const fileName = basename(filePath, extname(filePath));
try {
const metaData = await parseFile(filePath);
Expand All @@ -15,6 +15,9 @@ module.exports = {
ext: '.lrc',
base: undefined
});
const imgBase64 = metaData.common?.picture?.[0]?.data?.toString('base64');
const img_url = imgBase64 ? `data:${metaData.common.picture?.[0].format};base64,${imgBase64}` : 'images/mycover.jpg';
metaData.common.img_url = img_url;
//if metadata doesn't include lyric, then try to read from local lyric file
if (!metaData.common.lyrics && existsSync(lyric_url)) {
metaData.common.lyrics = [];
Expand Down
53 changes: 28 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "listen1_chrome_extension",
"version": "3.0.0",
"private": false,
"packageManager": "pnpm@7.12.0",
"packageManager": "pnpm@8.6.0",
"scripts": {
"build": "vite build",
"build:mv3": "cross-env mv3=1 vite build",
Expand All @@ -19,38 +19,38 @@
},
"description": "one for all free music in china",
"devDependencies": {
"@intlify/vite-plugin-vue-i18n": "^6.0.3",
"@types/chrome": "^0.0.203",
"@types/node-forge": "^1.3.1",
"@types/serviceworker": "^0.0.57",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"@vitejs/plugin-vue": "^3.2.0",
"autoprefixer": "^10.4.13",
"axios": "^1.2.0",
"@intlify/unplugin-vue-i18n": "^0.11.0",
"@types/chrome": "^0.0.237",
"@types/node-forge": "^1.3.2",
"@types/serviceworker": "^0.0.67",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@vitejs/plugin-vue": "^4.2.3",
"autoprefixer": "^10.4.14",
"axios": "^1.4.0",
"cross-env": "^7.0.3",
"dexie": "^3.2.2",
"electron": "21.3.1",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-vue": "^9.8.0",
"dexie": "^3.2.4",
"electron": "22.3.12",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-vue": "^9.14.1",
"feather-icons": "^4.29.0",
"mitt": "^3.0.0",
"node-forge": "^1.3.1",
"notyf": "^3.10.0",
"postcss": "^8.4.19",
"prettier": "^2.8.0",
"prettier-plugin-tailwindcss": "^0.2.0",
"postcss": "^8.4.24",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.3.0",
"rollup-plugin-chrome-extension": "3.6.6",
"tailwindcss": "^3.2.4",
"typescript": "^4.9.3",
"vite": "^3.2.4",
"tailwindcss": "^3.3.2",
"typescript": "^5.1.3",
"vite": "^4.3.9",
"vite-plugin-zip": "^1.0.1",
"vue": "^3.2.45",
"vue": "^3.3.4",
"vue-feather": "^2.0.0",
"vue-i18n": "^9.2.2",
"vue-router": "^4.1.6",
"vue-tsc": "1.0.9"
"vue-router": "^4.2.2",
"vue-tsc": "1.6.5"
},
"browserslist": [
"last 8 chrome versions",
Expand All @@ -69,5 +69,8 @@
"bugs": {
"url": "https://github.com/listen1/listen1_chrome_extension/issues"
},
"homepage": "https://github.com/listen1/listen1_chrome_extension#readme"
"homepage": "https://github.com/listen1/listen1_chrome_extension#readme",
"dependencies": {
"music-metadata-browser": "^2.5.10"
}
}
Loading

0 comments on commit 56b4a6e

Please sign in to comment.