Skip to content

Commit

Permalink
Updated to 3.0.0-stable.20231027
Browse files Browse the repository at this point in the history
- Added a schema to validate release-notes.json
- Added support for saving LRC files in a seperate folder other than the folder that the relevant song is located.
- Added support for renaming a playlist.
- Added a log entry to save the time taken to complete processes such as full library parsing, palette generation etc.
- Fixed a bug where default artist artworks are not displayed.
- Added support for sending album artist with the scrobble song payload.
- Added support for reading album artists in songs.
- Fixed a bug where albums are created using data from artist tag in a song instead of the albumArtist tag.
- Sortings songs with `track number` now also considers their disk numbers.
- Added a fade-in animation when images are displayed.
- Improved animations in lyrics lines.
- Added up next song popup for the mini-player.
- Fixed a bug where sorting option is not saved in FoldersPage and PlaylistInfoPage.
- Added a button to clear app local storage data.
  • Loading branch information
Sandakan committed Oct 27, 2023
1 parent 05a84c9 commit 2f18288
Show file tree
Hide file tree
Showing 45 changed files with 925 additions and 381 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@
"iconClassName",
"titleClassName"
],
"json.schemas": [
{
"fileMatch": ["../release-notes.json"],
"url": "../release-notes-schema.json"
}
],
"editor.tokenColorCustomizations": {
"comments": "",
"comments": "#00b894",
"textMateRules": []
}
}
89 changes: 89 additions & 0 deletions release-notes-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$ref": "#/definitions/Changelog",
"definitions": {
"Changelog": {
"type": "object",
"additionalProperties": false,
"properties": {
"latestVersion": {
"$ref": "#/definitions/Version"
},
"versions": {
"type": "array",
"items": {
"$ref": "#/definitions/Version"
}
}
},
"required": ["latestVersion", "versions"],
"title": "Changelog"
},
"Notes": {
"type": "object",
"additionalProperties": false,
"properties": {
"fixed": {
"type": "array",
"items": {
"$ref": "#/definitions/Fixed"
}
},
"knownIssues": {
"type": "array",
"items": {
"$ref": "#/definitions/Fixed"
}
},
"new": {
"type": "array",
"items": {
"$ref": "#/definitions/Fixed"
}
}
},
"required": ["fixed", "knownIssues", "new"],
"title": "Notes"
},
"Fixed": {
"type": "object",
"additionalProperties": false,
"properties": {
"note": {
"type": "string"
}
},
"required": ["note"],
"title": "Fixed"
},
"Version": {
"type": "object",
"additionalProperties": false,
"properties": {
"artwork": {
"type": "string"
},
"importantNotes": {
"type": "array",
"items": {
"type": "string"
}
},
"phase": {
"type": "string"
},
"releaseDate": {
"type": "string"
},
"version": {
"type": "string"
},
"notes": {
"$ref": "#/definitions/Notes"
}
},
"required": ["releaseDate", "version"],
"title": "Version"
}
}
}
4 changes: 3 additions & 1 deletion release-notes.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
],
"notes": {
"fixed": [
"Fixed a bug where environment variables are not initialized when migrating the database to a newer version."
{
"note": "Fixed a bug where environment variables are not initialized when migrating the database to a newer version."
}
],
"knownIssues": [
{
Expand Down
21 changes: 13 additions & 8 deletions src/@types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ declare global {
artists?: { artistId: string; name: string }[];
album?: { albumId: string; name: string };
genres?: { genreId: string; name: string }[];
albumArtist?: { artistId: string; name: string };
albumArtists?: { artistId: string; name: string }[];
bitrate?: number;
trackNo?: number;
diskNo?: number;
noOfChannels?: number;
year?: number;
sampleRate?: number;
Expand Down Expand Up @@ -371,7 +372,9 @@ declare global {
| 'preferences.sendSongScrobblingDataToLastFM'
| 'preferences.sendSongFavoritesDataToLastFM'
| 'preferences.sendNowPlayingSongDataToLastFM'
| 'preferences.saveLyricsInLrcFilesForSupportedSongs'
| 'customMusixmatchUserToken'
| 'customLrcFilesSaveLocation'
| 'lastFmSessionData'
| 'storageMetrics'
| PageSortTypes;
Expand Down Expand Up @@ -402,6 +405,7 @@ declare global {
sendSongScrobblingDataToLastFM: boolean;
sendSongFavoritesDataToLastFM: boolean;
sendNowPlayingSongDataToLastFM: boolean;
saveLyricsInLrcFilesForSupportedSongs: boolean;
};
windowPositions: {
mainWindow?: WindowCordinates;
Expand All @@ -416,6 +420,7 @@ declare global {
customMusixmatchUserToken?: string;
lastFmSessionData?: LastFMSessionData;
storageMetrics?: StorageMetrics;
customLrcFilesSaveLocation?: string;
}

interface AppThemeData {
Expand Down Expand Up @@ -570,7 +575,7 @@ declare global {
playlistsPage?: PlaylistSortTypes;
albumsPage?: AlbumSortTypes;
genresPage?: GenreSortTypes;
musicFoldersPage?: SongSortTypes;
musicFoldersPage?: FolderSortTypes;
}

interface LyricsEditorSettings {
Expand Down Expand Up @@ -1120,16 +1125,16 @@ declare global {
releaseDate: string;
importantNotes?: string[];
artwork?: string;
notes: Notes;
notes: ChangelogNoteTypes;
}

export interface Notes {
new: Fixed[];
fixed: Fixed[];
knownIssues: Fixed[];
export interface ChangelogNoteTypes {
new: ChangelogNote[];
fixed: ChangelogNote[];
knownIssues: ChangelogNote[];
}

export interface Fixed {
export interface ChangelogNote {
note: string;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/core/addMusicFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { tryToParseSong } from '../parseSong/parseSong';
import sortSongs from '../utils/sortSongs';
import { dataUpdateEvent, sendMessageToRenderer } from '../main';
import { generatePalettes } from '../other/generatePalette';
import { timeEnd, timeStart } from '../utils/measureTimeUsage';

const removeAlreadyAvailableStructures = (structures: FolderStructure[]) => {
const parents: FolderStructure[] = [];
Expand Down Expand Up @@ -49,6 +50,7 @@ const addMusicFromFolderStructures = async (
let songs: SongData[] = [];

if (songPaths) {
const startTime = timeStart();
for (let i = 0; i < songPaths.length; i += 1) {
if (abortSignal?.aborted) {
log(
Expand Down Expand Up @@ -77,6 +79,7 @@ const addMusicFromFolderStructures = async (
);
}
}
timeEnd(startTime, 'Time to parse the whole folder');
setTimeout(generatePalettes, 1500);
} else throw new Error('Failed to get song paths from music folders.');

Expand All @@ -86,7 +89,6 @@ const addMusicFromFolderStructures = async (
`Successfully parsed ${songs.length} songs from the selected music folders.`,
{
folderPaths: eligableStructures.map((x) => x.path),
timeElapsed: console.timeEnd('parseTime'),
},
);
dataUpdateEvent('userData/musicFolder');
Expand Down
2 changes: 1 addition & 1 deletion src/main/core/getArtistInfoFromNet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const getArtistArtworksFromNet = async (artist: SavableArtist) => {
};

const getArtistDataFromSavableArtistData = (artist: SavableArtist): Artist => {
const artworkPaths = getArtistArtworkPath(artist.name);
const artworkPaths = getArtistArtworkPath(artist.artworkName);
return { ...artist, artworkPaths };
};

Expand Down
27 changes: 22 additions & 5 deletions src/main/core/getSongLyrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,34 @@ const fetchLyricsFromAudioSource = (songPath: string) => {
};

const fetchLyricsFromLRCFile = async (songPath: string) => {
const lrcFilePath = `${songPath}.lrc`;
const userData = getUserData();
const defaultLrcFilePath = `${songPath}.lrc`;
const customLrcFilePath = userData.customLrcFilesSaveLocation
? path.join(
userData.customLrcFilesSaveLocation,
`${path.basename(songPath)}.lrc`,
)
: undefined;

try {
const lyricsInLrcFormat = await fs.readFile(lrcFilePath, {
encoding: 'utf-8',
});
const lyricsInLrcFormat = await fs
.readFile(defaultLrcFilePath, {
encoding: 'utf-8',
})
.catch((err) => {
if (userData.customLrcFilesSaveLocation) {
return fs.readFile(defaultLrcFilePath, {
encoding: 'utf-8',
});
}
throw err;
});
const parsedLyrics = parseLyrics(lyricsInLrcFormat);
return parsedLyrics;
} catch (error) {
return log(
`Lyrics containing LRC file for ${path.basename(songPath)} didn't exist.`,
{ error },
{ defaultLrcFilePath, customLrcFilePath },
);
}
};
Expand Down
25 changes: 25 additions & 0 deletions src/main/core/renameAPlaylist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable no-await-in-loop */
import log from '../log';
import { getPlaylistData, setPlaylistData } from '../filesystem';

export default async (playlistId: string, newName: string) => {
const playlists = getPlaylistData();

for (let i = 0; i < playlists.length; i += 1) {
if (playlistId === playlists[i].playlistId) {
playlists[i].name = newName;
setPlaylistData(playlists);
return log(
'Playlist renamed successfully.',
{ playlistId, newName },
'INFO',
{
sendToRenderer: 'SUCCESS',
},
);
}
}
return log('Playlist not found.', { playlistId, newName }, 'WARN', {
sendToRenderer: 'FAILURE',
});
};
58 changes: 58 additions & 0 deletions src/main/core/saveLyricsToLrcFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import path from 'path';
import fs from 'fs/promises';

import log from '../log';
import { getUserData } from '../filesystem';

const convertLyricsToLrcFormat = (songLyrics: SongLyrics) => {
// const { title, lyrics } = songLyrics;
// const output: string[] = [];

// output.push(`[ti:${title}]`);
// output.push(`[length:${min}:${sec}]`);

// if (artists && artists?.length > 0)
// metadataLines.push(`[ar:${artists.map((x) => x.name).join(', ')}]`);
// if (album) metadataLines.push(`[al:${album.name}]`);
// metadataLines.push('');

// const unparsedLines = lyrics.unparsedLyrics.split('\n');
// output.push(...unparsedLines);

return songLyrics.lyrics.unparsedLyrics;
};

const getLrcFileSaveDirectory = (
songPathWithoutProtocol: string,
lrcFileName: string,
) => {
const userData = getUserData();
let saveDirectory: string;

if (userData.customLrcFilesSaveLocation)
saveDirectory = userData.customLrcFilesSaveLocation;
else {
const songContainingFolderPath = path.dirname(songPathWithoutProtocol);
saveDirectory = songContainingFolderPath;
}

return path.join(saveDirectory, `${lrcFileName}.lrc`);
};

const saveLyricsToLRCFile = async (
songPathWithoutProtocol: string,
songLyrics: SongLyrics,
) => {
const songFileName = path.basename(songPathWithoutProtocol);
const lrcFilePath = getLrcFileSaveDirectory(
songPathWithoutProtocol,
songFileName,
);

const lrcFormattedLyrics = convertLyricsToLrcFormat(songLyrics);

await fs.writeFile(lrcFilePath, lrcFormattedLyrics);
log(`Lyrics saved in ${lrcFilePath}.`, { title: songLyrics.title });
};

export default saveLyricsToLRCFile;
11 changes: 11 additions & 0 deletions src/main/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const USER_DATA_TEMPLATE: UserData = {
sendSongScrobblingDataToLastFM: false,
sendSongFavoritesDataToLastFM: false,
sendNowPlayingSongDataToLastFM: false,
saveLyricsInLrcFilesForSupportedSongs: false,
},
windowPositions: {},
windowDiamensions: {},
Expand Down Expand Up @@ -305,6 +306,11 @@ export function setUserData(dataType: UserDataTypes, data: unknown) {
typeof data === 'boolean'
) {
userData.preferences.hideWindowOnClose = data;
} else if (
dataType === 'preferences.saveLyricsInLrcFilesForSupportedSongs' &&
typeof data === 'boolean'
) {
userData.preferences.saveLyricsInLrcFilesForSupportedSongs = data;
} else if (
dataType === 'preferences.openWindowAsHiddenOnSystemStart' &&
typeof data === 'boolean'
Expand All @@ -331,6 +337,11 @@ export function setUserData(dataType: UserDataTypes, data: unknown) {
) {
const encryptedToken = encrypt(data);
userData.customMusixmatchUserToken = encryptedToken;
} else if (
dataType === 'customLrcFilesSaveLocation' &&
typeof data === 'string'
) {
userData.customLrcFilesSaveLocation = data;
} else if (dataType === 'lastFmSessionData' && typeof data === 'object') {
userData.lastFmSessionData = data as LastFMSessionData;
} else if (dataType === 'storageMetrics' && typeof data === 'object') {
Expand Down
Loading

0 comments on commit 2f18288

Please sign in to comment.