Skip to content

Commit

Permalink
Merge pull request #585 from nukeop/fix/dropfile
Browse files Browse the repository at this point in the history
Fix/dropfile
  • Loading branch information
nukeop authored Jan 2, 2020
2 parents 082d00a + 6dc8c36 commit 1781f51
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 24 deletions.
6 changes: 3 additions & 3 deletions packages/app/app/actions/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ export const PREVIOUS_SONG = 'PREVIOUS_SONG';
export const SELECT_SONG = 'SELECT_SONG';
export const REPOSITION_SONG = 'REPOSITION_SONG';

function addTrackToQueue (streamProviders, item) {
function addTrackToQueue (streamProviders, item) {
return dispatch => {
item.loading = true;
item.loading = !item.local;
item = safeAddUuid(item);
mpris.addTrack(item);

dispatch({
type: ADD_TO_QUEUE,
payload: item
});
Promise.all(_.map(streamProviders, m => m.search({ artist: item.artist, track: item.name })))
!item.local && Promise.all(_.map(streamProviders, m => m.search({ artist: item.artist, track: item.name })))
.then(results => Promise.all(results))
.then(results => {
_.pull(results, null);
Expand Down
9 changes: 2 additions & 7 deletions packages/app/app/components/PlayQueue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ import QueuePopup from '../QueuePopup';
import QueueMenu from './QueueMenu';

@withTranslation('queue')
class PlayQueue extends React.Component {
constructor(props){
super(props);

}

class PlayQueue extends React.PureComponent {
onDropFile = (event) => {
event.preventDefault();
event.stopPropagation();
Expand Down Expand Up @@ -203,4 +198,4 @@ class PlayQueue extends React.Component {

export default compose(
withState('isFileHovered', 'setFileHovered', false)
)(PlayQueue);
)(PlayQueue);
1 change: 1 addition & 0 deletions packages/app/app/components/PlayQueue/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
.file_icon {
font-size: 5em;
align-self: center;
pointer-events: none;
}

&.compact {
Expand Down
10 changes: 10 additions & 0 deletions packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ export interface NuclearMeta {
artist: string;
}

export interface NuclearStream {
uuid: string;
title?: string;
duration?: number;
source: 'Local' | string;
stream: string;
thumbnail?: string;
}

export interface NuclearBrutMeta {
uuid: string;
duration?: number;
Expand All @@ -33,6 +42,7 @@ export interface NuclearBrutMeta {
loading: boolean;
local?: boolean;
image: Array<{ '#text': string } | undefined>;
streams?: NuclearStream[];
}

export interface NuclearPlaylist {
Expand Down
29 changes: 16 additions & 13 deletions packages/main/src/services/local-library/db.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NuclearBrutMeta } from '@nuclear/common';
import { NuclearBrutMeta, NuclearStream } from '@nuclear/common';
import ElectronStore from 'electron-store';
import { injectable, inject } from 'inversify';
import _ from 'lodash';
Expand Down Expand Up @@ -75,6 +75,20 @@ class LocalLibraryDb extends ElectronStore {
return cache;
}

mapToStream(track: NuclearBrutMeta): NuclearStream {
return {
uuid: track.uuid,
title: track.name,
duration: track.duration,
source: 'Local',
stream: url.format({
pathname: track.path,
protocol: 'file',
slashes: true
})
};
}

private byArtist(): Record<string, NuclearBrutMeta[]> {
const cache = this.getCache();

Expand All @@ -89,18 +103,7 @@ class LocalLibraryDb extends ElectronStore {
.map(artist => byArtist[artist])
.flat()
.filter(song => song.name && song.name.includes(track))
.map(track => ({
uuid: track.uuid,
title: track.name,
duration: track.duration,
source: 'Local',
stream: url.format({
pathname: track.path,
protocol: 'file',
slashes: true
}),
thumbnail: track.image && track.image[0] ? track.image[0]['#text'] : undefined
}))
.map(this.mapToStream)
.pop();

return result;
Expand Down
18 changes: 17 additions & 1 deletion packages/main/src/services/local-library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import asyncPool from 'tiny-async-pool';
import { promisify } from 'util';
import uuid from 'uuid/v4';
import fs from 'fs';
import url from 'url';

import AcousticId from '../acoustic-id';
import Config from '../config';
Expand Down Expand Up @@ -35,8 +36,10 @@ class LocalLibrary {
* Format metadata from files to nuclear format
*/
private formatMeta({ common, format }: IAudioMetadata, path: string): NuclearBrutMeta {
const id = uuid();

return {
uuid: uuid(),
uuid: id,
path,
duration: format.duration,
name: common.title,
Expand All @@ -57,6 +60,19 @@ class LocalLibrary {
};base64,${common.picture[0].data.toString('base64')}`
}
: undefined
],
streams: [
{
uuid: id,
title: common.title,
duration: format.duration,
source: 'Local',
stream: url.format({
pathname: path,
protocol: 'file',
slashes: true
})
}
]
};
}
Expand Down

0 comments on commit 1781f51

Please sign in to comment.