Skip to content

Commit

Permalink
Merge pull request #3391 from reosarevok/MBS-13784
Browse files Browse the repository at this point in the history
MBS-13784: Support paid streaming alongside download for Beatport
  • Loading branch information
reosarevok authored Oct 25, 2024
2 parents be16908 + e9897c9 commit cfa2ee4
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 7 deletions.
50 changes: 46 additions & 4 deletions root/static/scripts/edit/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1368,9 +1368,49 @@ const CLEANUPS: CleanupEntries = {
},
'beatport': {
match: [/^(https?:\/\/)?([^/]+\.)?beatport\.com/i],
restrict: [LINK_TYPES.downloadpurchase],
restrict: [
LINK_TYPES.downloadpurchase,
{
recording: [
LINK_TYPES.downloadpurchase.recording,
LINK_TYPES.streamingpaid.recording,
],
},
{
release: [
LINK_TYPES.downloadpurchase.release,
LINK_TYPES.streamingpaid.release,
],
},
],
select(url, sourceType) {
const m = /^https?:\/\/(?:sounds|www)\.beatport\.com\/([\w-]+)\/[\w!%-]+\/[1-9][0-9]*$/.exec(url);
if (m) {
const prefix = m[1];
switch (prefix) {
case 'chart':
case 'release':
case 'stem-pack':
if (sourceType === 'release') {
return LINK_TYPES.downloadpurchase.release;
}
break;
case 'stem':
case 'track':
if (sourceType === 'recording') {
return LINK_TYPES.downloadpurchase.recording;
}
break;
}
}
return false;
},
clean(url) {
url = url.replace(/^(?:https?:\/\/)?(?:(?:classic|pro|www)\.)?beatport\.com\//, 'https://www.beatport.com/');
url = url.replace(/^(?:https?:\/\/)?([^/]+\.)?beatport\.com\//, 'https://$1beatport.com/');
url = url.replace(/^https:\/\/(?:(?:classic|pro|www)\.)?beatport\.com\//, 'https://www.beatport.com/');
url = url.replace(/^https:\/\/dj\.beatport\.com\/(artist|label)s\/([\w-]+)\/([1-9][0-9]*)/, 'https://www.beatport.com/$1/$2/$3');
url = url.replace(/^https:\/\/dj\.beatport\.com\/releases\/[1-9][0-9]*\/([1-9][0-9]*)/, 'https://www.beatport.com/track/-/$1');
url = url.replace(/^https:\/\/dj\.beatport\.com\/releases\/([1-9][0-9]*)/, 'https://www.beatport.com/release/-/$1');
const m = url.match(/^(https:\/\/www\.beatport\.com)\/[\w-]+\/html\/content\/([\w-]+)\/detail\/0*([0-9]+)\/([^/?&#]*).*$/);
if (m) {
const slug = m[4].toLowerCase()
Expand All @@ -1387,11 +1427,11 @@ const CLEANUPS: CleanupEntries = {
.replace(/[^a-z0-9!]/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '')
.replace(/^$/, '---');
.replace(/^$/, '-');
url = [m[1], m[2], slug, m[3]].join('/');
}
url = url.replace(/^(https:\/\/www\.beatport\.com)\/([\w-]+)\/([\w!-]+)\/0*([0-9]+).*$/, '$1/$2/$3/$4');
url = url.replace(/^(https:\/\/www\.beatport\.com)\/([\w-]+)\/\/0*([0-9]+)(?![\w!-]|\/[0-9]).*$/, '$1/$2/---/$3');
url = url.replace(/^(https:\/\/www\.beatport\.com)\/([\w-]+)\/\/0*([0-9]+)(?![\w!-]|\/[0-9]).*$/, '$1/$2/-/$3');
return url;
},
validate(url, id) {
Expand All @@ -1405,11 +1445,13 @@ const CLEANUPS: CleanupEntries = {
target: ERROR_TARGETS.ENTITY,
};
case LINK_TYPES.downloadpurchase.recording:
case LINK_TYPES.streamingpaid.recording:
return {
result: prefix === 'track' || prefix === 'stem',
target: ERROR_TARGETS.ENTITY,
};
case LINK_TYPES.downloadpurchase.release:
case LINK_TYPES.streamingpaid.release:
return {
result: prefix === 'release' ||
prefix === 'chart' ||
Expand Down
86 changes: 83 additions & 3 deletions root/static/scripts/tests/Control/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ limited_link_type_combinations: [
expected_clean_url: 'https://www.bbc.co.uk/music/artists/b52dd210-909c-461a-a75d-19e85a522042',
},
// Beatport
{ // Closed in Dec. 2017, replaced with www.beatport.com/chart
{ // Old DJ page, closed in Dec. 2017, replaced with www.beatport.com/chart
input_url: 'http://dj.beatport.com/thegoldenboyuk',
input_entity_type: 'artist',
expected_relationship_type: 'downloadpurchase',
Expand Down Expand Up @@ -1063,90 +1063,170 @@ limited_link_type_combinations: [
expected_clean_url: 'https://www.beatport.com/artist/4orcedj/208047',
only_valid_entity_types: ['artist'],
},
{
input_url: 'https://dj.beatport.com/artists/4orce-dj/208047',
input_entity_type: 'artist',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://www.beatport.com/artist/4orce-dj/208047',
only_valid_entity_types: ['artist'],
},
{
input_url: 'https://www.beatport.com/release/pryda-10-vol-i/1563118',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/release/pryda-10-vol-i/1563118',
only_valid_entity_types: ['release'],
},
{ // Used to fool the detection of missing slug (MBS-9846)
input_url: 'http://classic.beatport.com/release/4/2361374',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/release/4/2361374',
only_valid_entity_types: ['release'],
},
{ // Legacy URL format (real example)
input_url: 'https://www.beatport.com/en-US/html/content/release/detail/161035/Back%20To%20The%20Future',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/release/back-to-the-future/161035',
only_valid_entity_types: ['release'],
},
{ // Legacy URL format (made up to test slug conversion)
input_url: 'https://www.beatport.com/en-US/html/content/release/detail/06130/%40@%26%25%24$%23%22%21!-&tracks#',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/release/at-at-and-percent-money-money-pound-!!/6130',
only_valid_entity_types: ['release'],
},
{ // Legacy URL format missing slug (real example)
input_url: 'https://www.beatport.com/en-US/html/content/release/detail/287442/',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://www.beatport.com/release/---/287442',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/release/-/287442',
only_valid_entity_types: ['release'],
},
{ // Nowadays erroneous redirect for legacy URL format missing slug (same example)
input_url: 'https://www.beatport.com/release//287442',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://www.beatport.com/release/---/287442',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/release/-/287442',
only_valid_entity_types: ['release'],
},
{ // Used to be rejected by validation (MBS-11263)
input_url: 'https://www.beatport.com/release/riva-starr-presents-square-pegs-round-holes-5-years-of-snatch%21-sampler/1520186',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/release/riva-starr-presents-square-pegs-round-holes-5-years-of-snatch%21-sampler/1520186',
only_valid_entity_types: ['release'],
},
{ // DJ page (no slug available)
input_url: 'https://dj.beatport.com/releases/3794236',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/release/-/3794236',
only_valid_entity_types: ['release'],
},
{
input_url: 'https://www.beatport.com/chart/eric-prydz-february-chart/32623',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/chart/eric-prydz-february-chart/32623',
only_valid_entity_types: ['release'],
},
{
input_url: 'https://www.beatport.com/stem-pack/my-colors-ep/3030',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/stem-pack/my-colors-ep/3030',
only_valid_entity_types: ['release'],
},
{
input_url: 'https://www.beatport.com/stem/celestial/7380',
input_entity_type: 'recording',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/stem/celestial/7380',
only_valid_entity_types: ['recording'],
},
{
input_url: 'https://www.beatport.com/track/full-stop-original-mix/1682783',
input_entity_type: 'recording',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/track/full-stop-original-mix/1682783',
only_valid_entity_types: ['recording'],
},
{
input_url: 'https://dj.beatport.com/releases/4758665/19583630',
input_entity_type: 'recording',
expected_relationship_type: 'downloadpurchase',
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'downloadpurchase',
],
expected_clean_url: 'https://www.beatport.com/track/-/19583630',
only_valid_entity_types: ['recording'],
},
{
input_url: 'https://www.beatport.com/label/mouseville/1421',
input_entity_type: 'label',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://www.beatport.com/label/mouseville/1421',
only_valid_entity_types: ['label'],
},
{
input_url: 'https://dj.beatport.com/labels/justice-hardcore/30135',
input_entity_type: 'label',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://www.beatport.com/label/justice-hardcore/30135',
only_valid_entity_types: ['label'],
},
// Behance
{
input_url: 'http://behance.net/tristan-gion/appreciated',
Expand Down

0 comments on commit cfa2ee4

Please sign in to comment.