Skip to content

Commit 8d5dee9

Browse files
committed
MBS-11684 (I): Handle editing Dogmazic URLs
Add support for editing Dogmazic URLs: * Auto-select “streaming for free” relationship type * Normalize URLs to canonical form if possible (see test examples) * Validate canonical URLs with the corresponding entity type only: * `album` with MB Release * `artist` with MB Artist * `label` with MB Label * `song` with MB Recording
1 parent ba92910 commit 8d5dee9

File tree

2 files changed

+191
-0
lines changed

2 files changed

+191
-0
lines changed

root/static/scripts/edit/URLCleanup.js

+64
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,70 @@ const CLEANUPS = {
13821382
return {result: false};
13831383
},
13841384
},
1385+
'dogmazic': {
1386+
match: [new RegExp('^(https?://)?([^/]+\\.)?(dogmazic\\.net)', 'i')],
1387+
type: LINK_TYPES.streamingfree,
1388+
clean: function (url) {
1389+
url = url.replace(/^https?:\/\/(?:(?:play|www)\.)?dogmazic\.net\//, 'https://play.dogmazic.net/');
1390+
// Drop one-word fragments such as '#albums' used for list display
1391+
url = url.replace(/^(https:\/\/play\.dogmazic\.net)\/([^#]+)#(?:\w+)?$/, '$1/$2');
1392+
// Drop current path when fragment contains a path to a PHP script
1393+
url = url.replace(/^(https:\/\/play\.dogmazic\.net)\/(?:[^#]+)#(\w+\.php)/, '$1/$2');
1394+
// Drop parents in path
1395+
url = url.replace(/^(https:\/\/play\.dogmazic\.net)\/(?:[^?#]+)\/(\w+\.php)/, '$1/$2');
1396+
// Overwrite path and query after query parameter with numeric value
1397+
const m = /^(https:\/\/play\.dogmazic\.net)\/\w+\.php\?(?:[^#]+&)?[\w%]+=([\w%]+)&([\w%]+)=(\d+)/.exec(url);
1398+
if (m) {
1399+
const host = m[1];
1400+
const type = m[2];
1401+
const key = m[3];
1402+
const value = m[4];
1403+
switch (key) {
1404+
case 'album':
1405+
return `${host}/albums.php?action=show&${key}=${value}`;
1406+
case 'artist':
1407+
return `${host}/artists.php?action=show&${key}=${value}`;
1408+
case 'label':
1409+
return `${host}/labels.php?action=show&${key}=${value}`;
1410+
case 'song_id':
1411+
return `${host}/song.php?action=show&${key}=${value}`;
1412+
case 'id':
1413+
case 'id%5B0%5D':
1414+
case 'object_id':
1415+
case 'oid':
1416+
switch (type) {
1417+
case 'album':
1418+
return `${host}/albums.php?action=show&${type}=${value}`;
1419+
case 'artist':
1420+
return `${host}/artists.php?action=show&${type}=${value}`;
1421+
case 'label':
1422+
return `${host}/labels.php?action=show&${type}=${value}`;
1423+
case 'song':
1424+
return `${host}/song.php?action=show&song_id=${value}`;
1425+
}
1426+
}
1427+
}
1428+
return url;
1429+
},
1430+
validate: function (url, id) {
1431+
const m = /^https:\/\/play\.dogmazic\.net\/(\w+)\.php\?action=show&(\w+)=\d+$/.exec(url);
1432+
if (m) {
1433+
const path = m[1];
1434+
const query = m[2];
1435+
switch (id) {
1436+
case LINK_TYPES.streamingfree.artist:
1437+
return {result: path === 'artists' && query === 'artist'};
1438+
case LINK_TYPES.streamingfree.label:
1439+
return {result: path === 'labels' && query === 'label'};
1440+
case LINK_TYPES.streamingfree.release:
1441+
return {result: path === 'albums' && query === 'album'};
1442+
case LINK_TYPES.streamingfree.recording:
1443+
return {result: path === 'song' && query === 'song_id'};
1444+
}
1445+
}
1446+
return {result: false};
1447+
},
1448+
},
13851449
'downloadpurchase': {
13861450
match: [
13871451
new RegExp('^(https?://)?([^/]+\\.)?junodownload\\.com', 'i'),

root/static/scripts/tests/Control/URLCleanup.js

+127
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,133 @@ const testData = [
14381438
expected_clean_url: 'http://d-nb.info/1181136512',
14391439
only_valid_entity_types: ['release'],
14401440
},
1441+
// Dogmazic
1442+
{
1443+
input_url: 'https://play.dogmazic.net/artists.php?action=show_all_songs&artist=2283',
1444+
input_entity_type: 'artist',
1445+
expected_relationship_type: 'streamingfree',
1446+
expected_clean_url: 'https://play.dogmazic.net/artists.php?action=show&artist=2283',
1447+
only_valid_entity_types: ['artist'],
1448+
},
1449+
{
1450+
input_url: 'https://play.dogmazic.net/rss.php?type=podcast&object_type=artist&object_id=2283',
1451+
input_entity_type: 'artist',
1452+
expected_relationship_type: 'streamingfree',
1453+
expected_clean_url: 'https://play.dogmazic.net/artists.php?action=show&artist=2283',
1454+
only_valid_entity_types: ['artist'],
1455+
},
1456+
{
1457+
input_url: 'https://play.dogmazic.net/batch.php?action=artist&id=2283',
1458+
input_entity_type: 'artist',
1459+
expected_relationship_type: 'streamingfree',
1460+
expected_clean_url: 'https://play.dogmazic.net/artists.php?action=show&artist=2283',
1461+
only_valid_entity_types: ['artist'],
1462+
},
1463+
{
1464+
input_url: 'https://play.dogmazic.net/artists.php?action=show&artist=2283#labels',
1465+
input_entity_type: 'artist',
1466+
expected_relationship_type: 'streamingfree',
1467+
expected_clean_url: 'https://play.dogmazic.net/artists.php?action=show&artist=2283',
1468+
only_valid_entity_types: ['artist'],
1469+
},
1470+
{
1471+
input_url: 'https://play.dogmazic.net/song.php?action=show_song&song_id=16660#artists.php?action=show&artist=2283',
1472+
input_entity_type: 'artist',
1473+
expected_relationship_type: 'streamingfree',
1474+
expected_clean_url: 'https://play.dogmazic.net/artists.php?action=show&artist=2283',
1475+
only_valid_entity_types: ['artist'],
1476+
},
1477+
{
1478+
input_url: 'https://play.dogmazic.net/artists.php?action=show&artist=2283#albums.php?action=show&album=3072',
1479+
input_entity_type: 'release',
1480+
expected_relationship_type: 'streamingfree',
1481+
expected_clean_url: 'https://play.dogmazic.net/albums.php?action=show&album=3072',
1482+
only_valid_entity_types: ['release'],
1483+
},
1484+
{
1485+
input_url: 'https://play.dogmazic.net/rss.php?type=podcast&object_type=album&object_id=3072',
1486+
input_entity_type: 'release',
1487+
expected_relationship_type: 'streamingfree',
1488+
expected_clean_url: 'https://play.dogmazic.net/albums.php?action=show&album=3072',
1489+
only_valid_entity_types: ['release'],
1490+
},
1491+
{
1492+
input_url: 'https://play.dogmazic.net/shout.php?action=show_add_shout&type=album&id=3072',
1493+
input_entity_type: 'release',
1494+
expected_relationship_type: 'streamingfree',
1495+
expected_clean_url: 'https://play.dogmazic.net/albums.php?action=show&album=3072',
1496+
only_valid_entity_types: ['release'],
1497+
},
1498+
{
1499+
input_url: 'https://play.dogmazic.net/batch.php?action=album&id%5B0%5D=3072',
1500+
input_entity_type: 'release',
1501+
expected_relationship_type: 'streamingfree',
1502+
expected_clean_url: 'https://play.dogmazic.net/albums.php?action=show&album=3072',
1503+
only_valid_entity_types: ['release'],
1504+
},
1505+
{
1506+
input_url: 'https://play.dogmazic.net/albums.php?action=show&album=3072#',
1507+
input_entity_type: 'release',
1508+
expected_relationship_type: 'streamingfree',
1509+
expected_clean_url: 'https://play.dogmazic.net/albums.php?action=show&album=3072',
1510+
only_valid_entity_types: ['release'],
1511+
},
1512+
{
1513+
input_url: 'https://play.dogmazic.net/shout.php?action=show_add_shout&type=label&id=443',
1514+
input_entity_type: 'label',
1515+
expected_relationship_type: 'streamingfree',
1516+
expected_clean_url: 'https://play.dogmazic.net/labels.php?action=show&label=443',
1517+
only_valid_entity_types: ['label'],
1518+
},
1519+
{
1520+
input_url: 'https://play.dogmazic.net/labels.php?action=show&label=443#songs',
1521+
input_entity_type: 'label',
1522+
expected_relationship_type: 'streamingfree',
1523+
expected_clean_url: 'https://play.dogmazic.net/labels.php?action=show&label=443',
1524+
only_valid_entity_types: ['label'],
1525+
},
1526+
{
1527+
input_url: 'https://play.dogmazic.net/song.php?action=show_song&song_id=16660#labels.php?action=show&name=Gauche%20d\'auteur%20(LibQ)',
1528+
input_entity_type: 'label',
1529+
expected_relationship_type: 'streamingfree',
1530+
expected_clean_url: 'https://play.dogmazic.net/labels.php?action=show&name=Gauche%20d\'auteur%20(LibQ)',
1531+
only_valid_entity_types: [],
1532+
},
1533+
{
1534+
input_url: 'https://play.dogmazic.net/albums.php?action=show&album=3072#song.php?action=show_song&song_id=16660',
1535+
input_entity_type: 'recording',
1536+
expected_relationship_type: 'streamingfree',
1537+
expected_clean_url: 'https://play.dogmazic.net/song.php?action=show&song_id=16660',
1538+
only_valid_entity_types: ['recording'],
1539+
},
1540+
{
1541+
input_url: 'https://play.dogmazic.net/shout.php?action=show_add_shout&type=song&id=16660',
1542+
input_entity_type: 'recording',
1543+
expected_relationship_type: 'streamingfree',
1544+
expected_clean_url: 'https://play.dogmazic.net/song.php?action=show&song_id=16660',
1545+
only_valid_entity_types: ['recording'],
1546+
},
1547+
{
1548+
input_url: 'https://play.dogmazic.net/play/index.php?type=song&oid=16660&uid=-1&name=Sophie%20jeukens%20-%20Casse-t-te.mp3',
1549+
input_entity_type: 'recording',
1550+
expected_relationship_type: 'streamingfree',
1551+
expected_clean_url: 'https://play.dogmazic.net/song.php?action=show&song_id=16660',
1552+
only_valid_entity_types: ['recording'],
1553+
},
1554+
{
1555+
input_url: 'https://play.dogmazic.net/stream.php?action=download&song_id=16660',
1556+
input_entity_type: 'recording',
1557+
expected_relationship_type: 'streamingfree',
1558+
expected_clean_url: 'https://play.dogmazic.net/song.php?action=show&song_id=16660',
1559+
only_valid_entity_types: ['recording'],
1560+
},
1561+
{
1562+
input_url: 'https://play.dogmazic.net/song.php?action=show_song&song_id=16660#',
1563+
input_entity_type: 'recording',
1564+
expected_relationship_type: 'streamingfree',
1565+
expected_clean_url: 'https://play.dogmazic.net/song.php?action=show&song_id=16660',
1566+
only_valid_entity_types: ['recording'],
1567+
},
14411568
// DRAM
14421569
{
14431570
input_url: 'http://www.dramonline.org/composers/buren-john-van',

0 commit comments

Comments
 (0)