Skip to content

Commit

Permalink
Merge pull request #62 from deenine/rh1-upload
Browse files Browse the repository at this point in the history
PoC Download function
  • Loading branch information
gavinbenda committed Nov 16, 2020
2 parents 9c17150 + 937ad73 commit 76653b8
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 98 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -9,4 +9,5 @@ npm-debug.log
npm-debug.log.*
thumbs.db
!.gitkeep
design-files
design-files
resources/netmd-py/*.pyc
26 changes: 21 additions & 5 deletions package.json
Expand Up @@ -56,6 +56,13 @@
"filter": [
"**/*"
]
},
{
"from": "resources/netmd-py",
"to": "Resources/netmd-py",
"filter": [
"**/*"
]
}
]
},
Expand All @@ -68,6 +75,13 @@
"filter": [
"**/*"
]
},
{
"from": "resources/netmd-py",
"to": "Resources/netmd-py",
"filter": [
"**/*"
]
}
]
},
Expand All @@ -94,20 +108,22 @@
"bootstrap": "^4.3.1",
"bootstrap-vue": "^2.0.2",
"electron-store": "^4.0.0",
"eslint-plugin-vue": "^6.2.2",
"ffi-napi": "^2.3.0",
"ffmpeg-static-electron": "^2.0.1",
"file-type": "^12.1.0",
"fluent-ffmpeg": "^2.1.2",
"fs-extra": "^8.0.0",
"jquery": "^3.5.0",
"music-metadata": "^6.3.7",
"python-shell": "^2.0.2",
"read-chunk": "^3.2.0",
"usb-detection": "^4.10.0",
"vue": "^2.5.16",
"vue-electron": "^1.0.6",
"vue-router": "^3.0.1",
"vuex": "^3.0.1",
"vuex-electron": "^1.0.0",
"fs-extra": "^8.0.0"
"vuex-electron": "^1.0.0"
},
"devDependencies": {
"@fortawesome/fontawesome-free": "^5.10.1",
Expand All @@ -121,15 +137,15 @@
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"cfonts": "^2.1.2",
"cfonts": "^2.8.6",
"chai": "^4.1.2",
"chalk": "^2.4.1",
"chalk": "^2.4.2",
"copy-webpack-plugin": "^4.5.1",
"cross-env": "^5.1.6",
"css-loader": "^0.28.11",
"del": "^5.1.0",
"devtron": "^1.4.0",
"electron": "^2.0.4",
"electron": "^2.0.18",
"electron-builder": "^22.4.1",
"electron-debug": "^1.5.0",
"electron-devtools-installer": "^2.2.4",
Expand Down
Binary file modified resources/mac/bin/netmdcli
Binary file not shown.
Binary file added resources/win/bin/libusb-1.0-64.dll
Binary file not shown.
4 changes: 3 additions & 1 deletion src/renderer/binaries.js
Expand Up @@ -8,10 +8,12 @@ const IS_PROD = process.env.NODE_ENV === 'production'
const root = process.cwd()
const { getAppPath } = remote.app

export const platform = getPlatform()

const binariesPath =
IS_PROD
? path.join(path.dirname(getAppPath()), '..', './Resources', './bin')
: path.join(root, './resources', getPlatform(), './bin')
: path.join(root, './resources', platform, './bin')

export const atracdencPath = path.resolve(path.join(binariesPath, './atracdenc'))
export const ffmpegPath = path.resolve(path.join(binariesPath, './ffmpeg'))
Expand Down
56 changes: 56 additions & 0 deletions src/renderer/common.js
@@ -0,0 +1,56 @@
const fs = require('fs-extra')
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path.replace('app.asar', 'app.asar.unpacked')
const ffmpeg = require('fluent-ffmpeg')
ffmpeg.setFfmpegPath(ffmpegPath)

/**
* Convert audio file to WAV file using ffmpeg
* This MUST be 44100 and 16bit for the atrac encoder to work
*/
export async function convertAudio (source, dest, format) {
return new Promise(async (resolve, reject) => {
// Start conversion
var codec = ['-acodec', 'pcm_s16le']
console.log('Starting WAV conversion process using ffmpeg: ' + source + ' --> ' + dest)
switch (format) {
case ('FLAC'):
codec = ['-acodec', 'flac']
break
case ('MP3'):
codec = ['-acodec', 'mp3', '-b:a', '320k']
break
}
ffmpeg(source)
.output(dest)
.outputOption(codec)
.audioFrequency(44100)
.on('start', function (commandLine) {
console.log('Spawned Ffmpeg with command: ', commandLine)
})
.on('progress', function (progress) {
console.log('Processing: ' + progress.timemark + ' done ' + progress.targetSize + ' kilobytes')
})
// If successful, resolve
.on('end', function () {
console.log('ffmpeg completed successfully')
resolve()
})
// Reject if we get any errors
.on('error', function (err) {
console.log('ffmpeg error: ' + err.message)
reject(err.message)
})
.run()
})
}

/**
* Make sure temp directory actually exists, if not create it
*/
export function ensureDirSync (dirpath) {
try {
fs.mkdirSync(dirpath, { recursive: true })
} catch (err) {
if (err.code !== 'EEXIST') throw err
}
}
54 changes: 53 additions & 1 deletion src/renderer/components/LandingPage.vue
Expand Up @@ -15,6 +15,21 @@
<hr />
<b-form-checkbox type="checkbox" name="sonicstage-titles" id="sonicstage-titles" v-model="sonicStageNosStrip">Strip SonicStage track numbers from titles (e.g 001-Title)</b-form-checkbox>
<hr />
<template v-if=rh1>
<b>RH1 Download Options</b>
<b-form-group label="Save downloaded tracks as:">
<b-form-radio v-model="downloadFormat" name="WAV" value="WAV">WAV</b-form-radio>
<b-form-radio v-model="downloadFormat" name="FLAC" value="FLAC">FLAC</b-form-radio>
<b-form-radio v-model="downloadFormat" name="MP3" value="MP3">MP3 (320kbs)</b-form-radio>
<b-form-radio v-model="downloadFormat" name="RAW" value="RAW">AEA/AT3 (Do not convert audio)</b-form-radio>
</b-form-group>
<b-form-checkbox type="checkbox" name="use-sonicstage-nos" id="use-sonicstage-nos" v-model="useSonicStageNos">Save tracks with SonicStage style track numbers (e.g 001-Title)</b-form-checkbox>
<br>
<p>Download directory: {{ downloadDir }}</p>
<b-button variant="outline-primary" @click="chooseDownloadDir">Browse <font-awesome-icon icon="folder-open"></font-awesome-icon></b-button>
<hr />
</template>

<b-button variant="outline-primary" @click="showDebugConsole">Debug Window</b-button>
</b-modal>

Expand Down Expand Up @@ -44,7 +59,9 @@
import DirectoryListing from './LandingPage/DirectoryListing'
import NetMdListing from './LandingPage/NetMdListing'
import ControlBar from './LandingPage/ControlBar'
import path from 'path'
const { remote } = require('electron')
const homedir = require('os').homedir()
const Store = require('electron-store')
const store = new Store()
export default {
Expand All @@ -54,12 +71,23 @@
return {
conversionMode: 'SP',
titleFormat: '%title% - %artist%',
sonicStageNosStrip: true
sonicStageNosStrip: true,
useSonicStageNos: true,
rh1: false,
downloadFormat: 'FLAC',
downloadDir: homedir + '/pmd-music/'
}
},
created () {
this.readConfig()
},
mounted () {
bus.$on('netmd-status', (data) => {
if ('deviceName' in data) {
this.rh1 = (data.deviceName === 'Sony MZ-RH1')
}
})
},
methods: {
/**
* Rename track modal
Expand All @@ -74,6 +102,9 @@
store.set('conversionMode', this.conversionMode)
store.set('titleFormat', this.titleFormat)
store.set('sonicStageNosStrip', this.sonicStageNosStrip)
store.set('useSonicStageNos', this.useSonicStageNos)
store.set('downloadFormat', this.downloadFormat)
store.set('downloadDir', this.downloadDir)
bus.$emit('config-update')
},
/**
Expand All @@ -89,12 +120,33 @@
if (store.has('sonicStageNosStrip')) {
this.sonicStageNosStrip = store.get('sonicStageNosStrip')
}
if (store.has('useSonicStageNos')) {
this.useSonicStageNos = store.get('useSonicStageNos')
}
if (store.has('downloadFormat')) {
this.downloadFormat = store.get('downloadFormat')
}
if (store.has('downloadDir')) {
this.downloadFormat = store.get('downloadDir')
}
},
/**
* Show debug console
*/
showDebugConsole: function () {
remote.getCurrentWindow().webContents.openDevTools()
},
chooseDownloadDir: function () {
remote.dialog.showOpenDialog({
properties: ['openDirectory'],
defaultPath: this.downloadDir
}, names => {
if (names != null) {
console.log('selected download directory:' + names[0])
store.set('downloadDir', names[0] + path.sep)
this.downloadDir = store.get('downloadDir')
}
})
}
}
}
Expand Down

0 comments on commit 76653b8

Please sign in to comment.