-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBS-12205: Add "play on ListenBrainz" button
This mostly copies the functionality of the existing script (https://gist.github.com/MonkeyDo/6b919302e97dc979f8277b9c71ff82ab). It shows a "Play on ListenBrainz" button on the right side of releases, recordings, recording collections and release groups that sends the user to play the release or a custom grouping of recordings with BrainzPlayer. It only shows on overview pages for recording collections and RGs, but that's also true of the script so hopefully not a problem. Ideally, LB would support passing an RG or collection MBID directly. Keep in mind this doesn't hit LB and doesn't know whether LB can actually play the music (I'm not sure even hitting LB would help since LB might also not know until it tries).
- Loading branch information
1 parent
dc3d5b0
commit 314e3f2
Showing
11 changed files
with
148 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
root/layout/components/sidebar/PlayOnListenBrainzButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* @flow strict | ||
* Copyright (C) 2017 MetaBrainz Foundation | ||
* | ||
* This file is part of MusicBrainz, the open internet music database, | ||
* and is licensed under the GPL version 2, or (at your option) any | ||
* later version: http://www.gnu.org/licenses/gpl-2.0.txt | ||
*/ | ||
|
||
import * as React from 'react'; | ||
|
||
import listenBrainzIconUrl | ||
from '../../../static/images/icons/listenbrainz.png'; | ||
|
||
type Props = { | ||
+entityType: 'release' | 'recording', | ||
+mbids: string | $ReadOnlyArray<string>, | ||
}; | ||
|
||
function getListenBrainzLink( | ||
entityType: 'release' | 'recording', | ||
mbids: string | $ReadOnlyArray<string>, | ||
): string | null { | ||
let formattedMbids; | ||
|
||
if (Array.isArray(mbids)) { | ||
formattedMbids = mbids.join(','); | ||
} else { | ||
formattedMbids = mbids; | ||
} | ||
|
||
if (entityType === 'release') { | ||
return `//listenbrainz.org/player/release/${formattedMbids}`; | ||
} | ||
|
||
if (entityType === 'recording') { | ||
return `//listenbrainz.org/player?recording_mbids=${formattedMbids}`; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
const PlayOnListenBrainzButton = ({ | ||
entityType, | ||
mbids, | ||
}: Props): React.Element<'a'> | null => { | ||
const link = getListenBrainzLink(entityType, mbids); | ||
|
||
if (link == null) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<a | ||
className="styled-button listenbrainz-button" | ||
href={link} | ||
rel="noreferrer" | ||
target="_blank" | ||
> | ||
<img | ||
alt={l('ListenBrainz')} | ||
className="warning" | ||
src={listenBrainzIconUrl} | ||
/> | ||
{' '} | ||
{l('Play on ListenBrainz')} | ||
</a> | ||
); | ||
}; | ||
|
||
export default PlayOnListenBrainzButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters