Skip to content

Commit

Permalink
MBS-12898: Autoselect Apple Music rel for artists/labels
Browse files Browse the repository at this point in the history
An Apple Music relationship type now exists for artists and labels,
so as suggested in 4a89ec0 when this
was originally written, I'm changing the autoselect to use it instead.
Existing relationships will need to be moved with a bot.
  • Loading branch information
reosarevok committed Feb 13, 2023
1 parent 0eeb798 commit afa0f25
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
28 changes: 21 additions & 7 deletions root/static/scripts/edit/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export const LINK_TYPES: LinkTypeMap = {
amazon: {
release: '4f2e710d-166c-480c-a293-2e2c8d658d87',
},
applemusic: {
artist: '64785d6c-2eeb-4f86-9418-b6c2d6c53c13',
label: 'debf36e1-b0fa-4e6c-987e-4248bf050fd8',
},
bandcamp: {
artist: 'c550166e-0548-4a18-b1d4-e2ae423a3e88',
genre: 'ad28869f-0f9e-4bd5-b786-70125cc69c3c',
Expand Down Expand Up @@ -838,9 +842,21 @@ const CLEANUPS: CleanupEntries = {
new RegExp('^(https?://)?([^/]+\\.)?apple\\.co/', 'i'),
],
restrict: [
LINK_TYPES.downloadpurchase,
LINK_TYPES.streamingpaid,
multiple(LINK_TYPES.downloadpurchase, LINK_TYPES.streamingpaid),
LINK_TYPES.applemusic,
...anyCombinationOf(
'recording',
[
LINK_TYPES.downloadpurchase.recording,
LINK_TYPES.streamingpaid.recording,
],
),
...anyCombinationOf(
'release',
[
LINK_TYPES.downloadpurchase.release,
LINK_TYPES.streamingpaid.release,
],
),
],
clean: function (url) {
url = url.replace(/^https?:\/\/(?:(?:beta|geo)\.)?music\.apple\.com\/([a-z]{2}\/)?(artist|album|author|label|music-video)\/(?:[^?#\/]+\/)?(?:id)?([0-9]+)(?:\?.*)?$/, 'https://music.apple.com/$1$2/$3');
Expand Down Expand Up @@ -871,17 +887,15 @@ const CLEANUPS: CleanupEntries = {
if (m) {
const prefix = m[1];
switch (id) {
case LINK_TYPES.downloadpurchase.artist:
case LINK_TYPES.streamingpaid.artist:
case LINK_TYPES.applemusic.artist:
if (prefix === 'artist') {
return {result: true};
}
return {
result: false,
target: ERROR_TARGETS.ENTITY,
};
case LINK_TYPES.downloadpurchase.label:
case LINK_TYPES.streamingpaid.label:
case LINK_TYPES.applemusic.label:
if (prefix === 'label') {
return {result: true};
}
Expand Down
21 changes: 6 additions & 15 deletions root/static/scripts/tests/Control/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,32 +567,23 @@ const testData = [
{
input_url: 'http://music.apple.com/artist/hangry-angry-f/id444923726',
input_entity_type: 'artist',
limited_link_type_combinations: [
'downloadpurchase',
'streamingpaid',
['downloadpurchase', 'streamingpaid'],
],
expected_relationship_type: 'applemusic',
expected_clean_url: 'https://music.apple.com/us/artist/444923726',
only_valid_entity_types: ['artist'],
},
{
input_url: 'https://beta.music.apple.com/ca/artist/imposs/205021452',
input_entity_type: 'artist',
limited_link_type_combinations: [
'downloadpurchase',
'streamingpaid',
['downloadpurchase', 'streamingpaid'],
],
expected_relationship_type: 'applemusic',
expected_clean_url: 'https://music.apple.com/ca/artist/205021452',
only_valid_entity_types: ['artist'],
},
{
input_url: 'https://music.apple.com/us/label/ghostly-international/1543968172',
input_entity_type: 'label',
limited_link_type_combinations: [
'downloadpurchase',
'streamingpaid',
['downloadpurchase', 'streamingpaid'],
],
expected_relationship_type: 'applemusic',
expected_clean_url: 'https://music.apple.com/us/label/1543968172',
only_valid_entity_types: ['label'],
},
{
input_url: 'https://music.apple.com/ee/music-video/black-and-yellow/539886832?uo=4&mt=5&app=music',
Expand Down

0 comments on commit afa0f25

Please sign in to comment.