Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: strip accents from filenames and tags #33

Merged
merged 6 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
Expand All @@ -19,7 +16,14 @@
"id": "command",
"type": "pickString",
"description": "Which command do you want to run?",
"options": ["smart", "relocate", "import-ext", "help"],
"options": [
//
"import-ext",
"relocate",
"smart",
"strip-accents",
"help"
],
"default": "smart"
}
]
Expand Down
Binary file added img/enjinn-square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"node-fetch": "2.6.1",
"node-rsa": "1.1.1",
"ora": "5.4.0",
"pluralize": "8.0.0",
"prompts": "2.4.1",
"sqlite3": "5.0.2",
"terminal-link": "2.1.1",
Expand All @@ -113,6 +114,7 @@
"@types/node": "14.14.41",
"@types/node-fetch": "2.5.10",
"@types/node-rsa": "1.1.0",
"@types/pluralize": "0.0.29",
"@types/prompts": "2.0.11",
"aws-sdk": "2.903.0",
"execa": "0.10.0",
Expand Down
43 changes: 35 additions & 8 deletions src/base-commands/base-engine-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,40 @@ export abstract class BaseEngineCommand extends Command {
protected libraryFolder!: string;
protected engineDb!: engine.EngineDB;

log(message = '', { indent = 0 }: { indent?: number } = {}) {
const indentStr = ' '.repeat(indent);
super.log(indentStr + message);
}

logBlock(message: string, opts?: { indent?: number }) {
super.log();
this.log(message, opts);
super.log();
}

warn(message: string, opts?: { indent?: number }) {
this.log(chalk`{yellow Warning} ${message}`, opts);
}

warnBlock(message: string, { indent = 0 }: { indent?: number } = {}) {
super.log();
this.warn('', { indent });
this.log(message, { indent: indent + 2 });
super.log();
}

protected async init() {
this.libraryFolder = appConf().get(AppConfKey.EngineLibraryFolder);
}

protected async finally() {
await this.engineDb?.disconnect();
if (this.engineDb) {
await spinner({
text: 'Disconnect from Engine DB',
successMessage: 'Disconnected from Engine DB',
run: async () => this.engineDb.disconnect(),
});
}
}

protected async connectToEngine() {
Expand All @@ -35,25 +63,24 @@ export abstract class BaseEngineCommand extends Command {
color?: string;
} = {},
) {
const indentStr = ' '.repeat(indent);
tracks.forEach(t =>
this.log(`${indentStr}${(chalk as any)[color](t.path)}`),
);
tracks.forEach(t => {
this.log((chalk as any)[color](t.path), { indent });
});
}

protected logPlaylistsWithTrackCount(
playlists: engine.PlaylistInput[],
{ indent = 4 }: { indent?: number } = {},
) {
const indentStr = ' '.repeat(indent);
playlists.forEach(({ title, tracks }) => {
const numTracks = tracks.length;
if (numTracks) {
this.log(
chalk`${indentStr}{blue ${title}} [{green ${numTracks.toString()}} tracks]`,
chalk`{blue ${title}} [{green ${numTracks.toString()}} tracks]`,
{ indent },
);
} else {
this.log(chalk`${indentStr}{blue ${title}} [{yellow 0} tracks]`);
this.log(chalk`{blue ${title}} [{yellow 0} tracks]`, { indent });
}
});
}
Expand Down
24 changes: 16 additions & 8 deletions src/commands/import-ext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from 'chalk';
import * as path from 'path';
import pluralize from 'pluralize';
import prompts from 'prompts';

import { BaseEngineCommand } from '../base-commands';
Expand All @@ -22,7 +23,7 @@ export default class ImportExt extends BaseEngineCommand {
await this.connectToEngine();

if (this.engineDb.version === engine.Version.V2_0) {
this.error(`import-ext doesn't support Engine 2.0`);
this.error(`${ImportExt.name} doesn't support Engine 2.0`);
}

const extLibraries = await spinner({
Expand All @@ -32,9 +33,10 @@ export default class ImportExt extends BaseEngineCommand {
const length = libraries.length;
if (length) {
ctx.succeed(
chalk`Found {blue ${length.toString()}} external ${
length > 1 ? 'libraries' : 'library'
}`,
chalk`Found {blue ${length.toString()}} external ${pluralize(
'library',
length,
)}`,
);
} else {
ctx.warn(`Didn't find any external Engine libraries`);
Expand Down Expand Up @@ -67,7 +69,10 @@ export default class ImportExt extends BaseEngineCommand {
const length = extPlaylists.length;
if (length) {
ctx.succeed(
chalk`Found {blue ${length.toString()}} external playlists`,
chalk`Found {blue ${length.toString()}} external ${pluralize(
'playlist',
length,
)}`,
);
} else {
ctx.warn(`Didn't find any external playlists`);
Expand All @@ -86,7 +91,10 @@ export default class ImportExt extends BaseEngineCommand {
const imported = await this.importPlaylists(selectedPlaylists);

ctx.succeed(
chalk`Imported {blue ${imported.length.toString()}} external playlists`,
chalk`Imported {blue ${imported.length.toString()}} external ${pluralize(
'playlist',
imported.length,
)}`,
);
this.logPlaylistsWithTrackCount(imported);

Expand Down Expand Up @@ -116,8 +124,8 @@ export default class ImportExt extends BaseEngineCommand {

private checkLicense(): boolean {
if (!isLicensed()) {
this.log(
chalk`{yellow Warning} The import-ext command isn't included in the free version.`,
this.warnBlock(
chalk`The {cyan ${ImportExt.name}} command isn't included in the free version.`,
);
return false;
}
Expand Down
37 changes: 27 additions & 10 deletions src/commands/relocate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chalk from 'chalk';
import { keyBy, partition } from 'lodash';
import path from 'path';
import pluralize from 'pluralize';
import prompts from 'prompts';
import { trueCasePath } from 'true-case-path';

Expand All @@ -25,9 +26,13 @@ export default class Relocate extends BaseEngineCommand {
text: 'Find missing tracks',
run: async ctx => {
const missing = await this.findMissingTracks();
if (missing.length) {
const length = missing.length;
if (length) {
ctx.succeed(
chalk`Found {red ${missing.length.toString()}} missing tracks`,
chalk`Found {red ${length.toString()}} missing ${pluralize(
'track',
length,
)}`,
);
this.logTracks(missing);
} else {
Expand All @@ -36,12 +41,12 @@ export default class Relocate extends BaseEngineCommand {
return missing;
},
});
this.log();

if (!missingTracks.length) {
return;
}

this.log();
const searchFolder = await this.promptForSearchFolder();
this.log();

Expand All @@ -53,17 +58,23 @@ export default class Relocate extends BaseEngineCommand {
searchFolder,
});

const numRelocated = relocated.length.toString();
const numMissing = stillMissing.length.toString();
const relocatedLength = relocated.length;
const missingLength = stillMissing.length;
const relocatedTrackWord = pluralize('track', relocatedLength);
const missingTrackWord = pluralize('track', missingLength);

if (!relocated.length) {
ctx.fail(chalk`Couldn't find {red ${numMissing}} tracks`);
} else if (stillMissing.length) {
ctx.fail(
chalk`Couldn't find {red ${missingLength.toString()}} ${missingTrackWord}`,
);
} else if (missingLength) {
ctx.warn(
chalk`Relocated {green ${numRelocated}} tracks, couldn't find {red ${numMissing}} tracks`,
chalk`Relocated {green ${relocatedLength.toString()}} ${relocatedTrackWord}, couldn't find {red ${missingLength.toString()}} ${missingTrackWord}`,
);
} else {
ctx.succeed(chalk`Relocated {green ${numRelocated}} tracks`);
ctx.succeed(
chalk`Relocated {green ${relocatedLength.toString()}} ${relocatedTrackWord}`,
);
}
this.logTracks(relocated);
if (stillMissing.length) {
Expand All @@ -85,7 +96,13 @@ export default class Relocate extends BaseEngineCommand {
await spinner({
text: 'Save relocated tracks to Engine',
successMessage: 'Saved relocated tracks to Engine',
run: async () => this.engineDb.updateTrackPaths(relocated),
run: async () =>
this.engineDb.updateTracks(
relocated.map(track => ({
id: track.id,
path: track.path,
})),
),
});
}

Expand Down
17 changes: 10 additions & 7 deletions src/commands/smart.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from 'chalk';
import { every, some } from 'lodash';
import pluralize from 'pluralize';

import { BaseEngineCommand } from '../base-commands';
import * as engine from '../engine';
Expand Down Expand Up @@ -41,15 +42,17 @@ export default class Smart extends BaseEngineCommand {
tracks: filterTracks({ tracks, playlistConfig }),
}),
);
const length = inputs.length;

const numEmpty = inputs.filter(x => !x.tracks.length).length;
const playlistWord = pluralize('playlist', length);
if (numEmpty) {
ctx.warn(
chalk`Built {blue ${inputs.length.toString()}} smart playlists, but {yellow ${numEmpty.toString()}} didn't match any tracks`,
chalk`Built {blue ${length.toString()}} smart ${playlistWord}, but {yellow ${numEmpty.toString()}} didn't match any tracks`,
);
} else {
ctx.succeed(
chalk`Built {blue ${inputs.length.toString()}} smart playlists`,
chalk`Built {blue ${length.toString()}} smart ${playlistWord}`,
);
}
this.logPlaylistsWithTrackCount(inputs);
Expand Down Expand Up @@ -81,19 +84,19 @@ export default class Smart extends BaseEngineCommand {

const numPlaylists = this.smartPlaylists.length;
if (numPlaylists > MAX_FREE_PLAYLISTS) {
this.log(
chalk`{yellow Warning} The free version only supports up to {green ${MAX_FREE_PLAYLISTS.toString()}}, but you have {yellow ${numPlaylists.toString()}}.`,
this.warnBlock(
chalk`The free version only supports up to {green ${MAX_FREE_PLAYLISTS.toString()}} smart playlists, but you have {yellow ${numPlaylists.toString()}}.`,
);
return false;
}
const withNestedRules = this.smartPlaylists.filter(p =>
normalizeRuleGroup(p.rules).nodes.some(isNodeGroup),
);
if (withNestedRules.length) {
this.log(
chalk`{yellow Warning} The free version doesn't support nested rules. The following playlists contain nested rules:`,
this.warnBlock(
`The free version doesn't support nested rules. The following playlists contain nested rules:`,
);
withNestedRules.forEach(p => this.log(` ${p.name}`));
withNestedRules.forEach(p => this.log(p.name, { indent: 4 }));
return false;
}

Expand Down
Loading