Skip to content

Commit

Permalink
Add MP3 support in NWJS
Browse files Browse the repository at this point in the history
  • Loading branch information
asivery committed Sep 30, 2024
1 parent 39cfdab commit 4041465
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
"electron-context-menu": "^3.6.1",
"electron-prompt": "^1.7.0",
"electron-store": "^8.1.0",
"himd-js": "^0.2.0-alpha.5",
"himd-js": "^0.2.0",
"jconv": "^0.1.5",
"jsbi": "^3.2.5",
"msgpackr": "^1.9.5",
"netmd-exploits": "^0.5.4",
"netmd-js": "^4.2.0",
"networkwm-js": "^0.1.0",
"netmd-tocmanip": "^0.1.5",
"networkwm-js": "^0.1.0",
"node-fetch": "^2.6.7",
"nufatfs": "^0.1.3",
"sudo-prompt": "^9.2.1",
Expand Down
2 changes: 0 additions & 2 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ export const CHANGELOG: ChangelogVersionInjection[] = [
args[i] = { interprocessType: 'function' };
}
}
console.log(`Invoke ${name}`);
const [response, error] = await ipcRenderer.invoke(name, ...args);
console.log(`Invoke ${name} done`);
if (error) throw error;
return await response;
};
Expand Down
40 changes: 30 additions & 10 deletions src/wmd/networkwm-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DeviceStatus, DiscFormat, TrackFlag } from "netmd-js";
import { Capability, Codec, Disc, Group, MinidiscSpec, NetMDService, RecordingCodec, TitleParameter, Track } from "./original/services/interfaces/netmd";
import { DatabaseManager, SonyVendorNWJSUSMCDriver, UMSCNWJSSession, createNWJSFS, openNewDeviceNode, importKeys, initCrypto, resolvePathFromGlobalIndex, TrackMetadata, flatten, DeviceIds } from 'networkwm-js';
import { DatabaseManager, SonyVendorNWJSUSMCDriver, UMSCNWJSSession, createNWJSFS, importKeys, initCrypto, resolvePathFromGlobalIndex, TrackMetadata, flatten, DeviceIds, DeviceDefinition, findDevice } from 'networkwm-js';
import { HiMDKBPSToFrameSize, UMSCHiMDFilesystem, generateCodecInfo } from "himd-js";
import nodeFs from 'fs';
import { AbstractedTrack, DatabaseAbstraction } from "networkwm-js/dist/database-abstraction";
Expand Down Expand Up @@ -109,15 +109,20 @@ export class NetworkWMService extends NetMDService {
}
await initCrypto();
importKeys(this.keyData);
let legacyDevice: any, vendorId, productId, name;
for({ vendorId, productId, name } of DeviceIds){
let legacyDevice: any;
let matchedDevice: DeviceDefinition | null = null;
for(const dev of DeviceIds){
const { vendorId, productId, name } = dev;
legacyDevice = findByIds(vendorId, productId);
if(legacyDevice) break;
if(legacyDevice) {
matchedDevice = dev;
break;
}
}
if(!legacyDevice) return false;

if(['darwin', 'linux'].includes(process.platform)){
await unmountAll(vendorId, productId);
await unmountAll(matchedDevice.vendorId, matchedDevice.productId);
}

legacyDevice.open();
Expand All @@ -134,9 +139,12 @@ export class NetworkWMService extends NetMDService {

this.deviceConnectedCallback?.(legacyDevice, webUsbDevice);

const fs = await createNWJSFS(webUsbDevice, bypassCoherencyChecks);
this.database = await DatabaseAbstraction.create(fs);
this.name = name;
const fs = await createNWJSFS({
dev: webUsbDevice,
definition: matchedDevice,
});
this.database = await DatabaseAbstraction.create(fs, matchedDevice);
this.name = matchedDevice.name;
return true;
}

Expand Down Expand Up @@ -234,6 +242,20 @@ export class NetworkWMService extends NetMDService {
artist?: string;
};

if(format.codec === 'MP3') {
this.cache = null;
return this.database.uploadMP3Track(
{
artist: artist ?? 'Unknown Artist',
album: album ?? 'Unknown Album',
genre: 'Genre',
title: title ?? 'Unknown Title',
},
new Uint8Array(data),
(done, outOf) => progressCallback({ written: done, encrypted: outOf, total: outOf })
);
}

const codecFrameSizeFamily = format.codec === 'A3+' ? HiMDKBPSToFrameSize.atrac3plus : HiMDKBPSToFrameSize.atrac3;
if(format.codec !== 'A3+' && format.codec !== 'AT3') throw new Error("Invalid format!");
const codecInfo = generateCodecInfo(format.codec, codecFrameSizeFamily[format.bitrate!]);
Expand All @@ -244,8 +266,6 @@ export class NetworkWMService extends NetMDService {
album: album ?? 'Unknown Album',
genre: 'Genre',
title: title ?? 'Unknown Title',
trackDuration: -1,
trackNumber: -1, // Assume last of album and artist
}, codecInfo,
new Uint8Array(data),
this.session,
Expand Down

0 comments on commit 4041465

Please sign in to comment.