forked from loujine/musicbrainz-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mb-display_acousticbrainz_data_for_recording.user.js
54 lines (51 loc) · 2.14 KB
/
mb-display_acousticbrainz_data_for_recording.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* global sidebar helper */
'use strict';
// ==UserScript==
// @name MusicBrainz: Display (more) AcousticBrainz data on recording page
// @namespace mbz-loujine
// @author loujine
// @version 2021.9.19
// @downloadURL https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mb-display_acousticbrainz_data_for_recording.user.js
// @updateURL https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mb-display_acousticbrainz_data_for_recording.user.js
// @supportURL https://github.com/loujine/musicbrainz-scripts
// @icon https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/icon.png
// @description musicbrainz.org: Display (more) AcousticBrainz data on recording page
// @compatible firefox+tampermonkey
// @license MIT
// @require https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mbz-loujine-common.js
// @include http*://*musicbrainz.org/recording/*
// @exclude http*://*musicbrainz.org/recording/merge*
// @exclude http*://*musicbrainz.org/recording/*/*
// @grant none
// @run-at document-end
// ==/UserScript==
function round(num, precision) {
const modifier = Math.pow(10, precision);
return Math.round(num * modifier) / modifier;
}
function showAcousticBrainzData() {
const mbid = helper.mbidFromURL();
fetch(`//acousticbrainz.org/api/v1/${mbid}/count`).then(
resp => resp.json()
).then(json => {
const count = json.count;
if (count > 0) {
fetch(`//acousticbrainz.org/api/v1/${mbid}/low-level`).then(
resp => resp.json()
).then(data => {
document.getElementById('ABfreq').append(round(data.tonal.tuning_frequency, 2));
document.getElementById('ABbeatcount').append(data.rhythm.beats_count);
});
}
});
}
(function main() {
sidebar.container().insertAdjacentHTML('beforeend', `
<h3>More acoustic analysis</h3>
<dl>
<dt>Tuning frequency:</dt><dd id="ABfreq"></dd>
<dt>Beats count:</dt><dd id="ABbeatcount"></dd>
</dl>
`);
showAcousticBrainzData();
})();