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",
|
||||
"location-history": "^1.0.0",
|
||||
"material-ui": "^0.17.0",
|
||||
"mime": "^2.0.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"musicmetadata": "^2.0.2",
|
||||
"music-metadata": "^0.8.4",
|
||||
"network-address": "^1.1.0",
|
||||
"parse-torrent": "^5.7.3",
|
||||
"prettier-bytes": "^1.0.1",
|
||||
|
||||
@@ -206,23 +206,42 @@ function renderOverlay (state) {
|
||||
function renderAudioMetadata (state) {
|
||||
const fileSummary = state.getPlayingFileSummary()
|
||||
if (!fileSummary.audioInfo) return
|
||||
const info = fileSummary.audioInfo
|
||||
const common = fileSummary.audioInfo.common
|
||||
|
||||
// Get audio track info
|
||||
let title = info.title
|
||||
let title = common.title
|
||||
if (!title) {
|
||||
title = fileSummary.name
|
||||
}
|
||||
let artist = info.artist && info.artist[0]
|
||||
let album = info.album
|
||||
if (album && info.year && !album.includes(info.year)) {
|
||||
album += ' (' + info.year + ')'
|
||||
let artist = common.albumartist || common.artist ||
|
||||
(common.artists && common.artists.filter(function (a) { return a }).join(', ')) || '(Unknown Artist)'
|
||||
let album = common.album
|
||||
if (album && common.year && !album.includes(common.year)) {
|
||||
album += ' (' + common.year + ')'
|
||||
if (common.label) {
|
||||
album += ', ' + common.label
|
||||
}
|
||||
}
|
||||
let track
|
||||
if (info.track && info.track.no && info.track.of) {
|
||||
track = info.track.no + ' of ' + info.track.of
|
||||
if (common.track && common.track.no && common.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
|
||||
const elems = []
|
||||
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
|
||||
const emptyLabel = (<label />)
|
||||
elems.unshift((
|
||||
|
||||
@@ -7,8 +7,9 @@ const deepEqual = require('deep-equal')
|
||||
const defaultAnnounceList = require('create-torrent').announceList
|
||||
const electron = require('electron')
|
||||
const fs = require('fs')
|
||||
const mime = require('mime')
|
||||
const mkdirp = require('mkdirp')
|
||||
const musicmetadata = require('musicmetadata')
|
||||
const mm = require('music-metadata')
|
||||
const networkAddress = require('network-address')
|
||||
const path = require('path')
|
||||
const WebTorrent = require('webtorrent')
|
||||
@@ -334,15 +335,16 @@ function stopServer () {
|
||||
server = null
|
||||
}
|
||||
|
||||
console.log('Initializing...')
|
||||
|
||||
function getAudioMetadata (infoHash, index) {
|
||||
const torrent = client.get(infoHash)
|
||||
const file = torrent.files[index]
|
||||
musicmetadata(file.createReadStream(), function (err, info) {
|
||||
if (err) return console.log('error getting audio metadata for ' + infoHash + ':' + index, err)
|
||||
const { artist, album, albumartist, title, year, track, disk, genre } = info
|
||||
const importantInfo = { artist, album, albumartist, title, year, track, disk, genre }
|
||||
console.log('got audio metadata for %s: %o', file.name, importantInfo)
|
||||
ipc.send('wt-audio-metadata', infoHash, index, importantInfo)
|
||||
mm.parseStream(file.createReadStream(), mime.getType(file.name), {native: false, skipCovers: true}).then(function (metadata) {
|
||||
console.log('got audio metadata for %s: %o', file.name, metadata)
|
||||
ipc.send('wt-audio-metadata', infoHash, index, metadata)
|
||||
}).catch(function (err) {
|
||||
return console.log('error getting audio metadata for ' + infoHash + ':' + index, err)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user