From 338f9dea52ea8b6d784465bbde684eaba28bb8e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Perttil=C3=A4?= Date: Thu, 15 Nov 2018 04:06:22 +0200 Subject: [PATCH 1/7] qobuz_importer.user.js: Add barcode, set cat#: [none], list ISRCs. Added textarea for listing ISRCs. This is for easy adding from within the added release with a bookmarklet. See: https://community.metabrainz.org/t/problems-with-isrc-batch-add/158976/2 --- qobuz_importer.user.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/qobuz_importer.user.js b/qobuz_importer.user.js index 77756c1..eaf895b 100644 --- a/qobuz_importer.user.js +++ b/qobuz_importer.user.js @@ -42,6 +42,7 @@ function parseRelease(data) { // Release information global to all Beatport releases release.packaging = 'None'; + release.barcode = data.upc; release.country = ""; if (i18n_global && i18n_global.zone) { if (i18n_global.zone == 'GB') release.country = 'UK'; @@ -65,12 +66,13 @@ function parseRelease(data) { $.each(data.label.name.split(' - '), function(index, label) { release.labels.push({ name: label, - catno: "" // no catno on qobuz ? + catno: "[none]" // no catno on qobuz ? }); }); - + release.isrcs = []; var tracks = []; $.each(data.tracks.items, function(index, trackobj) { + release.isrcs.push(trackobj.isrc); var track = {}; track.title = trackobj.title; track.duration = trackobj.duration * 1000; @@ -119,8 +121,9 @@ function insertLink(release) { var parameters = MBImport.buildFormParameters(release, edit_note); var mbUI = $('

' + MBImport.buildFormHTML(parameters) + MBImport.buildSearchButton(release) + '

').hide(); + var isrcslist = $(''); - $("#info div.meta").append(mbUI); + $("#info div.meta").append(mbUI).append(isrcslist); $('form.musicbrainz_import').css({ 'display': 'inline-block', 'margin': '1px' From 42e0e68d94f1e5186616952fe0373085cd3c7ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Perttil=C3=A4?= Date: Thu, 15 Nov 2018 04:17:00 +0200 Subject: [PATCH 2/7] qobuz_importer.user.js: Fix release country error on import. The GB is valid instead of UK when importing. Set the default to world wide. Does qobuz have any georestrictions on downloadable sales even. --- qobuz_importer.user.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/qobuz_importer.user.js b/qobuz_importer.user.js index eaf895b..20a74a2 100644 --- a/qobuz_importer.user.js +++ b/qobuz_importer.user.js @@ -43,10 +43,9 @@ function parseRelease(data) { // Release information global to all Beatport releases release.packaging = 'None'; release.barcode = data.upc; - release.country = ""; + release.country = "XW"; if (i18n_global && i18n_global.zone) { - if (i18n_global.zone == 'GB') release.country = 'UK'; - else release.country = i18n_global.zone; + release.country = i18n_global.zone; } release.status = 'official'; release.urls = []; From ce5a8322112d73a8f040b5729bbf1670c8b28e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Perttil=C3=A4?= Date: Thu, 15 Nov 2018 04:24:15 +0200 Subject: [PATCH 3/7] qobuz_importer.user.js: Fix #191 by hooking to web player. Replaced the invalid API key and separate requesting by hooking to XMLHttpRequest and using the data requested by the official web player. --- qobuz_importer.user.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/qobuz_importer.user.js b/qobuz_importer.user.js index 20a74a2..2a7fc84 100644 --- a/qobuz_importer.user.js +++ b/qobuz_importer.user.js @@ -135,30 +135,27 @@ function insertLink(release) { mbUI.slideDown(); } +// Hook all XMLHttpRequest to use the data fetched by the official web-player. +(function() { + const send = XMLHttpRequest.prototype.send + XMLHttpRequest.prototype.send = function() { + this.addEventListener('load', function() { + var wsUrl = 'https://www.qobuz.com/api.json/0.2/album/get?album_id='; + var repUrl = arguments[0].originalTarget.responseURL; + if (repUrl.startsWith(wsUrl)) { + var data = JSON.parse(this.responseText); + var release = parseRelease(data); + insertLink(release); + } + }) + return send.apply(this, arguments) + } +})() + $(document).ready(function() { MBImportStyle(); - album_id = $('ol.tracks').attr('data-qbplayer-id'); - app_id = '667867760'; - - wsUrl = 'https://www.qobuz.com/api.json/0.2/album/get?album_id=' + album_id + '&app_id=' + app_id; - - $.ajax({ - url: wsUrl, - dataType: 'json', - crossDomain: true, - success: function(data, textStatus, jqXHR) { - LOGGER.debug("Qobuz JSON Data from API:", data); - var release = parseRelease(data); - insertLink(release); - }, - error: function(jqXHR, textStatus, errorThrown) { - LOGGER.error("AJAX Status: ", textStatus); - LOGGER.error("AJAX error thrown: ", errorThrown); - } - }); - // replace image zoom link by the maximum size image link var maximgurl = $("#product-cover-link").attr("href").replace('_600', '_max'); var maximg = new Image(); From 7df7907a7bdf738627cc5e8e3eac0167bb6a57ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Perttil=C3=A4?= Date: Thu, 15 Nov 2018 14:17:55 +0200 Subject: [PATCH 4/7] qobuz_importer.user.js: update version. --- qobuz_importer.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qobuz_importer.user.js b/qobuz_importer.user.js index 2a7fc84..f2259df 100644 --- a/qobuz_importer.user.js +++ b/qobuz_importer.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Import Qobuz releases to MusicBrainz // @description Add a button on Qobuz's album pages to open MusicBrainz release editor with pre-filled data for the selected release -// @version 2018.2.18.1 +// @version 2018.11.15.1 // @namespace https://github.com/murdos/musicbrainz-userscripts // @downloadURL https://raw.github.com/murdos/musicbrainz-userscripts/master/qobuz_importer.user.js // @updateURL https://raw.github.com/murdos/musicbrainz-userscripts/master/qobuz_importer.user.js From 1608191cd581923e9e2c535ddb314fdccb230077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Perttil=C3=A4?= Date: Thu, 15 Nov 2018 15:06:40 +0200 Subject: [PATCH 5/7] qobuz_importer.user.js: Add support for discs. --- qobuz_importer.user.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/qobuz_importer.user.js b/qobuz_importer.user.js index f2259df..a17ccfa 100644 --- a/qobuz_importer.user.js +++ b/qobuz_importer.user.js @@ -69,9 +69,19 @@ function parseRelease(data) { }); }); release.isrcs = []; - var tracks = []; + release.comment = "Digital download"; + release.discs = []; + var tracks = [], old_media_num = 1; $.each(data.tracks.items, function(index, trackobj) { release.isrcs.push(trackobj.isrc); + if (trackobj.media_number != old_media_num) { + release.discs.push({ + 'tracks': tracks, + 'format': "Digital Media" + }); + old_media_num = trackobj.media_number; + tracks = []; + } var track = {}; track.title = trackobj.title; track.duration = trackobj.duration * 1000; @@ -104,7 +114,6 @@ function parseRelease(data) { } tracks.push(track); }); - release.discs = []; release.discs.push({ 'tracks': tracks, 'format': "Digital Media" From 667090ca7d9f4e938712f4d2fd09345137fc8ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Perttil=C3=A4?= Date: Tue, 20 Nov 2018 15:02:51 +0200 Subject: [PATCH 6/7] qobuz_importer.user.js: Put ISRC list behind a button. --- qobuz_importer.user.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/qobuz_importer.user.js b/qobuz_importer.user.js index a17ccfa..49df111 100644 --- a/qobuz_importer.user.js +++ b/qobuz_importer.user.js @@ -128,10 +128,11 @@ function insertLink(release) { var edit_note = MBImport.makeEditNote(release.url, 'Qobuz'); var parameters = MBImport.buildFormParameters(release, edit_note); - var mbUI = $('

