mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-11-10 13:14:16 +00:00
discogs_importer: introduce two functions building a cache key including mb type
This commit is contained in:
parent
dd9e2895cd
commit
dab6f5ccc1
1 changed files with 30 additions and 0 deletions
|
@ -296,6 +296,36 @@ function defaultMBtype(discogs_type) {
|
|||
return discogs_type;
|
||||
}
|
||||
|
||||
function getCacheKeyFromInfo(info_key, mb_type) {
|
||||
var inf = link_infos[info_key];
|
||||
if (inf) {
|
||||
if (!mb_type) mb_type = defaultMBtype(inf.type);
|
||||
return inf.type + '/' + inf.id + '/' + mb_type;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function getCacheKeyFromUrl(url, discogs_type, mb_type) {
|
||||
try {
|
||||
var key = getDiscogsLinkKey(url);
|
||||
console.log(link_infos[key]);
|
||||
if (key) {
|
||||
if (!discogs_type || link_infos[key].type == discogs_type) {
|
||||
var cachekey = getCacheKeyFromInfo(key, mb_type);
|
||||
LOGGER.debug('getCacheKeyFromUrl: ' + key + ', ' + url + ' --> ' + cachekey);
|
||||
return cachekey;
|
||||
} else {
|
||||
LOGGER.debug('getCacheKeyFromUrl: ' + key + ', ' + url + ' --> unmatched type: ' + discogs_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
LOGGER.error(err);
|
||||
}
|
||||
LOGGER.debug('getCacheKeyFromUrl: ' + url + ' (' + discogs_type + ') failed');
|
||||
return false;
|
||||
}
|
||||
|
||||
function MBIDfromUrl(url, discogs_type) {
|
||||
return mblinks.resolveMBID(getCleanUrl(url, discogs_type));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue