Skip to content

Commit

Permalink
Added a youtube playlist tracks identifier
Browse files Browse the repository at this point in the history
When a youtube playlist is entered in the search box, the different songs appear in the search results.
Known limitations :
- we should also be able to enter a song url (and not only playlist url) - not implemented
- for now, only the first 100 songs of the playlist are displayed
- some functionalities like "add all" or play all would make sense

A first step towards uniformization of components was taken but isn't deployed everywhere yet (only in search results for now).
  • Loading branch information
trekiteasy committed Jan 23, 2019
1 parent ba18c78 commit 5a24449
Show file tree
Hide file tree
Showing 12 changed files with 503 additions and 169 deletions.
102 changes: 76 additions & 26 deletions app/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import globals from '../globals';
const mb = require('../rest/Musicbrainz');
const discogs = require('../rest/Discogs');
const lastfmRest = require('../rest/LastFm');
const youtube = require('../rest/Youtube');

let lastfm = new core.LastFmApi(globals.lastfmApiKey, globals.lastfmApiSecret);

Expand Down Expand Up @@ -33,7 +34,10 @@ export const LASTFM_ARTIST_INFO_SEARCH_SUCCESS =
export const LASTFM_TRACK_SEARCH_START = 'LASTFM_TRACK_SEARCH_START';
export const LASTFM_TRACK_SEARCH_SUCCESS = 'LASTFM_TRACK_SEARCH_SUCCESS';

