Skip to content

Commit

Permalink
fix(local): fetch missing metadata from acousticId api (nukeop#342)
Browse files Browse the repository at this point in the history
* fix(local): fetch missing metadata from acousticId api

* fix: make acousticId fetching works

* fix(local): handle case when no meta at all

* feat(local): persist local files metadata in electron-store

* fix(local): fix windows issues

* fix: improve storage

* fix(local): add message when api off on library view

* fix: remove useless dependencies
  • Loading branch information
Charles Jacquin authored and nukeop committed Jul 8, 2019
1 parent a215a34 commit d95b8b0
Show file tree
Hide file tree
Showing 30 changed files with 393 additions and 149 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ package-lock.json

# vscode
.vscode/
tsconfig.json
tsconfig.json

#nvm
.nvmrc
5 changes: 1 addition & 4 deletions app/actions/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ export function scanLocalFolders() {
export function scanLocalFoldersSuccess(payload) {
return {
type: SCAN_LOCAL_FOLDER_SUCCESS,
payload: payload.reduce((acc, track) => ({
...acc,
[track.uuid]: track
}), {})
payload
};
}

Expand Down
21 changes: 21 additions & 0 deletions app/components/LibraryView/NoApi/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { Icon, Button } from 'semantic-ui-react';

import styles from './styles.scss';

export default ({ enableApi }) => {
const { t } = useTranslation('library');
const handleClick = useCallback(() => {
enableApi('api.enabled', true);
});

return (
<div className={styles.library_empty_state}>
<Icon name='file audio outline' />
<h2>{ t('no-api')}</h2>
<div>{ t('no-api-help')}</div>
<Button onClick={handleClick}>{t('api-enable')}</Button>
</div>
);
};
6 changes: 6 additions & 0 deletions app/components/LibraryView/NoApi/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import '../../../mixin.scss';

.library_no_api {
@include emptyState;
padding: 6rem 0;
}
47 changes: 27 additions & 20 deletions app/components/LibraryView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
Table
} from 'semantic-ui-react';
import { useTranslation } from 'react-i18next';
import _ from 'lodash';

import Header from '../Header';
import TrackRow from '../TrackRow';
import EmptyState from './EmptyState';
import NoApi from './NoApi';

import trackRowStyles from '../TrackRow/styles.scss';
import styles from './index.scss';
Expand All @@ -25,7 +27,8 @@ const LibraryView = ({
pending,
localFolders,
sortBy,
direction
direction,
api
}) => {
const handleSort = useCallback(
columnName => () => {
Expand Down Expand Up @@ -73,10 +76,11 @@ const LibraryView = ({
</List>
</Segment>
<Segment>
{
_.isEmpty(tracks)
? <EmptyState />
: <React.Fragment>
{api ? (
_.isEmpty(tracks) ? (
<EmptyState />
) : (
<React.Fragment>
<div className={styles.search_field}>
<Input
inverted
Expand All @@ -89,8 +93,8 @@ const LibraryView = ({
</div>

<Segment inverted className={trackRowStyles.tracks_container}>
<Dimmer active={pending} loading={pending} />
<Dimmer active={pending} loading={pending.toString()} />

{!pending && (
<Table sortable className={styles.table}>
<Table.Header className={styles.thead}>
Expand Down Expand Up @@ -120,24 +124,27 @@ const LibraryView = ({
</Table.Header>
<Table.Body className={styles.tbody}>
{tracks &&
tracks.map((track, idx) => (
<TrackRow
key={'favorite-track-' + idx}
track={track}
index={idx}
displayCover
displayArtist
displayAlbum
withAddToDownloads={false}
isLocal
/>
))}
tracks.map((track, idx) => (
<TrackRow
key={'favorite-track-' + idx}
track={track}
index={idx}
displayCover
displayArtist
displayAlbum
withAddToDownloads={false}
isLocal
/>
))}
</Table.Body>
</Table>
)}
</Segment>
</React.Fragment>
}
)
) : (
<NoApi enableApi={actions.setBooleanOption} />
)}
</Segment>
</div>
);
Expand Down
6 changes: 4 additions & 2 deletions app/containers/LibraryViewContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import _ from 'lodash';

import LibraryView from '../../components/LibraryView';
import * as LocalActions from '../../actions/local';
import * as SettingsActions from '../../actions/settings';

function mapStateToProps(state) {
const lowercaseFilter = _.lowerCase(state.local.filter);
Expand Down Expand Up @@ -35,13 +36,14 @@ function mapStateToProps(state) {

localFolders: state.local.folders,
sortBy: state.local.sortBy,
direction: state.local.direction
direction: state.local.direction,
api: state.settings['api.enabled']
};
}

function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({ ...LocalActions }, dispatch)
actions: bindActionCreators({ ...LocalActions, ...SettingsActions }, dispatch)
};
}

Expand Down
5 changes: 4 additions & 1 deletion app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@
"header": "Local Library",
"title": "Title",
"empty": "The library is empty",
"empty-help": "Try adding some music using the button above."
"empty-help": "Try adding some music using the button above.",
"no-api": "Web Api is not enabled :(",
"no-api-help": "In order to use the local library you need to enable the web api.",
"api-enable": "enable the api."
},
"lyrics": {
"by-artist": "by {{artist}}",
Expand Down
13 changes: 6 additions & 7 deletions app/persistence/store.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import _ from 'lodash';
import electronStore from 'electron-store';
import logger from 'electron-timber';

import options from '../../common/settings';
import { restartApi, stopApi } from '../mpris';

const store = new electronStore();

function setIfUnset (key, value) {
function setIfUnset(key, value) {
if (!store.get(key)) {
store.set(key, value);
}
}

function initStore () {
function initStore() {
setIfUnset('lastFm', {});
setIfUnset('settings', {});
setIfUnset('localMeta', {});

setIfUnset('localFolders', []);
setIfUnset('playLists', []);

setIfUnset( 'favorites', {
setIfUnset('favorites', {
tracks: [],
artists: [],
albums: []
Expand Down Expand Up @@ -68,7 +68,7 @@ function initStore () {
// Should be called in startup process
initStore();

function getOption (key) {
function getOption(key) {
const settings = store.get('settings') || {};
let value = settings[key];

Expand All @@ -83,7 +83,7 @@ function isValidPort(value) {
return typeof value === 'number' && value > 1024 && value < 49151;
}

function setOption (key, value) {
function setOption(key, value) {
const settings = store.get('settings') || {};

store.set('settings', Object.assign({}, settings, { [`${key}`]: value }));
Expand All @@ -98,5 +98,4 @@ function setOption (key, value) {
}
}


export { store, getOption, setOption };
6 changes: 1 addition & 5 deletions app/reducers/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ const initialState = {
sortBy: 'artist',
direction: 'ascending',
filter: '',
tracks: {
byId: {},
byAlbum: {},
byArtist: {}
}
tracks: {}
};

export default function LocalReducer(state = initialState, action) {
Expand Down
39 changes: 35 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Streaming music player that finds music sources automatically.",
"main": "main.js",
"scripts": {
"start": "npm-run-all --parallel watch electron:dev:linux",
"start": "npm-run-all --parallel watch electron:dev",
"electron:dev": "webpack --progress --colors --config=webpack.config.electron.js && electron ./bundle.electron.js",
"electron:prod:linux": "npm run build:electron:linux && electron ./dist/bundle.electron.js",
"electron:prod": "npm run build:electron && electron ./dist/bundle.electron.js",
Expand Down Expand Up @@ -49,6 +49,7 @@
"body-parser": "^1.18.3",
"chart.js": "^2.8.0",
"cheerio": "^1.0.0-rc.2",
"concat-stream": "^2.0.0",
"cors": "^2.8.5",
"d3-drag": "^1.2.3",
"d3-selection": "^1.4.0",
Expand All @@ -57,6 +58,7 @@
"electron-store": "^2.0.0",
"electron-timber": "^0.5.1",
"electron-util": "^0.11.0",
"event-stream": "^4.0.1",
"express": "^4.16.4",
"express-json-validator-middleware": "^1.2.3",
"fast-levenshtein": "^2.0.6",
Expand Down Expand Up @@ -84,7 +86,8 @@
"react-toastify": "^4.5.2",
"semantic-ui-react": "^0.82.1",
"simple-get-lyrics": "0.0.4",
"slug": "^1.1.0",
"stream-filter": "^2.1.0",
"stream-reduce": "^1.0.3",
"styled-components": "^3.2.6",
"swagger-spec-express": "^2.0.15",
"uuid": "^3.3.2",
Expand Down Expand Up @@ -150,7 +153,8 @@
"url-loader": "^1.0.1",
"utf-8-validate": "^5.0.2",
"webpack": "^4.12.1",
"webpack-dev-server": "^3.1.4"
"webpack-dev-server": "^3.1.4",
"webpack-node-externals": "^1.7.2"
},
"optionalDependencies": {
"7zip-bin-mac": "^1.0.1"
Expand Down Expand Up @@ -185,20 +189,47 @@
"tar.gz",
"snap"
],
"category": "Audio;AudioVideo;Network;Player;Music"
"category": "Audio;AudioVideo;Network;Player;Music",
"extraFiles": [
{
"from": "resources/bin/linux",
"to": "Resources/bin",
"filter": [
"**/*"
]
}
]
},
"mac": {
"category": "public.app-category.music",
"target": [
"zip",
"pkg",
"dmg"
],
"extraFiles": [
{
"from": "resources/bin/mac",
"to": "Resources/bin",
"filter": [
"**/*"
]
}
]
},
"win": {
"target": [
"nsis",
"portable"
],
"extraFiles": [
{
"from": "resources/bin/win",
"to": "Resources/bin",
"filter": [
"**/*"
]
}
]
},
"nsis": {
Expand Down
Binary file added resources/bin/linux/fpcalc
Binary file not shown.
Binary file added resources/bin/mac/fpcalc
Binary file not shown.
Binary file added resources/bin/win/fpcalc.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion server/http/api/equalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import swagger from 'swagger-spec-express';
import { store } from '../../store';
import { onUpdateEqualizer, onSetEqualizer } from '../../mpris';
import { updateEqualizerSchema } from '../schema';
import { getStandardDescription } from '../lib/swagger';
import { getStandardDescription } from '../swagger';

const { validate } = new Validator({ allErrors: true });

Expand Down
Loading

0 comments on commit d95b8b0

Please sign in to comment.