From 76f25ac19930d0589bc7171c22c7bee0245f2f7d Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 29 Apr 2024 20:53:19 +0300 Subject: [PATCH] Ignore album art and info files --- src/client/components/MusicLibrary.ts | 2 +- src/utilities/Util.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/components/MusicLibrary.ts b/src/client/components/MusicLibrary.ts index aacace7..09bf968 100644 --- a/src/client/components/MusicLibrary.ts +++ b/src/client/components/MusicLibrary.ts @@ -212,7 +212,7 @@ class MusicLibrary implements Initialisable { this.#logger.info('Starting library scan'); const start = Date.now(); - const filePaths = Util.readdirRecursive(this.#path); + const filePaths = Util.readdirRecursive(this.#path, { ignoreSuffixes: [ '.nfo', '.jpg', '.jpeg', '.png' ] }); this.#logger.debug(`${filePaths.length} files to go through`); if (!this.#index.size) this.#logger.info('No index built, performing first time scan. This may take some time depending on the size of your music library'); diff --git a/src/utilities/Util.ts b/src/utilities/Util.ts index 703a740..822e8a9 100644 --- a/src/utilities/Util.ts +++ b/src/utilities/Util.ts @@ -16,6 +16,7 @@ import { PlainError } from '../../@types/Shared.js'; import { DiscordBaseStruct } from '../../@types/DiscordClient.js'; export type StringIndexable = { [key: string]: T }; +type ReaddirOpts = { ignoreDotfiles?: boolean, ignoreSuffixes?: string[] }; const Constants: { QuotePairs: StringIndexable @@ -213,11 +214,13 @@ class Util * Read directory recursively and return all file paths * @static * @param {string} directory Full path to target directory - * @param {boolean} [ignoreDotfiles=true] + * @param {{ ignoreDotfiles?: boolean; }} opts + * @param {boolean} [opts.ignoreDotfiles=true] + * @param {string[]} [opts.ignoreSuffixes=[]] * @return {string[]} Array with the paths to the files within the directory * @memberof Util */ - static readdirRecursive (dir: string, ignoreDotfiles = true) + static readdirRecursive (dir: string, { ignoreDotfiles = true, ignoreSuffixes = [] }: ReaddirOpts = {}) { const result = []; (function read (directory: string) @@ -227,6 +230,8 @@ class Util { if (file.startsWith('.') && ignoreDotfiles) continue; + if (ignoreSuffixes.some(suf => file.endsWith(suf))) + continue; const filePath = path.join(directory, file); if (fs.statSync(filePath).isDirectory())