export function sourcesSearch(terms, plugins) {
export const YOUTUBE_PLAYLIST_SEARCH_START = 'YOUTUBE_PLAYLIST_SEARCH_START';
export const YOUTUBE_PLAYLIST_SEARCH_SUCCESS = 'YOUTUBE_PLAYLIST_SEARCH_SUCCESS';

export function sourcesSearch (terms, plugins) {
let searchResults = {};
for (let i = 0; i < plugins.musicSources.length; i++) {
Object.assign(searchResults, plugins.musicSources[i].search(terms));
Expand All @@ -44,27 +48,27 @@ export function sourcesSearch(terms, plugins) {
};
}

export function unifiedSearchStart() {
export function unifiedSearchStart () {
return {
type: UNIFIED_SEARCH_START,
payload: true
};
}

export function unifiedSearchSuccess() {
export function unifiedSearchSuccess () {
return {
type: UNIFIED_SEARCH_SUCCESS,
payload: false
};
}

export function unifiedSearchError() {
export function unifiedSearchError () {
return {
type: UNIFIED_SEARCH_ERROR
};
}

function discogsSearch(terms, searchType, dispatchType) {
function discogsSearch (terms, searchType, dispatchType) {
return dispatch => {
return searchType(terms)
.then(searchResults => searchResults.json())
Expand All @@ -81,22 +85,22 @@ function discogsSearch(terms, searchType, dispatchType) {
};
}

export function albumSearch(terms) {
export function albumSearch (terms) {
return discogsSearch(terms, discogs.searchReleases, 'ALBUM_SEARCH_SUCCESS');
}

export function artistSearch(terms) {
export function artistSearch (terms) {
return discogsSearch(terms, discogs.searchArtists, 'ARTIST_SEARCH_SUCCESS');
}

export function lastFmTrackSearchStart(terms) {
export function lastFmTrackSearchStart (terms) {
return {
type: LASTFM_TRACK_SEARCH_START,
payload: terms
};
}

export function lastFmTrackSearchSuccess(terms, searchResults) {
export function lastFmTrackSearchSuccess (terms, searchResults) {
return {
type: LASTFM_TRACK_SEARCH_SUCCESS,
payload: {
Expand All @@ -106,7 +110,7 @@ export function lastFmTrackSearchSuccess(terms, searchResults) {
};
}

export function lastFmTrackSearch(terms) {
export function lastFmTrackSearch (terms) {
return dispatch => {
dispatch(lastFmTrackSearchStart(terms));
Promise.all([lastfmRest.searchTracks(terms)])
Expand All @@ -122,16 +126,60 @@ export function lastFmTrackSearch(terms) {
};
}

export function unifiedSearch(terms, history) {
export function youtubePlaylistSearchStart (terms) {
return {
type: YOUTUBE_PLAYLIST_SEARCH_START,
payload: terms
};
}

export function youtubePlaylistSearchSuccess (terms, results) {
return {
type: YOUTUBE_PLAYLIST_SEARCH_SUCCESS,
payload: {
id: terms,
info: results
}
};
}

export function youtubePlaylistSearch (terms) {
return dispatch => {
dispatch(youtubePlaylistSearchStart(terms));

youtube.playlistSearch(terms)
.then(results => {
//console.log(results)
dispatch(
youtubePlaylistSearchSuccess(terms, results)
);
})
.catch(error => {
logger.error(error);
});
/*Promise.all([lastfmRest.searchTracks(terms)])
.then(results => Promise.all(results.map(info => info.json())))
.then(results => {
dispatch(
//youtubePlaylistSearchSuccess(terms, results[0].results.trackmatches.track)
);
})
.catch(error => {
logger.error(error);
});*/
};
}

export function unifiedSearch (terms, history) {
return dispatch => {
dispatch(unifiedSearchStart());

Promise.all([
dispatch(albumSearch(terms)),
dispatch(artistSearch(terms)),
dispatch(lastFmTrackSearch(terms))
dispatch(lastFmTrackSearch(terms)),
dispatch(youtubePlaylistSearch(terms))
])

.then(() => {
dispatch(unifiedSearchSuccess());
if (history.location.pathname !== '/search') {
Expand All @@ -145,14 +193,14 @@ export function unifiedSearch(terms, history) {
};
}

export function albumInfoStart(albumId) {
export function albumInfoStart (albumId) {
return {
type: ALBUM_INFO_SEARCH_START,
payload: albumId
};
}

export function albumInfoSuccess(albumId, info) {
export function albumInfoSuccess (albumId, info) {
return {
type: ALBUM_INFO_SEARCH_SUCCESS,
payload: {
Expand All @@ -162,7 +210,7 @@ export function albumInfoSuccess(albumId, info) {
};
}

export function albumInfoSearch(albumId, releaseType) {
export function albumInfoSearch (albumId, releaseType) {
return dispatch => {
dispatch(albumInfoStart(albumId));
discogs
Expand All @@ -183,14 +231,14 @@ export function albumInfoSearch(albumId, releaseType) {
};
}

export function artistInfoStart(artistId) {
export function artistInfoStart (artistId) {
return {
type: ARTIST_INFO_SEARCH_START,
payload: artistId
};
}

export function artistInfoSuccess(artistId, info) {
export function artistInfoSuccess (artistId, info) {
return {
type: ARTIST_INFO_SEARCH_SUCCESS,
payload: {
Expand All @@ -200,7 +248,7 @@ export function artistInfoSuccess(artistId, info) {
};
}

export function artistInfoSearch(artistId) {
export function artistInfoSearch (artistId) {
return dispatch => {
dispatch(artistInfoStart(artistId));
discogs
Expand All @@ -216,14 +264,14 @@ export function artistInfoSearch(artistId) {
};
}

export function artistReleasesStart(artistId) {
export function artistReleasesStart (artistId) {
return {
type: ARTIST_RELEASES_SEARCH_START,
payload: artistId
};
}

export function artistReleasesSuccess(artistId, releases) {
export function artistReleasesSuccess (artistId, releases) {
return {
type: ARTIST_RELEASES_SEARCH_SUCCESS,
payload: {
Expand All @@ -233,7 +281,7 @@ export function artistReleasesSuccess(artistId, releases) {
};
}

export function artistReleasesSearch(artistId) {
export function artistReleasesSearch (artistId) {
return dispatch => {
dispatch(artistReleasesStart(artistId));
discogs
Expand All @@ -248,7 +296,7 @@ export function artistReleasesSearch(artistId) {
};
}

export function artistInfoSearchByName(artistName, history) {
export function artistInfoSearchByName (artistName, history) {
return dispatch => {
discogs
.searchArtists(artistName)
Expand All @@ -267,14 +315,14 @@ export function artistInfoSearchByName(artistName, history) {
};
}

export function lastFmArtistInfoStart(artistId) {
export function lastFmArtistInfoStart (artistId) {
return {
type: LASTFM_ARTIST_INFO_SEARCH_START,
payload: artistId
};
}

export function lastFmArtistInfoSuccess(artistId, info) {
export function lastFmArtistInfoSuccess (artistId, info) {
return {
type: LASTFM_ARTIST_INFO_SEARCH_SUCCESS,
payload: {
Expand All @@ -284,7 +332,7 @@ export function lastFmArtistInfoSuccess(artistId, info) {
};
}

export function lastFmArtistInfoSearch(artist, artistId) {
export function lastFmArtistInfoSearch (artist, artistId) {
return dispatch => {
dispatch(lastFmArtistInfoStart(artistId));
Promise.all([
Expand All @@ -305,3 +353,5 @@ export function lastFmArtistInfoSearch(artist, artistId) {
});
};
}


Loading

3 comments on commit 5a24449

@nukeop
Copy link
Owner

@nukeop nukeop commented on 5a24449 Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we often have to merge master back, why don't we work on separate branches from now on if we're working on larger features? This way we'll have more control over merging/reverting features.

@trekiteasy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree for larger works (such as this one). Will do this on future features. I think I should continue working directly on master for small bug fixes or code style fixes.

@nukeop
Copy link
Owner

@nukeop nukeop commented on 5a24449 Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agreed.

Please sign in to comment.