2017-10-09 21:08:27 +13:00
|
|
|
|
2019-02-20 21:08:48 +13:00
|
|
|
import React from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
2017-10-09 21:08:27 +13:00
|
|
|
|
2019-01-25 15:42:00 +13:00
|
|
|
import Link from '../components/Link';
|
2019-01-22 21:46:56 +13:00
|
|
|
import ErrorMessage from '../components/ErrorMessage';
|
2019-02-20 21:08:48 +13:00
|
|
|
import Header from '../components/Header';
|
|
|
|
|
import TrackList from '../components/TrackList';
|
|
|
|
|
import Thumbnail from '../components/Thumbnail';
|
|
|
|
|
import ArtistSentence from '../components/ArtistSentence';
|
|
|
|
|
import ArtistGrid from '../components/ArtistGrid';
|
|
|
|
|
import FollowButton from '../components/Fields/FollowButton';
|
|
|
|
|
import LastfmLoveButton from '../components/Fields/LastfmLoveButton';
|
|
|
|
|
import Dater from '../components/Dater';
|
|
|
|
|
import LazyLoadListener from '../components/LazyLoadListener';
|
|
|
|
|
import ContextMenuTrigger from '../components/ContextMenuTrigger';
|
|
|
|
|
import URILink from '../components/URILink';
|
|
|
|
|
import Icon from '../components/Icon';
|
|
|
|
|
import Popularity from '../components/Popularity';
|
|
|
|
|
|
|
|
|
|
import * as helpers from '../helpers';
|
|
|
|
|
import * as coreActions from '../services/core/actions';
|
|
|
|
|
import * as uiActions from '../services/ui/actions';
|
|
|
|
|
import * as mopidyActions from '../services/mopidy/actions';
|
|
|
|
|
import * as spotifyActions from '../services/spotify/actions';
|
|
|
|
|
import * as lastfmActions from '../services/lastfm/actions';
|
|
|
|
|
import * as geniusActions from '../services/genius/actions';
|
2017-10-09 21:08:27 +13:00
|
|
|
|
|
|
|
|
class Track extends React.Component{
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2017-10-09 21:08:27 +13:00
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
2019-01-23 21:50:38 +13:00
|
|
|
this.props.coreActions.loadTrack(this.props.uri);
|
2018-09-20 16:29:16 +12:00
|
|
|
|
|
|
|
|
// We already have the track in our index, so it won't fire componentWillReceiveProps
|
|
|
|
|
if (this.props.track){
|
|
|
|
|
this.setWindowTitle(this.props.track);
|
|
|
|
|
|
2018-11-26 08:43:16 +13:00
|
|
|
if (this.props.genius_authorized && this.props.track.artists && !this.props.track.lyrics_results){
|
2018-09-20 16:29:16 +12:00
|
|
|
this.props.geniusActions.findTrackLyrics(this.props.track);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleContextMenu(e){
|
|
|
|
|
e.preventDefault()
|
2019-01-23 21:50:38 +13:00
|
|
|
var data = { uris: [this.props.uri] }
|
2017-10-10 13:05:28 +13:00
|
|
|
this.props.uiActions.showContextMenu(e, data, 'track', 'click' )
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
componentWillReceiveProps(nextProps){
|
2017-10-09 21:08:27 +13:00
|
|
|
|
2017-11-04 22:09:51 +13:00
|
|
|
// if our URI has changed, fetch new track
|
2019-01-23 21:50:38 +13:00
|
|
|
if (nextProps.uri != this.props.uri){
|
|
|
|
|
this.props.coreActions.loadTrack(nextProps.uri);
|
2017-10-09 21:08:27 +13:00
|
|
|
|
2018-10-18 16:47:35 +13:00
|
|
|
if (nextProps.genius_authorized && nextProps.tracks.artists){
|
2018-09-20 16:29:16 +12:00
|
|
|
this.props.geniusActions.findTrackLyrics(nextProps.track);
|
2018-09-19 16:59:48 +12:00
|
|
|
}
|
|
|
|
|
|
2017-11-04 22:09:51 +13:00
|
|
|
// if mopidy has just connected AND we're not a Spotify track, go get
|
2017-10-09 21:08:27 +13:00
|
|
|
} else if (!this.props.mopidy_connected && nextProps.mopidy_connected){
|
2019-01-23 21:50:38 +13:00
|
|
|
if (helpers.uriSource(this.props.uri) != 'spotify'){
|
|
|
|
|
this.props.coreActions.loadTrack(nextProps.uri);
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
2017-10-10 11:50:29 +13:00
|
|
|
}
|
|
|
|
|
|
2018-09-20 16:29:16 +12:00
|
|
|
// We have just received our full track or our track artists
|
|
|
|
|
if ((!this.props.track && nextProps.track) || (!this.props.track.artists && nextProps.track.artists)){
|
2017-11-06 16:59:21 +13:00
|
|
|
|
2018-09-20 16:29:16 +12:00
|
|
|
this.setWindowTitle(nextProps.track);
|
2018-06-28 08:12:03 +12:00
|
|
|
|
2017-11-06 16:59:21 +13:00
|
|
|
// Ready to load LastFM
|
|
|
|
|
if (nextProps.lastfm_authorized){
|
2017-11-13 21:19:02 +13:00
|
|
|
this.props.lastfmActions.getTrack(nextProps.track.uri);
|
2017-11-06 16:59:21 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ready to load lyrics
|
2018-08-21 21:08:11 +12:00
|
|
|
if (nextProps.genius_authorized && !nextProps.track.lyrics_results){
|
2017-11-06 16:59:21 +13:00
|
|
|
this.props.geniusActions.findTrackLyrics(nextProps.track);
|
|
|
|
|
}
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
2018-06-29 14:26:06 +12:00
|
|
|
|
|
|
|
|
if (!this.props.track && nextProps.track){
|
|
|
|
|
this.setWindowTitle(nextProps.track);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 19:58:36 +12:00
|
|
|
setWindowTitle(track = this.props.track){
|
2018-06-29 14:26:06 +12:00
|
|
|
if (track){
|
|
|
|
|
var artists = "";
|
|
|
|
|
for (var i = 0; i < track.artists.length; i++){
|
|
|
|
|
if (artists != ""){
|
|
|
|
|
artists += ", ";
|
|
|
|
|
}
|
|
|
|
|
artists += track.artists[i].name;
|
|
|
|
|
}
|
|
|
|
|
this.props.uiActions.setWindowTitle(track.name+" by "+artists+" (track)");
|
|
|
|
|
} else{
|
|
|
|
|
this.props.uiActions.setWindowTitle("Track");
|
|
|
|
|
}
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleContextMenu(e){
|
|
|
|
|
var data = {
|
|
|
|
|
e: e,
|
|
|
|
|
context: 'track',
|
|
|
|
|
items: [this.props.track],
|
2019-01-23 21:50:38 +13:00
|
|
|
uris: [this.props.uri]
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
this.props.uiActions.showContextMenu(data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
play(){
|
2019-01-23 21:50:38 +13:00
|
|
|
this.props.mopidyActions.playURIs([this.props.uri], this.props.uri)
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
|
2017-10-17 18:54:57 +13:00
|
|
|
renderLyricsSelector(){
|
2018-02-12 08:14:13 +13:00
|
|
|
if (this.props.track.lyrics_results === undefined || this.props.track.lyrics_results === null){
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
} else if (this.props.track.lyrics_results.length <= 0){
|
2017-10-17 20:24:31 +13:00
|
|
|
return (
|
|
|
|
|
<div className="field lyrics-selector">
|
|
|
|
|
<div className="input">
|
2018-02-12 08:14:13 +13:00
|
|
|
<input type="text" disabled="disabled" value="No results" />
|
2017-10-17 20:24:31 +13:00
|
|
|
<div className="description">
|
|
|
|
|
Switch to another lyrics seach result
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2017-10-17 18:54:57 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="field lyrics-selector">
|
|
|
|
|
<div className="input">
|
|
|
|
|
<select
|
|
|
|
|
onChange={e => this.props.geniusActions.getTrackLyrics(this.props.track.uri, e.target.value)}>
|
|
|
|
|
{
|
|
|
|
|
this.props.track.lyrics_results.map(result => {
|
|
|
|
|
return (
|
2018-08-13 19:58:36 +12:00
|
|
|
<option
|
|
|
|
|
key={result.path}
|
2018-07-04 21:10:51 +12:00
|
|
|
value={result.path}
|
|
|
|
|
defaultValue={result.path == this.props.track.lyrics_path}
|
2017-10-17 18:54:57 +13:00
|
|
|
>
|
|
|
|
|
{result.title}
|
|
|
|
|
</option>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</select>
|
|
|
|
|
<div className="description">
|
|
|
|
|
Switch to another lyrics seach result
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 21:08:27 +13:00
|
|
|
renderLyrics(){
|
|
|
|
|
if (helpers.isLoading(this.props.load_queue,['genius_'])){
|
|
|
|
|
return (
|
2017-10-17 20:12:59 +13:00
|
|
|
<div className="lyrics">
|
|
|
|
|
<div className="body-loader loading">
|
|
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
2017-10-09 21:08:27 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
2017-10-17 20:24:31 +13:00
|
|
|
} else if (this.props.track.lyrics){
|
2017-10-17 18:54:57 +13:00
|
|
|
return (
|
|
|
|
|
<div className="lyrics">
|
|
|
|
|
<div className="content" dangerouslySetInnerHTML={{__html: this.props.track.lyrics}}></div>
|
2018-10-13 15:57:01 +13:00
|
|
|
<div className="origin mid_grey-text">
|
2018-07-04 21:10:51 +12:00
|
|
|
Origin: <a href={"https://genius.com"+this.props.track.lyrics_path} target="_blank">{"https://genius.com"+this.props.track.lyrics_path}</a>
|
2017-10-17 18:54:57 +13:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2017-10-17 20:24:31 +13:00
|
|
|
} else {
|
2019-01-22 21:46:56 +13:00
|
|
|
return (
|
|
|
|
|
<ErrorMessage type="not-found" title="Not found">
|
2019-01-30 16:59:51 +13:00
|
|
|
<p>Could not find track with URI "{encodeURIComponent(this.props.uri)}"</p>
|
2019-01-22 21:46:56 +13:00
|
|
|
</ErrorMessage>
|
|
|
|
|
);
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
2019-01-23 21:50:38 +13:00
|
|
|
if (helpers.isLoading(this.props.load_queue,['spotify_track/'+helpers.getFromUri('trackid',this.props.uri)])){
|
2017-10-09 21:08:27 +13:00
|
|
|
return (
|
|
|
|
|
<div className="body-loader loading">
|
|
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this.props.track){
|
|
|
|
|
return null
|
2017-10-10 11:50:29 +13:00
|
|
|
} else {
|
2018-11-20 21:35:35 +13:00
|
|
|
var track = this.props.track;
|
|
|
|
|
|
|
|
|
|
// Flatten our simple album so we can inherit artwork
|
|
|
|
|
if (track.album){
|
|
|
|
|
var album = this.props.albums[track.album.uri];
|
|
|
|
|
|
|
|
|
|
if (album && album.images){
|
|
|
|
|
track.images = album.images;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view track-view content-wrapper">
|
|
|
|
|
|
2018-08-13 19:58:36 +12:00
|
|
|
{this.props.slim_mode ? <Header
|
|
|
|
|
icon="music"
|
|
|
|
|
title="Track"
|
|
|
|
|
handleContextMenuTrigger={e => this.handleContextMenu(e)}
|
2017-10-10 11:50:29 +13:00
|
|
|
uiActions={this.props.uiActions} /> : null}
|
2017-10-09 21:08:27 +13:00
|
|
|
|
|
|
|
|
<div className="thumbnail-wrapper">
|
2018-08-21 21:49:43 +12:00
|
|
|
<Thumbnail size="large" canZoom images={track.images} />
|
2017-10-09 21:08:27 +13:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="title">
|
|
|
|
|
|
2017-10-10 11:50:29 +13:00
|
|
|
<h1>{track.name}</h1>
|
2018-10-13 15:57:01 +13:00
|
|
|
<h2 className="mid_grey-text">
|
2019-01-22 16:57:43 +13:00
|
|
|
{track.album && track.album.uri ? <Link to={'/album/'+track.album.uri}>{track.album.name}</Link> : null}
|
2018-02-12 08:14:13 +13:00
|
|
|
{track.album && !track.album.uri ? track.album.name : null}
|
|
|
|
|
{!track.album ? "Unknown album" : null}
|
|
|
|
|
by <ArtistSentence artists={track.artists} />
|
|
|
|
|
</h2>
|
2017-10-09 21:08:27 +13:00
|
|
|
|
|
|
|
|
<ul className="details">
|
2019-02-25 18:37:43 +13:00
|
|
|
{!this.props.slim_mode ? <li className="source"><Icon type="fontawesome" name={helpers.sourceIcon(this.props.uri)} /></li> : null}
|
2017-10-10 11:50:29 +13:00
|
|
|
{track.date ? <li><Dater type="date" data={track.date} /></li> : null}
|
|
|
|
|
{track.explicit ? <li><span className="flag dark">EXPLICIT</span></li> : null}
|
|
|
|
|
<li>
|
|
|
|
|
{track.disc_number ? <span>Disc {track.disc_number}</span> : null}
|
2017-10-10 13:32:04 +13:00
|
|
|
{track.disc_number && track.track_number ? <span>, </span> : null}
|
|
|
|
|
{track.track_number ? <span>Track {track.track_number}</span> : null}
|
2017-10-10 11:50:29 +13:00
|
|
|
</li>
|
2017-10-19 09:58:26 +13:00
|
|
|
{track.duration ? <li><Dater type="length" data={track.duration} /></li> : null}
|
2018-11-20 21:35:35 +13:00
|
|
|
{track.popularity ? <li>{track.popularity}% popularity</li> : null}
|
2017-10-09 21:08:27 +13:00
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="actions">
|
2018-12-07 15:57:20 +13:00
|
|
|
<button className="button button--primary" onClick={e => this.play()}>Play</button>
|
2019-01-23 21:50:38 +13:00
|
|
|
<LastfmLoveButton uri={this.props.uri} artist={(this.props.track.artists ? this.props.track.artists[0].name : null)} track={this.props.track.name} addText="Love" removeText="Unlove" is_loved={this.props.track.userloved} />
|
2017-11-04 22:09:51 +13:00
|
|
|
<ContextMenuTrigger onTrigger={e => this.handleContextMenu(e)} />
|
2017-10-09 21:08:27 +13:00
|
|
|
</div>
|
|
|
|
|
|
2019-02-10 19:51:33 +13:00
|
|
|
{!this.props.genius_authorized ? <p className="no-results">Want track lyrics? Authorize Genius under <Link to="/settings/genius" scrollTo="#services-menu">Settings</Link>.</p> : null}
|
2018-08-21 21:08:11 +12:00
|
|
|
{this.props.genius_authorized ? this.renderLyricsSelector() : null}
|
|
|
|
|
{this.props.genius_authorized ? this.renderLyrics() : null}
|
2017-10-09 21:08:27 +13:00
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-25 19:18:27 +13:00
|
|
|
/**
|
|
|
|
|
* Rebuild a track URI with some ugly-ass handling of encoding.
|
|
|
|
|
*
|
|
|
|
|
* Basically the ID part of a Mopidy URI needs to be encoded, but the rest of the URI can't be.
|
|
|
|
|
* This means we need to break down the URI (decoded) and then reconstruct with an encoded ID
|
|
|
|
|
* because the URI is passed to us from a URL.
|
|
|
|
|
*
|
|
|
|
|
* @param uri String
|
|
|
|
|
* @return String
|
|
|
|
|
**/
|
|
|
|
|
const rebuildUri = (uri) => {
|
|
|
|
|
var rebuilt_uri = helpers.uriSource(uri)+':'+helpers.uriType(uri)+':';
|
|
|
|
|
|
|
|
|
|
// Escape unreserved characters (RFC 3986)
|
|
|
|
|
// https://stackoverflow.com/questions/18251399/why-doesnt-encodeuricomponent-encode-single-quotes-apostrophes
|
|
|
|
|
var id = helpers.getFromUri('trackid', uri);
|
|
|
|
|
id = encodeURIComponent(id).replace(/[!'()*]/g, escape);
|
|
|
|
|
|
|
|
|
|
// Reinstate slashes for the Mopidy-Local structure
|
|
|
|
|
id = id.replace(/%2F/g, '/');
|
|
|
|
|
|
|
|
|
|
return rebuilt_uri+id;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 21:08:27 +13:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2019-01-23 21:50:38 +13:00
|
|
|
var uri = decodeURIComponent(ownProps.match.params.uri);
|
2019-02-25 19:18:27 +13:00
|
|
|
uri = rebuildUri(uri);
|
2019-02-25 18:37:43 +13:00
|
|
|
|
2017-10-09 21:08:27 +13:00
|
|
|
return {
|
2019-01-23 21:50:38 +13:00
|
|
|
uri: uri,
|
2017-10-09 21:08:27 +13:00
|
|
|
slim_mode: state.ui.slim_mode,
|
|
|
|
|
load_queue: state.ui.load_queue,
|
2017-10-26 20:36:27 +13:00
|
|
|
track: (state.core.tracks && state.core.tracks[uri] !== undefined ? state.core.tracks[uri] : false),
|
2017-10-09 21:08:27 +13:00
|
|
|
tracks: state.core.tracks,
|
|
|
|
|
artists: state.core.artists,
|
|
|
|
|
albums: state.core.albums,
|
|
|
|
|
spotify_library_albums: state.spotify.library_albums,
|
|
|
|
|
local_library_albums: state.mopidy.library_albums,
|
2018-10-01 21:51:46 +13:00
|
|
|
lastfm_authorized: state.lastfm.authorization,
|
2017-10-09 21:08:27 +13:00
|
|
|
spotify_authorized: state.spotify.authorization,
|
2018-08-21 21:08:11 +12:00
|
|
|
genius_authorized: state.genius.authorization,
|
2017-10-09 21:08:27 +13:00
|
|
|
mopidy_connected: state.mopidy.connected
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2018-08-13 19:58:36 +12:00
|
|
|
coreActions: bindActionCreators(coreActions, dispatch),
|
2017-10-09 21:08:27 +13:00
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
2017-11-04 22:09:51 +13:00
|
|
|
lastfmActions: bindActionCreators(lastfmActions, dispatch),
|
2017-10-09 21:08:27 +13:00
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch),
|
|
|
|
|
geniusActions: bindActionCreators(geniusActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 19:58:36 +12:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Track)
|