Skip to content

Commit d4b27bf

Browse files
authored
Merge pull request metabrainz#2119 from yvanzo/mbs-11684-dogmazic
MBS-11684: Handle Dogmazic URLs
2 parents 03aa4c5 + f499356 commit d4b27bf

File tree

7 files changed

+219
-0
lines changed

7 files changed

+219
-0
lines changed

lib/MusicBrainz/Server/Data/URL.pm

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ my %URL_SPECIALIZATIONS = (
5555
'Directlyrics' => qr{^https?://(?:www\.)?directlyrics\.com/}i,
5656
'Discogs' => qr{^https?://(?:www\.)?discogs\.com/}i,
5757
'DiscosDoBrasil' => qr{^https?://(?:www\.)?discosdobrasil\.com\.br/}i,
58+
'Dogmazic' => qr{^https?://(?:[^/]+\.)?dogmazic\.net/}i,
5859
'DNB' => qr{^https?://(?:www\.)?d-nb\.info/}i,
5960
'DRAM' => qr{^https?://(?:www\.)?dramonline\.org/}i,
6061
'DynamicRangeDB' => qr{^https?://dr\.loudness-war\.info/}i,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package MusicBrainz::Server::Entity::URL::Dogmazic;
2+
3+
use Moose;
4+
5+
use MusicBrainz::Server::Translation qw( l );
6+
7+
extends 'MusicBrainz::Server::Entity::URL';
8+
with 'MusicBrainz::Server::Entity::URL::Sidebar';
9+
10+
sub sidebar_name { l('Stream at Dogmazic') }
11+
12+
__PACKAGE__->meta->make_immutable;
13+
no Moose;
14+
1;
15+
16+
=head1 COPYRIGHT AND LICENSE
17+
18+
Copyright (C) 2021 MetaBrainz Foundation
19+
20+
This file is part of MusicBrainz, the open internet music database,
21+
and is licensed under the GPL version 2, or (at your option) any
22+
later version: http://www.gnu.org/licenses/gpl-2.0.txt
23+
24+
=cut
Loading

root/static/scripts/common/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const FAVICON_CLASSES = {
7272
'dhhu.dk': 'dhhu',
7373
'directlyrics.com': 'directlyrics',
7474
'discogs.com': 'discogs',
75+
'dogmazic.net': 'dogmazic',
7576
'dramonline.org': 'dram',
7677
'encyclopedisque.fr': 'encyclopedisque',
7778
'ester.ee': 'ester',

root/static/scripts/edit/URLCleanup.js

+65
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export const LINK_TYPES = {
205205
},
206206
streamingfree: {
207207
artist: '769085a1-c2f7-4c24-a532-2375a77693bd',
208+
label: '5b3d2907-5cd0-459b-9a33-d4398a544388',
208209
recording: '7e41ef12-a124-4324-afdb-fdbae687a89c',
209210
release: '08445ccf-7b99-4438-9f9a-fb9ac18099ee',
210211
},
@@ -1381,6 +1382,70 @@ const CLEANUPS = {
13811382
return {result: false};
13821383
},
13831384
},
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+
},
13841449
'downloadpurchase': {
13851450
match: [
13861451
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',

root/static/styles/favicons.less

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
.favicon("directlyrics", 32);
4545
.favicon("discogs", 32);
4646
.favicon("dnb");
47+
.favicon("dogmazic", 32);
4748
.favicon("dram");
4849
.favicon("encyclopedisque");
4950
.favicon("ester");

0 commit comments

Comments
 (0)