Skip to content

Instantly share code, notes, and snippets.

@Freso
Created January 6, 2013 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Freso/4465817 to your computer and use it in GitHub Desktop.
Save Freso/4465817 to your computer and use it in GitHub Desktop.
otherdatabases: {
match: new RegExp("^(https?://)?(www\\.)?(rateyourmusic\\.com/|worldcat\\.org/|musicmoz\\.org/|45cat\\.com/|musik-sammler\\.de/|discografia\\.dds\\.it/|tallinn\\.ester\\.ee/|tartu\\.ester\\.ee/|encyclopedisque\\.fr/|discosdobrasil\\.com\\.br/|isrc\\.ncl\\.edu\\.tw/|rolldabeats\\.com/|psydb\\.net/|metal-archives\\.com/|spirit-of-metal\\.com/|ibdb\\.com/|lortel.\\org/|theatricalia\\.com/|ocremix\\.org/|trove\\.nla\\.gov\\.au/|(wiki\\.)?rockinchina\\.com|(www\\.)?dhhu\\.dk|thesession\\.org)", "i"),
type: MB.constants.LINK_TYPES.otherdatabases,
clean: function(url) {
//Removing cruft from Worldcat URLs
url = url.replace(/^(?:https?:\/\/)?(?:www\.)?worldcat\.org(?:\/title\/[a-zA-Z0-9_-]+)?\/oclc\/([^&?]+)(?:.*)$/, "http://www.worldcat.org/oclc/$1");
//Standardising IBDb not to use www
url = url.replace(/^(https?:\/\/)?(www\.)?ibdb\.com/, "http://ibdb.com");
//Standardising ESTER to their default parameters
url = url.replace(/^(?:https?:\/\/)?(tallinn|tartu)\.ester\.ee\/record=([^~]+)(?:.*)?$/, "http://$1.ester.ee/record=$2~S1*est");
//Standardising Trove
url = url.replace(/^(?:https?:\/\/)?trove.nla.gov.au\/([^\/]+)\/([^\/?]+)(?:\?.*)?$/, "http://trove.nla.gov.au/$1/$2");
//Standardising RIC
url = url.replace(/^(?:https?:\/\/)?(wiki|www)\.rockinchina\.com\/w\/(.*)+$/, "http://www.rockinchina.com/w/$2");
//Standardising DHHU
url = url.replace(/^(?:https?:\/\/)?(www\.)?dhhu\.dk\/w\/(.*)+$/, "http://www.dhhu.dk/w/$2");
//Standardising The Session
url = url.replace(/^(?:https?:\/\/)?(www\.)?thesession\.org\/([^\/]+)/display/(.*)+$/, "http://www.thesession.org/$1/display/$2");
return url;
},
validate: function(url, type) {
if url matches foo {
if type == artist {
return (test for artist) // Ie., true or false
}
else if type == event {
return (test for event) // Ie., true or false
}
}
return true; // If no test matches the parameters given, pass the "test"
}
}
...
MB.Control.URLCleanup = function (sourceType, typeControl, urlControl) {
var self = MB.Object ();
self.typeControl = $(typeControl);
self.urlControl = $(urlControl);
self.sourceType = sourceType;
self.errorList = $('<ul class="errors" />').hide();
self.typeControl.after(self.errorList);
var validationRules = { };
// "has lyrics at" is only allowed for certain lyrics sites
validationRules[ MB.constants.LINK_TYPES.lyrics.artist ] = function() {
return MB.constants.CLEANUPS.lyrics.match.test($('#id-ar\\.url').val(), 'event')
};
...
// Do tests for other databases
validationRules[ MB.constants.LINK_TYPES.otherdatabases.event ] = function() {
return MB.constants.LINK_TYPES.otherdatabases.validate($('$id-ar\\.url').val()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment