Last active
September 5, 2023 11:35
-
-
Save Jimmyson/42ef389bcdd7bd478146e3b4ede45e04 to your computer and use it in GitHub Desktop.
OCRemix Musicbrainz Userscripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Import OC ReMix recording to MusicBrainz | |
// @author Jimmyson | |
// @namespace https://github.com/murdos/musicbrainz-userscripts/ | |
// @version 1 | |
// @grant none | |
// @match *://ocremix.org/remix/* | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js | |
// ==/UserScript== | |
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant | |
this.$ = this.jQuery = jQuery.noConflict(true); | |
//var recording = new Array(); | |
$(document).ready(function() { | |
var release_url = window.location.href.replace('/\?.*$/', '').replace(/#.*$/, ''); | |
var rec = retrieveRecordingInfo(); | |
insertLink(rec, release_url); | |
}); | |
function retrieveRecordingInfo() { | |
var recording = {}; | |
//Recording Name | |
recording['title'] = $('body div div div h1').text().trim().substring(7) + " OC ReMix"; | |
recording['length'] = $('body div div div div div.panel-2-green>span').text().split(' ')[2].replace(",",''); | |
//Composer(s) | |
var remixers = $('body div div div div div div div div ul li:nth-child(3) a').map(function (key, object) {return object.innerHTML}); | |
recording['artist_credit'] = {}; | |
recording['artist_credit']['names'] = []; | |
for(var i = 0; i < remixers.length; i++) { | |
recording['artist_credit']['names'][i] = {}; | |
recording['artist_credit']['names'][i]['name'] = remixers[i]; | |
recording['artist_credit']['names'][i]['artist'] = {}; | |
recording['artist_credit']['names'][i]['artist']['name'] = remixers[i]; | |
recording['artist_credit']['names'][i]['artist']['id'] = (i+1); | |
if (i < remixers.length-1) { | |
recording['artist_credit']['names'][i]['join_phrase'] = ', '; | |
} | |
} | |
//External Links | |
recording['url'] = []; | |
recording['url'][0] = {}; | |
recording['url'][0]['text'] = window.location.href; | |
recording['url'][0]['link_type_id'] = 306; | |
//recording['url'][1] = {}; | |
//recording['url'][1]['text'] = "http://www.youtube.com/watch?v=" + String.split($('.youtube_html5 iframe').attr("src"),'/')[4].substring(0,11); | |
//recording['url'][1]['link_type_id'] = 268; | |
//OC ReMix MB Catalog Relationship | |
recording['rels'] = []; | |
recording['rels'][0] = {}; | |
recording['rels'][0]['target'] = 'b2b031ec-176e-45fd-8965-4691a9e79691'; | |
recording['rels'][0]['type'] = 'ea6f0698-6782-30d6-b16d-293081b66774'; | |
recording['rels'][0]['attributes'] = []; | |
recording['rels'][0]['attributes'][0] = {}; | |
recording['rels'][0]['attributes'][0]['type'] = 'a59c5830-5ec7-38fe-9a21-c7ea54f6650a'; | |
recording['rels'][0]['attributes'][0]['text_value'] = String.split(window.location.href, '/')[4]; | |
//Work Relationships | |
return recording; | |
} | |
function fnBuildFormParametersRecording(recording, edit_note) { | |
// Form parameters | |
var parameters = new Array(); | |
appendParameter(parameters, 'edit-recording.name', recording.title); | |
appendParameter(parameters, 'edit-recording.length', recording.length); | |
// Release Artist credits | |
buildArtistCreditsFormParametersRecording(parameters, "edit-recording.", recording.artist_credit); | |
// URLs | |
for (var i=0; i < recording.url.length; i++) { | |
var url = recording['url'][i]; | |
appendParameter(parameters, 'edit-recording.url.'+i+'.text', url.text); | |
appendParameter(parameters, 'edit-recording.url.'+i+'.link_type_id', url.link_type_id); | |
} | |
// Relationships | |
for (var i=0; i < recording.rels.length; i++) { | |
for (var index in recording.rels[i]) { | |
if(index === 'attributes') { | |
for(var j=0; j<recording.rels[i].attributes.length; j++) { | |
for (var index_attr in recording.rels[i].attributes[j]) { | |
appendParameter(parameters, 'rels.'+i+'.attributes.'+j+'.'+index_attr, recording.rels[i].attributes[j][index_attr]); | |
} | |
} | |
continue; | |
} | |
appendParameter(parameters, 'rels.'+i+'.'+index, recording.rels[i][index]); | |
} | |
} | |
// Add Edit note parameter | |
appendParameter(parameters, 'edit-recording.edit_note', edit_note); | |
return parameters; | |
} | |
function fnBuildFormHTMLRecording(parameters) { | |
// Build form | |
var innerHTML = '<form class="musicbrainz_import musicbrainz_import_add" action="//musicbrainz.org/recording/create" method="get" target="_blank" accept-charset="UTF-8" charset="' + document.characterSet + '">'; | |
parameters.forEach(function(parameter) { | |
var value = parameter.value + ""; | |
innerHTML += "<input type='hidden' value='" + value.replace(/'/g,"'") + "' name='" + parameter.name + "'/>"; | |
}); | |
innerHTML += '<button type="submit" title="Import this release into MusicBrainz (open a new tab)"><img src="//musicbrainz.org/favicon.ico" /><span>Import into MB</span></button>'; | |
innerHTML += '</form>'; | |
return innerHTML; | |
} | |
function buildArtistCreditsFormParametersRecording(parameters, paramPrefix, artist_credit) { | |
if(!artist_credit) return; | |
for (var i=0; i < artist_credit.names.length; i++) { | |
var ac = artist_credit.names[i]; | |
appendParameter(parameters, paramPrefix+'artist_credit.names.'+i+'.name', ac.name); | |
appendParameter(parameters, paramPrefix+'artist_credit.names.'+i+'.artist.name', ac.artist.name); | |
appendParameter(parameters, paramPrefix+'artist_credit.names.'+i+'.artist.id', ac.artist.id); | |
//appendParameter(parameters, paramPrefix+'artist_credit.names.'+i+'.mbid', ac.mbid); | |
if (typeof ac.join_phrase != 'undefined' && ac.join_phrase != "") { | |
appendParameter(parameters, paramPrefix+'artist_credit.names.'+i+'.join_phrase', ac.join_phrase); | |
} | |
} | |
} | |
function appendParameter(parameters, paramName, paramValue) { | |
if(!paramValue) return; | |
parameters.push( { name: paramName, value: paramValue } ); | |
} | |
function insertLink(release, release_url) { | |
var parameters = fnBuildFormParametersRecording(release, 'Recording scraped from OverClocked ReMix ('+release_url+') using the OC ReMix import script'); | |
var mbUI = $('<li class="interior-release-chart-content-item musicbrainz-import">' | |
+ fnBuildFormHTMLRecording(parameters) | |
//+ buildSearchButton(release) | |
+ '</li>');//.hide(); | |
$("#panel-main>div").prepend(mbUI); | |
$('form.musicbrainz_import').css({'display': 'inline-block', 'margin-left': '5px'}); | |
$('form.musicbrainz_import button').css({'width': '120px'}); | |
mbUI.slideDown(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
edit-recording.name=<name> OC ReMix | |
edit-recording.artist_credit.names.x.name=<remixer name> | |
edit-recording.artist_credit.names.x.join_phrase=, | |
edit-recording.artist_credit.names.x.artist.name=<remixer name> | |
edit-recording.artist_credit.names.x.artist.id=<x+1> | |
edit-recording.comment= | |
edit-recording.length=<length> | |
edit-recording.edit_note="Recording scraped from OverClocked ReMix (<url>) using the OC ReMix import script" | |
edit-recording.url.0.text=<orc url> | |
edit-recording.url.0.link_type_id=306 | |
edit-recording.url.1.text=<yt url> | |
edit-recording.url.1.link_type_id=268 | |
rels.0.target=b2b031ec-176e-45fd-8965-4691a9e79691 | |
rels.0.type=ea6f0698-6782-30d6-b16d-293081b66774 | |
rels.0.attributes.0.number=<OCR Number> | |
rels.x+1.target=<work id> | |
rels.x+1.type=a3005666-a872-32c3-ad06-98af558e99b0 | |
rels.x+1.attributes.0.cover=true | |
rels.x+1.direction=backward |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name OC Remix Recording to MB | |
// @namespace Jimmyson | |
// @description Generate a Recording from OverClocked ReMix | |
// @match *://ocremix.org/remix/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
var recording = new Array(); | |
$(document).ready(function() { | |
recording["oc_loc"] = window.location; | |
recording["ocid"] = String.split(recording["oc_loc"], '/')[4]; | |
recording["title"] = $('body div div div h1').text().trim().substring(7) + " OC ReMix"; | |
recording["rel_remixers"] = $('body div div div div div div div div ul li:nth-child(3) a'); | |
recording["composers"] = $('body div div div div div div div div ul li:nth-child(4) a'); | |
//var yt = "http://www.youtube.com/watch?v=" + String.split($('.youtube_html5 iframe').attr("src"),'/')[4].substring(0,11); | |
console.log(recording["ocid"]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment