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

Asynchronous music-metadata updates while streaming #1449

Merged
merged 24 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
39145b2
Ensure that default file/protocol handlers are re-installed after upd…
bnjmnt4n Oct 2, 2016
0e0b0e6
webtorrent/webtorrent-desktop#1340: Switch to async metadata updates.
Borewit Aug 13, 2018
198c62e
Use fat arrow
Borewit Aug 13, 2018
b185a62
Merge remote-tracking branch 'origin/master' into feature/async-updat…
Borewit Aug 15, 2018
a30d804
Fix issue track number not displayed if total number of tracks is not…
Borewit Aug 15, 2018
c2594f5
Add disk number in addition to track number.
Borewit Aug 15, 2018
c7f30df
Update order of audio properties from: album, track, disk, format to …
Borewit Aug 15, 2018
b73db82
#1340 Update music-metadata to 2.5.0, enabling async 'per' tag updates
Borewit Aug 16, 2018
8848534
#1340 Commented out the metadata event debug output.
Borewit Aug 16, 2018
f925b1f
#1340 Remove line comment to get rid of max line length lint error
Borewit Aug 16, 2018
30276d5
Merge branch 'master' into feature/async-update-music-metadata
Borewit Aug 16, 2018
c6944a3
Merge remote-tracking branch 'upstream/fix/audio-track-nr' into featu…
Borewit Aug 16, 2018
090b906
Update music-metadata 2.6.0 to fix some async events are getting trig…
Borewit Aug 17, 2018
e2448ca
Return JSX block.
Borewit Aug 18, 2018
c85f331
Merge branches 'demoneaux/fix-handlers', 'feature/async-update-music-…
Borewit Aug 18, 2018
4306569
Get rid of third parameter which is replaced by CSS capitalize
Borewit Aug 19, 2018
e508b13
Merge branch 'fix/audio-track-nr' into feature/async-update-music-met…
Borewit Aug 19, 2018
8e91840
Fixed error when value is undefined.
codealchemist Aug 19, 2018
50bf7e1
Merge branch 'fix/audio-track-nr' into feature/async-update-music-met…
Borewit Aug 19, 2018
ee9bf1d
Merge branch 'master' into feature/async-update-music-metadata
Borewit Aug 29, 2018
e34edc2
Update music-metadata dependency to 2.6.1.
Borewit Aug 29, 2018
db50e97
fix(package): update music-metadata to version 3.1.0
greenkeeper[bot] Sep 20, 2018
f7719a7
Merge remote-tracking branch 'upstream/greenkeeper/music-metadata-3.1…
Borewit Sep 26, 2018
78b71d3
Revert "Ensure that default file/protocol handlers are re-installed a…
mathiasvr Sep 26, 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",
"music-metadata": "^2.4.2",
"music-metadata": "^3.1.0",
"network-address": "^1.1.0",
"parse-torrent": "^6.0.1",
"prettier-bytes": "^1.0.1",
Expand Down
45 changes: 32 additions & 13 deletions src/renderer/pages/player-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ function renderOverlay (state) {
)
}

/**
* Render track or disk number string
* @param common metadata.common part
* @param key should be either 'track' or 'disk'
* @return track or disk number metadata as JSX block
*/
function renderTrack (common, key) {
// Audio metadata: track-number
if (common[key] && common[key].no) {
let str = `${common[key].no}`
if (common[key].of) {
str += ` of ${common[key].of}`
}
const style = { textTransform: 'capitalize' }
return (
<div className={`audio-${key}`}>
<label style={style}>{key}</label> {str}
</div>
)
}
}

function renderAudioMetadata (state) {
const fileSummary = state.getPlayingFileSummary()
if (!fileSummary.audioInfo) return
Expand All @@ -216,9 +238,7 @@ function renderAudioMetadata (state) {
const elems = []

// Audio metadata: artist(s)
const artist = common.albumartist || common.artist ||
(common.artists && common.artists.filter(function (a) { return a }).join(', ')) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

common.artists array is not available anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is still available, but common.artist is already designed to summarize the artist(s) in a single string.
Either derived from common.artists or directly from the metadata.

In other words, the code removed is already done in music-metadata.

'(Unknown Artist)'
const artist = common.artist || common.albumartist
if (artist) {
elems.push((
<div key='artist' className='audio-artist'>
Expand All @@ -227,6 +247,15 @@ function renderAudioMetadata (state) {
))
}

// Audio metadata: disk & track-number
const count = ['track', 'disk']
count.forEach(key => {
const nrElem = renderTrack(common, key)
if (nrElem) {
elems.push(nrElem)
}
})

// Audio metadata: album
if (common.album) {
elems.push((
Expand Down Expand Up @@ -269,16 +298,6 @@ function renderAudioMetadata (state) {
))
}

// 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 = []
fileSummary.audioInfo.format = fileSummary.audioInfo.format || ''
Expand Down
12 changes: 8 additions & 4 deletions src/renderer/webtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,21 @@ function getAudioMetadata (infoHash, index) {
const metadata = { title: file.name }
ipc.send('wt-audio-metadata', infoHash, index, metadata)

const options = { native: false, skipCovers: true, fileSize: file.length }
const options = { native: false,
skipCovers: true,
fileSize: file.length,
observer: event => {
ipc.send('wt-audio-metadata', infoHash, index, event.metadata)
} }
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
.then(function (metadata) {
console.log('got audio metadata for %s (length=%s): %o', file.name, file.length, metadata)
ipc.send('wt-audio-metadata', infoHash, index, metadata)
.then(() => {
console.log(`metadata for file='${file.name}' completed.`)
}).catch(function (err) {
return console.log('error getting audio metadata for ' + infoHash + ':' + index, err)
})
Expand Down