' + MBImport.buildFormHTML(parameters) + MBImport.buildSearchButton(release) + '

').hide(); - var isrcslist = $(''); + var mbUI = $('

').append(MBImport.buildFormHTML(parameters) + MBImport.buildSearchButton(release)).hide(); + mbUI.append($('')); + var isrclist = $('

'); - $("#info div.meta").append(mbUI).append(isrcslist); + $("#info div.meta").append(mbUI).append(isrclist); $('form.musicbrainz_import').css({ 'display': 'inline-block', 'margin': '1px' @@ -178,3 +179,13 @@ $(document).ready(function() { maximg.src = maximgurl; }); + +$(document).on('click', '#isrcs', function (){ + $('#isrclist').toggle(); + if ($('#isrclist').is(':visible')) { + $('#isrclist').select(); + $(this).text('Hide ISRCs'); + } + else $(this).text('Show ISRCs'); + return false; +}); \ No newline at end of file From 5dd6eda4d179e5f3ef90f3e376213493400f5554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Perttil=C3=A4?= Date: Tue, 20 Nov 2018 19:05:55 +0200 Subject: [PATCH 7/7] qobuz_importer.user.js: Fix single performer, fix quotes in title. Fix parsing error when performers is missing, use performer for trackobj. Fix import error bad request 400 with quoted track titles. --- qobuz_importer.user.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qobuz_importer.user.js b/qobuz_importer.user.js index 49df111..82033cf 100644 --- a/qobuz_importer.user.js +++ b/qobuz_importer.user.js @@ -83,13 +83,13 @@ function parseRelease(data) { tracks = []; } var track = {}; - track.title = trackobj.title; + track.title = trackobj.title.replace('"','\"'); track.duration = trackobj.duration * 1000; - var performers = trackobj.performers.split('\r - ').map(function(v) { + var performers = (typeof trackobj.performers !== 'undefined') && trackobj.performers.split('\r - ').map(function(v) { var list = v.split(', '); var name = list.shift(); return [name, list]; - }); + }) || [trackobj.performer.name, ['Primary']]; var artists = []; var featured_artists = []; $.each(performers, function(index, performer) {