View-defined library URIs, so we can have multiple library uris via Mopidy; Adding Jellyfin to docker; #716

This commit is contained in:
James Barnsley
2021-04-17 22:08:49 +12:00
parent 1c2777f0aa
commit a2d70c0329
23 changed files with 419 additions and 412 deletions

View File

@ -196,6 +196,8 @@ class Album extends React.Component {
filter,
} = this.state;
console.debug({ uri })
if (loading) {
return <Loader body loading />;
}

View File

@ -10,7 +10,6 @@ import Icon from '../../components/Icon';
import * as coreActions from '../../services/core/actions';
import * as uiActions from '../../services/ui/actions';
import * as mopidyActions from '../../services/mopidy/actions';
import * as googleActions from '../../services/google/actions';
import * as spotifyActions from '../../services/spotify/actions';
import { sortItems, applyFilter } from '../../util/arrays';
import Button from '../../components/Button';
@ -25,7 +24,6 @@ import {
const processKeys = [
'MOPIDY_GET_LIBRARY_ALBUMS',
'SPOTIFY_GET_LIBRARY_ALBUMS',
'GOOGLE_GET_LIBRARY_ALBUMS',
];
class LibraryAlbums extends React.Component {
@ -45,18 +43,14 @@ class LibraryAlbums extends React.Component {
} = this.props;
setWindowTitle(i18n('library.albums.title'));
this.getMopidyLibrary();
this.getGoogleLibrary();
this.getSpotifyLibrary();
this.getLibraries();
}
componentDidUpdate = ({ source: prevSource }) => {
const { source } = this.props;
if (source !== prevSource) {
this.getMopidyLibrary();
this.getGoogleLibrary();
this.getSpotifyLibrary();
this.getLibraries();
}
}
@ -64,9 +58,7 @@ class LibraryAlbums extends React.Component {
const { uiActions: { hideContextMenu } } = this.props;
hideContextMenu();
this.getMopidyLibrary(true);
this.getGoogleLibrary(true);
this.getSpotifyLibrary(true);
this.getLibraries(true);
}
cancelRefresh = () => {
@ -76,7 +68,7 @@ class LibraryAlbums extends React.Component {
cancelProcess(processKeys);
}
getMopidyLibrary = (forceRefetch = false) => {
getLibraries = (forceRefetch = false) => {
const {
source,
coreActions: {
@ -84,39 +76,13 @@ class LibraryAlbums extends React.Component {
},
} = this.props;
if (source !== 'local' && source !== 'all') return;
loadLibrary('mopidy:library:albums', { forceRefetch });
};
getGoogleLibrary = (forceRefetch = false) => {
const {
source,
google_available,
coreActions: {
loadLibrary,
},
} = this.props;
if (!google_available) return;
if (source !== 'google' && source !== 'all') return;
loadLibrary('google:library:albums', { forceRefetch });
};
getSpotifyLibrary = (forceRefetch = false) => {
const {
source,
spotify_available,
coreActions: {
loadLibrary,
},
} = this.props;
if (!spotify_available) return;
if (source !== 'spotify' && source !== 'all') return;
loadLibrary('spotify:library:albums', { forceRefetch });
let uris = [];
if (source === 'all') {
uris = this.sourceOptions().map((o) => o.value).filter((u) => u !== 'all');
} else {
uris.push(source);
}
uris.forEach((uri) => loadLibrary(uri, 'albums', { forceRefetch }));
};
handleContextMenu = (e, item) => {
@ -195,10 +161,49 @@ class LibraryAlbums extends React.Component {
);
}
render = () => {
sourceOptions = () => {
const {
spotify_available,
google_available,
youtube_available,
} = this.props;
const options = [
{
value: 'all',
label: i18n('fields.filters.all'),
},
{
value: 'local:directory?type=album',
label: i18n('services.mopidy.local'),
},
];
if (youtube_available) {
options.push({
value: 'ytmusic:album',
label: i18n('services.youtube.title'),
});
}
if (google_available) {
options.push({
value: 'gmusic:album',
label: i18n('services.google.title'),
});
}
if (spotify_available) {
options.push({
value: 'spotify:library:albums',
label: i18n('services.spotify.title'),
});
}
return options;
}
render = () => {
const {
sort,
view,
source,
@ -211,31 +216,6 @@ class LibraryAlbums extends React.Component {
per_page,
} = this.state;
const source_options = [
{
value: 'all',
label: i18n('fields.filters.all'),
},
{
value: 'local',
label: i18n('services.mopidy.local'),
},
];
if (spotify_available) {
source_options.push({
value: 'spotify',
label: i18n('services.spotify.title'),
});
}
if (google_available) {
source_options.push({
value: 'google',
label: i18n('services.google.title'),
});
}
const view_options = [
{
value: 'thumbnails',
@ -303,7 +283,7 @@ class LibraryAlbums extends React.Component {
name={i18n('fields.source')}
value={source}
valueAsLabel
options={source_options}
options={this.sourceOptions()}
handleChange={(val) => { uiActions.set({ library_albums_source: val }); uiActions.hideContextMenu(); }}
/>
<Button
@ -334,10 +314,11 @@ const librarySelector = makeLibrarySelector('albums');
const processProgressSelector = makeProcessProgressSelector(processKeys);
const mapStateToProps = (state) => ({
loading_progress: processProgressSelector(state),
mopidy_uri_schemes: state.mopidy.uri_schemes,
uri_schemes: state.mopidy.uri_schemes,
albums: librarySelector(state, 'albums'),
google_available: (state.mopidy.uri_schemes && state.mopidy.uri_schemes.includes('gmusic:')),
spotify_available: state.spotify.access_token,
google_available: state.mopidy?.uri_schemes?.includes('gmusic:'),
youtube_available: state.mopidy?.uri_schemes?.includes('ytmusic:'),
view: state.ui.library_albums_view,
source: getLibrarySource(state, 'albums'),
sort: state.ui.library_albums_sort,
@ -347,7 +328,6 @@ const mapDispatchToProps = (dispatch) => ({
coreActions: bindActionCreators(coreActions, dispatch),
uiActions: bindActionCreators(uiActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch),
googleActions: bindActionCreators(googleActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch),
});

View File

@ -22,7 +22,6 @@ import {
const processKeys = [
'MOPIDY_GET_LIBRARY_ARTISTS',
'SPOTIFY_GET_LIBRARY_ARTISTS',
'GOOGLE_GET_LIBRARY_ARTISTS',
];
class LibraryArtists extends React.Component {
@ -42,18 +41,14 @@ class LibraryArtists extends React.Component {
} = this.props;
setWindowTitle(i18n('library.artists.title'));
this.getMopidyLibrary();
this.getSpotifyLibrary();
this.getLibraries();
}
componentDidUpdate = ({ source: prevSource }) => {
const { source } = this.props;
if (source !== prevSource) {
this.getMopidyLibrary();
this.getGoogleLibrary();
this.getSpotifyLibrary();
this.getLibraries();
}
}
@ -61,9 +56,7 @@ class LibraryArtists extends React.Component {
const { uiActions: { hideContextMenu } } = this.props;
hideContextMenu();
this.getMopidyLibrary(true);
this.getGoogleLibrary(true);
this.getSpotifyLibrary(true);
this.getLibraries(true);
}
cancelRefresh = () => {
@ -93,7 +86,7 @@ class LibraryArtists extends React.Component {
});
}
getMopidyLibrary = (forceRefetch = false) => {
getLibraries = (forceRefetch = false) => {
const {
source,
coreActions: {
@ -101,40 +94,55 @@ class LibraryArtists extends React.Component {
},
} = this.props;
if (source !== 'local' && source !== 'all') return;
loadLibrary('mopidy:library:artists', { forceRefetch });
let uris = [];
if (source === 'all') {
uris = this.sourceOptions().map((o) => o.value).filter((u) => u !== 'all');
} else {
uris.push(source);
}
uris.forEach((uri) => loadLibrary(uri, 'artists', { forceRefetch }));
};
getGoogleLibrary = (forceRefetch = false) => {
sourceOptions = () => {
const {
source,
google_available,
coreActions: {
loadLibrary,
},
} = this.props;
if (!google_available) return;
if (source !== 'google' && source !== 'all') return;
loadLibrary('google:library:artists', { forceRefetch });
};
getSpotifyLibrary = (forceRefetch = false) => {
const {
source,
spotify_available,
coreActions: {
loadLibrary,
},
youtube_available,
google_available,
} = this.props;
const options = [
{
value: 'all',
label: i18n('fields.filters.all'),
},
{
value: 'local:directory?type=artist&role=albumartist',
label: i18n('services.mopidy.local'),
},
];
if (!spotify_available) return;
if (source !== 'spotify' && source !== 'all') return;
if (youtube_available) {
options.push({
value: 'ytmusic:artist',
label: i18n('services.youtube.title'),
});
}
loadLibrary('spotify:library:artists', { forceRefetch });
};
if (google_available) {
options.push({
value: 'gmusic:artist',
label: i18n('services.google.title'),
});
}
if (spotify_available) {
options.push({
value: 'spotify:library:artists',
label: i18n('services.spotify.title'),
});
}
return options;
}
renderView = () => {
const {
@ -182,36 +190,7 @@ class LibraryArtists extends React.Component {
}
render = () => {
const {
spotify_available,
google_available,
loading_progress,
} = this.props;
const source_options = [
{
value: 'all',
label: i18n('fields.filters.all'),
},
{
value: 'local',
label: i18n('services.mopidy.local'),
},
];
if (spotify_available) {
source_options.push({
value: 'spotify',
label: i18n('services.spotify.title'),
});
}
if (google_available) {
source_options.push({
value: 'google',
label: i18n('services.google.title'),
});
}
const { loading_progress } = this.props;
const view_options = [
{
@ -272,7 +251,7 @@ class LibraryArtists extends React.Component {
name={i18n('fields.source')}
value={this.props.source}
valueAsLabel
options={source_options}
options={this.sourceOptions()}
handleChange={(value) => { this.props.uiActions.set({ library_artists_source: value }); this.props.uiActions.hideContextMenu(); }}
/>
<Button
@ -303,9 +282,10 @@ const librarySelector = makeLibrarySelector('artists');
const processProgressSelector = makeProcessProgressSelector(processKeys);
const mapStateToProps = (state) => ({
loading_progress: processProgressSelector(state),
mopidy_uri_schemes: state.mopidy.uri_schemes,
google_available: (state.mopidy.uri_schemes && state.mopidy.uri_schemes.includes('gmusic:')),
uri_schemes: state.mopidy.uri_schemes,
spotify_available: (state.spotify.access_token),
google_available: state.mopidy?.uri_schemes?.includes('gmusic:'),
youtube_available: state.mopidy?.uri_schemes?.includes('ytmusic:'),
artists: librarySelector(state, 'artists'),
source: getLibrarySource(state, 'artists'),
sort: (state.ui.library_artists_sort ? state.ui.library_artists_sort : null),

View File

@ -73,7 +73,7 @@ class LibraryPlaylists extends React.Component {
if (source !== 'local' && source !== 'all') return;
loadLibrary('mopidy:library:playlists', { forceRefetch });
loadLibrary('mopidy:library:playlists', 'playlists', { forceRefetch });
};
getSpotifyLibrary = (forceRefetch = false) => {
@ -88,7 +88,7 @@ class LibraryPlaylists extends React.Component {
if (!spotify_available) return;
if (source !== 'spotify' && source !== 'all') return;
loadLibrary('spotify:library:playlists', { forceRefetch });
loadLibrary('spotify:library:playlists', 'playlists', { forceRefetch });
};
componentDidUpdate = ({ source: prevSource }) => {

View File

@ -81,7 +81,7 @@ class LibraryTracks extends React.Component {
if (source !== 'local' && source !== 'all') return;
loadLibrary('mopidy:library:tracks', { forceRefetch });
loadLibrary('mopidy:library:tracks', 'tracks', { forceRefetch });
};
getSpotifyLibrary = (forceRefetch = false) => {
@ -96,7 +96,7 @@ class LibraryTracks extends React.Component {
if (!spotify_available) return;
if (source !== 'spotify' && source !== 'all') return;
loadLibrary('spotify:library:tracks', { forceRefetch });
loadLibrary('spotify:library:tracks', 'tracks', { forceRefetch });
};
handleContextMenu = (e, item) => {

View File

@ -39,11 +39,11 @@ class AddToPlaylist extends React.Component {
} = this.props;
if (!spotify_library.length && spotify_available) {
loadLibrary('spotify:library:playlists');
loadLibrary('spotify:library:playlists', 'playlists');
}
if (!mopidy_library.length) {
loadLibrary('mopidy:library:playlists');
loadLibrary('mopidy:library:playlists', 'playlists');
}
setWindowTitle(i18n('modal.add_to_playlist.title'));