diff --git a/root/static/scripts/edit/URLCleanup.js b/root/static/scripts/edit/URLCleanup.js index 810a2f79da3..2bb198d2f6c 100644 --- a/root/static/scripts/edit/URLCleanup.js +++ b/root/static/scripts/edit/URLCleanup.js @@ -6156,6 +6156,102 @@ const CLEANUPS: CleanupEntries = { }; }, }, + 'vibe': { + match: [ + /^(https?:\/\/)?vibe\.naver\.com\//i, + /^(https?:\/\/)?music\.naver\.com\//i, // legacy URL + ], + restrict: [ + multiple(LINK_TYPES.downloadpurchase, LINK_TYPES.streamingpaid), + LINK_TYPES.streamingpaid, + ], + select(url, sourceType) { + const m = /^https:\/\/vibe\.naver\.com\/(album|artist|track|video)/.exec(url); + if (m) { + const prefix = m[1]; + switch (prefix) { + case 'album': + if (sourceType === 'release') { + return [ + LINK_TYPES.downloadpurchase.release, + LINK_TYPES.streamingpaid.release, + ]; + } + break; + case 'artist': + if (sourceType === 'artist') { + return [ + LINK_TYPES.downloadpurchase.artist, + LINK_TYPES.streamingpaid.artist, + ]; + } + break; + case 'track': + if (sourceType === 'recording') { + return [ + LINK_TYPES.downloadpurchase.recording, + LINK_TYPES.streamingpaid.recording, + ]; + } + break; + default: // video + if (sourceType === 'release') { + return [ + LINK_TYPES.streamingpaid.release, + ]; + } else if (sourceType === 'recording') { + return [ + LINK_TYPES.streamingpaid.recording, + ]; + } + break; + } + } + return false; + }, + clean(url) { + url = url.replace(/^(?:https?:\/\/)?music\.naver\.com\/album\/index\.nhn\?albumId=(\d+)(?:&.+)/, 'https://vibe.naver.com/album/$1'); + url = url.replace(/^(?:https?:\/\/)?music\.naver\.com\/artist\/(?:\w+)\.nhn\?artistId=(\d+)(?:&.+)/, 'https://vibe.naver.com/artist/$1'); + url = url.replace(/^(?:https?:\/\/)?music\.naver\.com\/video\/(?:\w+)\.nhn\?videoId=(\d+)(?:&.+)/, 'https://vibe.naver.com/video/$1'); + url = url.replace(/^(?:https?:\/\/)?vibe\.naver\.com\/(album|artist|track|video)\/(\d+)(?:\/\w+)/, 'https://vibe.naver.com/$1/$2'); + return url; + }, + validate(url, id) { + if (/https:\/\/vibe\.naver\.com\/search/.test(url)) { + return { + error: noLinkToSearchMsg(), + result: false, + target: ERROR_TARGETS.URL, + }; + } + const m = /^https?:\/\/vibe\.naver\.com\/(album|artist|track|video)\/(\d+)/.exec(url); + if (m) { + const prefix = m[1]; + switch (id) { + case LINK_TYPES.downloadpurchase.release: + case LINK_TYPES.streamingpaid.release: + return { + result: prefix === 'album' || prefix === 'video', + target: ERROR_TARGETS.ENTITY, + }; + case LINK_TYPES.downloadpurchase.artist: + case LINK_TYPES.streamingpaid.artist: + return { + result: prefix === 'artist', + target: ERROR_TARGETS.ENTITY, + }; + case LINK_TYPES.downloadpurchase.recording: + case LINK_TYPES.streamingpaid.recording: + return { + result: prefix === 'track' || prefix === 'video', + target: ERROR_TARGETS.ENTITY, + }; + } + return {result: false, target: ERROR_TARGETS.RELATIONSHIP}; + } + return {result: false, target: ERROR_TARGETS.URL}; + }, + }, 'vimeo': { match: [/^(https?:\/\/)?([^/]+\.)?vimeo\.com\/(?!(?:ondemand|store\/ondemand))/i], restrict: [{...LINK_TYPES.streamingfree, ...LINK_TYPES.videochannel}], diff --git a/root/static/scripts/tests/Control/URLCleanup.js b/root/static/scripts/tests/Control/URLCleanup.js index c12210f0b43..10ad2ed8265 100644 --- a/root/static/scripts/tests/Control/URLCleanup.js +++ b/root/static/scripts/tests/Control/URLCleanup.js @@ -6451,6 +6451,69 @@ limited_link_type_combinations: ['downloadpurchase', 'mailorder'], input_url: 'www.viaf.org/viaf/16766997/', expected_clean_url: 'http://viaf.org/viaf/16766997', }, + // Naver Vibe + { + input_url: 'https://vibe.naver.com/album/32004180', + input_entity_type: 'release', + expected_relationship_type: ['downloadpurchase', 'streamingpaid'], +limited_link_type_combinations: [ + ['downloadpurchase', 'streamingpaid'], + 'streamingpaid', + ], + expected_clean_url: 'https://vibe.naver.com/album/32004180', + }, + { + input_url: 'https://vibe.naver.com/artist/5176052', + input_entity_type: 'artist', + expected_relationship_type: ['downloadpurchase', 'streamingpaid'], +limited_link_type_combinations: [ + ['downloadpurchase', 'streamingpaid'], + 'streamingpaid', + ], + expected_clean_url: 'https://vibe.naver.com/artist/5176052', + }, + { + input_url: 'https://vibe.naver.com/artist/5176052/albums', + input_entity_type: 'artist', + expected_relationship_type: ['downloadpurchase', 'streamingpaid'], +limited_link_type_combinations: [ + ['downloadpurchase', 'streamingpaid'], + 'streamingpaid', + ], + expected_clean_url: 'https://vibe.naver.com/artist/5176052', + }, + { + input_url: 'https://vibe.naver.com/video/406927', + input_entity_type: 'release', + expected_relationship_type: ['downloadpurchase', 'streamingpaid'], +limited_link_type_combinations: [ + ['downloadpurchase', 'streamingpaid'], + 'streamingpaid', + ], + expected_clean_url: 'https://vibe.naver.com/video/406927', + }, + { + input_url: 'https://vibe.naver.com/search?query=NMIXX', + input_entity_type: 'artist', + input_relationship_type: 'streamingpaid', + expected_relationship_type: undefined, + expected_clean_url: 'https://vibe.naver.com/search?query=NMIXX', + expected_error: { + error: 'a link to a search result', + target: 'url', + }, + only_valid_entity_types: [], + }, + { + input_url: 'http://music.naver.com/album/index.nhn?albumId=307278', + input_entity_type: 'release', + expected_relationship_type: ['downloadpurchase', 'streamingpaid'], +limited_link_type_combinations: [ + ['downloadpurchase', 'streamingpaid'], + 'streamingpaid', + ], + expected_clean_url: 'https://vibe.naver.com/album/307278', + }, // Videogam.in { input_url: 'http://videogam.in/music/?id=PCCG-00486',