some test

This commit is contained in:
vapormusic 2022-06-30 22:34:00 +07:00
parent f0ceaae958
commit d872087685
4 changed files with 30 additions and 9 deletions

View file

@ -68,11 +68,13 @@
"node-ssdp": "^4.0.1",
"pouchdb-adapter-leveldb": "^7.3.0",
"pouchdb-node": "^7.3.0",
"pouchdb-upsert": "^2.2.0",
"qrcode": "^1.5.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"run-script-os": "^1.1.6",
"source-map-support": "^0.5.21",
"ts-md5": "^1.2.11",
"v8-compile-cache": "^2.3.0",
"wallpaper": "5.0.1",
"ws": "^8.5.0",

View file

@ -1185,6 +1185,8 @@ export class BrowserWindow {
ipcMain.handle("scanLibrary", async (event, folders) => {
const oldmetadatalist = await LocalFiles.sendOldLibrary()
BrowserWindow.win.webContents.send('getUpdatedLocalList', oldmetadatalist);
const metadatalist = await LocalFiles.scanLibrary()
BrowserWindow.win.webContents.send('getUpdatedLocalList', metadatalist);
})

View file

@ -1,8 +1,12 @@
import * as PouchDB from 'pouchdb-node';
import {join} from 'path';
import {app} from "electron";
PouchDB.plugin(require('pouchdb-upsert'));
export class ProviderDB {
public static db: any = null
static async init() {
// ProviderDB.db = new PouchDB('tracks')
static init() {
if (ProviderDB.db == null){
ProviderDB.db = new PouchDB(join(app.getPath('userData'), 'tracksdb'))
}
}
}

View file

@ -1,16 +1,26 @@
// import { ProviderDB } from "./db";
import { ProviderDB } from "./db";
import * as path from 'path';
const { readdir } = require('fs').promises;
import { utils } from '../../base/utils';
import * as mm from 'music-metadata';
import {Md5} from 'ts-md5/dist/md5';
export class LocalFiles {
static localSongs: any = [];
static localSongsArts: any = [];
// public static DB = ProviderDB.db;
public static DB = ProviderDB.db;
static async sendOldLibrary() {
ProviderDB.init()
let u = (await ProviderDB.db.allDocs({include_docs: true,
attachments: true})).rows.map((item: any)=>{return item.doc})
this.localSongs = u;
console.log('sdadad', u.length)
return u;
}
static async scanLibrary() {
ProviderDB.init()
let folders = utils.getStoreValue("libraryPrefs.localPaths")
if (folders == null || folders.length == null || folders.length == 0) folders = ["D:\\Music"]
console.log('folders', folders)
@ -30,16 +40,18 @@ export class LocalFiles {
for (var audio of audiofiles) {
try {
const metadata = await mm.parseFile(audio);
let lochash = Md5.hashStr(audio) ?? numid;
if (metadata != null) {
let form = {
"id": "ciderlocal" + numid,
"id": "ciderlocal" + lochash,
"_id": "ciderlocal" + lochash,
"type": "podcast-episodes",
"href": audio,
"attributes": {
"artwork": {
"width": 3000,
"height": 3000,
"url": "/ciderlocalart/" + "ciderlocal" + numid,
"url": "/ciderlocalart/" + "ciderlocal" + lochash,
},
"topics": [],
"url": "",
@ -74,10 +86,11 @@ export class LocalFiles {
}
};
metadatalistart.push({
id: "ciderlocal" + numid,
id: "ciderlocal" + lochash,
url: metadata.common.picture != undefined ? metadata.common.picture[0].data.toString('base64') : "",
})
numid += 1;
ProviderDB.db.putIfNotExists(form)
metadatalist.push(form)
}
} catch (e) { }