Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix playing back audio files & reading music metadata #1240

Merged
merged 24 commits into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8868128
Add audio format information to play screen.
Borewit Sep 17, 2017
83350b3
Add catalognumber in addition of the release label.
Borewit Sep 17, 2017
6aa3a6c
Fix lint errors
Borewit Sep 17, 2017
54e1564
Fix max line length
Borewit Sep 17, 2017
52e16c3
Fix lint error
Borewit Sep 17, 2017
c11a86d
Fix max line length
Borewit Sep 17, 2017
0f00985
Eliminated mime dependency
Borewit Sep 20, 2017
f56f3c6
Update version of dependency music-metadata to 0.8.8
Borewit Feb 4, 2018
30c9934
Update version of dependency music-metadata to 0.9.0
Borewit Feb 4, 2018
bc91cde
Merge branch 'master' into music-metadata
Borewit Feb 5, 2018
0cce110
Fix bug #1320 by update music-metadata.
Borewit Feb 5, 2018
ba1f82f
Use direct file access, if the individual file has completed download…
Borewit Feb 5, 2018
d5a62cb
Add additional audio extensions: 'aiff', 'ape', 'mp2', 'oga', 'opus',…
Borewit Feb 6, 2018
070d3ff
Update music-metadata dependency to 0.9.2
Borewit Feb 6, 2018
23d37d7
Merge branch 'master' into music-metadata
Borewit Feb 19, 2018
0572f8a
Update music-metadata dependency to 0.9.4.
Borewit Feb 19, 2018
e5a64d9
Add comments to metadata media overlay.
Borewit Feb 19, 2018
a725726
Fix formatting according 'standard'
Borewit Feb 19, 2018
c720f65
Update dependency music-metadata to version 0.9.5
Borewit Feb 24, 2018
fce0003
Add audio metadata standalone entries for: year & release information
Borewit Feb 24, 2018
3dcab9e
Fix audio format metadata
Borewit Feb 24, 2018
34463d9
Enforce music-metadata version which is able to deal with bad Ogg files
Borewit Mar 3, 2018
9b74602
Fixed the win32 version of the test-integration/test-audio: updated s…
Borewit Mar 4, 2018
bd2fbe6
Pass file length parameter to music-metadata parser.
Borewit Mar 11, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"location-history": "^1.0.0",
"material-ui": "^0.17.0",
"mkdirp": "^0.5.1",
"musicmetadata": "^2.0.2",
"music-metadata": "^0.9.8",
"network-address": "^1.1.0",
"parse-torrent": "^5.7.3",
"prettier-bytes": "^1.0.1",
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/lib/torrent-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ function isVideo (file) {
function isAudio (file) {
return [
'.aac',
'.aiff',
'.ape',
'.ac3',
'.flac',
'.m4a',
'.mp2',
'.mp3',
'.oga',
'.ogg',
'.opus',
'.wav',
'.flac',
'.m4a'
'.wma'
].includes(getFileExtension(file))
}

Expand Down
88 changes: 71 additions & 17 deletions src/renderer/pages/player-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,47 +207,101 @@ 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
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 track
if (info.track && info.track.no && info.track.of) {
track = info.track.no + ' of ' + info.track.of
}
const title = common.title ? common.title : fileSummary.name

// Show a small info box in the middle of the screen with title/album/etc
const elems = []

// Audio metadata: artist(s)
const artist = common.albumartist || common.artist ||
(common.artists && common.artists.filter(function (a) { return a }).join(', ')) ||
'(Unknown Artist)'
if (artist) {
elems.push((
<div key='artist' className='audio-artist'>
<label>Artist</label>{artist}
</div>
))
}
if (album) {

// Audio metadata: album
if (common.album) {
elems.push((
<div key='album' className='audio-album'>
<label>Album</label>{album}
<label>Album</label>{common.album}
</div>
))
}

// Audio metadata: year
if (common.year) {
elems.push((
<div key='year' className='audio-year'>
<label>Year</label>{common.year}
</div>
))
}

// Audio metadata: release information (label & catalog-number)
if (common.label || common.catalognumber) {
const releaseInfo = []
if (common.label) {
releaseInfo.push(common.label)
}
if (common.catalognumber) {
releaseInfo.push(common.catalognumber)
}
elems.push((
<div key='release' className='audio-release'>
<label>Release</label>{ releaseInfo.join(' / ') }
</div>
))
}
if (track) {

// Audio metadata: track-number
if (common.track && common.track.no && common.track.of) {
const track = common.track.no + ' of ' + common.track.of
elems.push((
<div key='track' className='audio-track'>
<label>Track</label>{track}
</div>
))
}

// Audio metadata: format
const 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')
}
if (format.length > 0) {
elems.push((
<div key='format' className='audio-format'>
<label>Format</label>{ format.join(', ') }
</div>
))
}

// Audio metadata: comments
if (common.comment) {
elems.push((
<div key='comments' className='audio-comments'>
<label>Comments</label>{common.comment.join(' / ')}
</div>
))
}

// Align the title with the other info, if available. Otherwise, center title
const emptyLabel = (<label />)
elems.unshift((
Expand Down
26 changes: 18 additions & 8 deletions src/renderer/webtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const defaultAnnounceList = require('create-torrent').announceList
const electron = require('electron')
const fs = require('fs')
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')
Expand Down Expand Up @@ -334,16 +334,26 @@ 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)
})

const options = {native: false, skipCovers: true}
const onMetaData = file.done
// If completed; use direct file access
? mm.parseFile(path.join(torrent.path, file.path), options)
// otherwise stream
: mm.parseStream(file.createReadStream(), file.name, options)

onMetaData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For MP3 files it seems like this promise is not resolved until the whole file is downloaded.
But the ID3 tags are already available.
Forcing onMetaData to be mm.parseFile(path.join(torrent.path, file.path), options) properly loads metadata on tested files.

We might need to check how ID3 tags are being read from the file.
I think we could load them before the full file is downloaded, at least on same cases.

Also, we might want to add a loading indication if we need to wait for the whole file to be downloaded to update the metadata.
Probable we can show the file name and an indication that metadata is being loading.

Cheers!

.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)
})
}

function selectFiles (torrentOrInfoHash, selections) {
Expand Down
7 changes: 6 additions & 1 deletion static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -820,12 +820,17 @@ video::-webkit-media-text-track-container {

.audio-metadata label {
display:inline-block;
width: 100px;
width: 120px;
text-align: right;
font-weight: normal;
margin-right: 25px;
}

.audio-metadata .audio-format,
.audio-metadata .audio-comments {
font-weight: normal;
}

/*
* ERRORS
*/
Expand Down
Binary file modified test/screenshots/win32/play-torrent-wired-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/screenshots/win32/play-torrent-wired-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/screenshots/win32/play-torrent-wired-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/screenshots/win32/play-torrent-wired-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/screenshots/win32/play-torrent-wired-fullscreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/screenshots/win32/play-torrent-wired.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.