Skip to content

Commit

Permalink
Merge branch 'Issue-martpie#401'
Browse files Browse the repository at this point in the history
  • Loading branch information
qcasey committed Jul 16, 2019
2 parents 13c73ea + 4d6fcba commit 595a0c8
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/shared/types/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export enum SortBy {
ALBUM = 'album',
TITLE = 'title',
DURATION = 'duration',
GENRE = 'genre'
GENRE = 'genre',
DATE_ADDED = 'date added',
FILESIZE = 'filesize'
}

export enum SortOrder {
Expand Down Expand Up @@ -87,6 +89,8 @@ export interface Track {
of: number
};
year: number | null;
dateAdded: Date | null;
filesize: number | null; // in MB
}

export interface Playlist {
Expand Down
7 changes: 5 additions & 2 deletions src/ui/components/TrackRow/TrackRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ export default class TrackRow extends React.PureComponent<Props, State> {
<div className={`${styles.cell} ${cellStyles.cellAlbum}`}>
{ track.album }
</div>
<div className={`${styles.cell} ${cellStyles.cellGenre}`}>
{ track.genre.join(', ') }
<div className={`${styles.cell} ${cellStyles.cellDuration}`}>
{ track.filesize ? track.filesize.toString() + ' MB' : '-' }
</div>
<div className={`${styles.cell} ${cellStyles.cellDateAdded}`}>
{ track.dateAdded ? track.dateAdded.toLocaleString() : 'Unknown' }
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/TracksListHeader/TracksListHeader.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}

.cell-track {
flex: 1;
width: calc(26% - 30px);
}

.cell-duration {
Expand Down
12 changes: 9 additions & 3 deletions src/ui/components/TracksListHeader/TracksListHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ class TracksListHeader extends React.Component<Props> {
sortBy={enableSort ? SortBy.ALBUM : null}
icon={TracksListHeader.getIcon(sort, SortBy.ALBUM)}
/>
<TracksListHeaderCell
className={styles.cellDuration}
title='Filesize'
sortBy={enableSort ? SortBy.FILESIZE : null}
icon={TracksListHeader.getIcon(sort, SortBy.FILESIZE)}
/>
<TracksListHeaderCell
className={styles.cellGenre}
title='Genre'
sortBy={enableSort ? SortBy.GENRE : null}
icon={TracksListHeader.getIcon(sort, SortBy.GENRE)}
title='Date Added'
sortBy={enableSort ? SortBy.DATE_ADDED : null}
icon={TracksListHeader.getIcon(sort, SortBy.DATE_ADDED)}
/>
</div>
);
Expand Down
51 changes: 50 additions & 1 deletion src/ui/constants/sort-orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Track, SortOrder, SortBy } from '../../shared/types/interfaces';
// the is far more resource/time impactful
const parseArtist = (t: Track): string => t.loweredMetas.artist.toString();
const parseGenre = (t: Track): string => t.loweredMetas.genre.toString();
const parseDateAdded = (t: Track): string => t.dateAdded ? t.dateAdded.getTime().toString() : '0';

// Declarations
const sortOrders = {
Expand Down Expand Up @@ -113,7 +114,55 @@ const sortOrders = {
],
[SortOrder.DSC]: [
[
parseGenre,
parseDateAdded,
parseArtist,
'year',
'loweredMetas.album',
'disk.no',
'track.no'
],
['desc']
]
},
[SortBy.DATE_ADDED]: {
[SortOrder.ASC]: [
[
parseDateAdded,
parseArtist,
'year',
'loweredMetas.album',
'disk.no',
'track.no'
],
null
],
[SortOrder.DSC]: [
[
parseDateAdded,
parseArtist,
'year',
'loweredMetas.album',
'disk.no',
'track.no'
],
['desc']
]
},
[SortBy.FILESIZE]: {
[SortOrder.ASC]: [
[
'filesize',
parseArtist,
'year',
'loweredMetas.album',
'disk.no',
'track.no'
],
null
],
[SortOrder.DSC]: [
[
'filesize',
parseArtist,
'year',
'loweredMetas.album',
Expand Down
16 changes: 15 additions & 1 deletion src/ui/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ export const stripAccents = (str: string): string => {
return str.replace(reg, replacement).toLowerCase();
};

export const roundNumber = (num: number, scale: number): number => {
let arr = ('' + num).split('e');
let sig = '';
if (+arr[1] + scale > 0) {
sig = '+';
}
return +(Math.round(parseFloat(+arr[0] + 'e' + sig + (+arr[1] + scale))) + 'e-' + scale);
}

/**
* Remove duplicates (realpath) and useless children folders
*/
Expand Down Expand Up @@ -123,7 +132,9 @@ export const getDefaultMetadata = (): Track => ({
no: 0,
of: 0
},
year: null
year: null,
dateAdded: null,
filesize: null
});

export const parseMusicMetadata = (data: mmd.IAudioMetadata, trackPath: string): Partial<Track> => {
Expand Down Expand Up @@ -208,6 +219,9 @@ export const getMetadata = async (trackPath: string): Promise<Track> => {
}
}

metadata.dateAdded = new Date();
metadata.filesize = Math.round(stats.size / 1000000.0);

return metadata;
} catch (err) {
console.warn(`An error occured while reading ${trackPath} id3 tags: ${err}`);
Expand Down

0 comments on commit 595a0c8

Please sign in to comment.