Add audio format information to play screen.
Extended album information with release lebel if available. Make use of music-metadata module (musicmetadata appears to be no longer maintained)
This commit is contained in:
@@ -30,8 +30,9 @@
|
|||||||
"languagedetect": "^1.1.1",
|
"languagedetect": "^1.1.1",
|
||||||
"location-history": "^1.0.0",
|
"location-history": "^1.0.0",
|
||||||
"material-ui": "^0.17.0",
|
"material-ui": "^0.17.0",
|
||||||
|
"mime": "^2.0.1",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"musicmetadata": "^2.0.2",
|
"music-metadata": "^0.8.4",
|
||||||
"network-address": "^1.1.0",
|
"network-address": "^1.1.0",
|
||||||
"parse-torrent": "^5.7.3",
|
"parse-torrent": "^5.7.3",
|
||||||
"prettier-bytes": "^1.0.1",
|
"prettier-bytes": "^1.0.1",
|
||||||
|
|||||||
@@ -206,23 +206,42 @@ function renderOverlay (state) {
|
|||||||
function renderAudioMetadata (state) {
|
function renderAudioMetadata (state) {
|
||||||
const fileSummary = state.getPlayingFileSummary()
|
const fileSummary = state.getPlayingFileSummary()
|
||||||
if (!fileSummary.audioInfo) return
|
if (!fileSummary.audioInfo) return
|
||||||
const info = fileSummary.audioInfo
|
const common = fileSummary.audioInfo.common
|
||||||
|
|
||||||
// Get audio track info
|
// Get audio track info
|
||||||
let title = info.title
|
let title = common.title
|
||||||
if (!title) {
|
if (!title) {
|
||||||
title = fileSummary.name
|
title = fileSummary.name
|
||||||
}
|
}
|
||||||
let artist = info.artist && info.artist[0]
|
let artist = common.albumartist || common.artist ||
|
||||||
let album = info.album
|
(common.artists && common.artists.filter(function (a) { return a }).join(', ')) || '(Unknown Artist)'
|
||||||
if (album && info.year && !album.includes(info.year)) {
|
let album = common.album
|
||||||
album += ' (' + info.year + ')'
|
if (album && common.year && !album.includes(common.year)) {
|
||||||
|
album += ' (' + common.year + ')'
|
||||||
|
if (common.label) {
|
||||||
|
album += ', ' + common.label
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let track
|
let track
|
||||||
if (info.track && info.track.no && info.track.of) {
|
if (common.track && common.track.no && common.track.of) {
|
||||||
track = info.track.no + ' of ' + info.track.of
|
track = common.track.no + ' of ' + common.track.of
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let format = []
|
||||||
|
if (fileSummary.audioInfo.format.dataformat) {
|
||||||
|
format.push(fileSummary.audioInfo.format.dataformat)
|
||||||
|
}
|
||||||
|
if (fileSummary.audioInfo.format.bitrate) {
|
||||||
|
format.push(fileSummary.audioInfo.format.bitrate / 1000 + ' kbps')
|
||||||
|
}
|
||||||
|
if (fileSummary.audioInfo.format.sampleRate) {
|
||||||
|
format.push(fileSummary.audioInfo.format.sampleRate / 1000 + ' kHz')
|
||||||
|
}
|
||||||
|
if (fileSummary.audioInfo.format.bitsPerSample) {
|
||||||
|
format.push(fileSummary.audioInfo.format.bitsPerSample + ' bit')
|
||||||
|
}
|
||||||
|
format = format.join(', ')
|
||||||
|
|
||||||
// Show a small info box in the middle of the screen with title/album/etc
|
// Show a small info box in the middle of the screen with title/album/etc
|
||||||
const elems = []
|
const elems = []
|
||||||
if (artist) {
|
if (artist) {
|
||||||
@@ -247,6 +266,14 @@ function renderAudioMetadata (state) {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (format) {
|
||||||
|
elems.push((
|
||||||
|
<div key='format' className='audio-format'>
|
||||||
|
<label>Format</label>{format}
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
// Align the title with the other info, if available. Otherwise, center title
|
// Align the title with the other info, if available. Otherwise, center title
|
||||||
const emptyLabel = (<label />)
|
const emptyLabel = (<label />)
|
||||||
elems.unshift((
|
elems.unshift((
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ const deepEqual = require('deep-equal')
|
|||||||
const defaultAnnounceList = require('create-torrent').announceList
|
const defaultAnnounceList = require('create-torrent').announceList
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const mime = require('mime')
|
||||||
const mkdirp = require('mkdirp')
|
const mkdirp = require('mkdirp')
|
||||||
const musicmetadata = require('musicmetadata')
|
const mm = require('music-metadata')
|
||||||
const networkAddress = require('network-address')
|
const networkAddress = require('network-address')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const WebTorrent = require('webtorrent')
|
const WebTorrent = require('webtorrent')
|
||||||
@@ -334,15 +335,16 @@ function stopServer () {
|
|||||||
server = null
|
server = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Initializing...')
|
||||||
|
|
||||||
function getAudioMetadata (infoHash, index) {
|
function getAudioMetadata (infoHash, index) {
|
||||||
const torrent = client.get(infoHash)
|
const torrent = client.get(infoHash)
|
||||||
const file = torrent.files[index]
|
const file = torrent.files[index]
|
||||||
musicmetadata(file.createReadStream(), function (err, info) {
|
mm.parseStream(file.createReadStream(), mime.getType(file.name), {native: false, skipCovers: true}).then(function (metadata) {
|
||||||
if (err) return console.log('error getting audio metadata for ' + infoHash + ':' + index, err)
|
console.log('got audio metadata for %s: %o', file.name, metadata)
|
||||||
const { artist, album, albumartist, title, year, track, disk, genre } = info
|
ipc.send('wt-audio-metadata', infoHash, index, metadata)
|
||||||
const importantInfo = { artist, album, albumartist, title, year, track, disk, genre }
|
}).catch(function (err) {
|
||||||
console.log('got audio metadata for %s: %o', file.name, importantInfo)
|
return console.log('error getting audio metadata for ' + infoHash + ':' + index, err)
|
||||||
ipc.send('wt-audio-metadata', infoHash, index, importantInfo)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user