Ignore album art and info files

This commit is contained in:
Erik 2024-04-29 20:53:19 +03:00
parent ba92da313b
commit 76f25ac199
2 changed files with 8 additions and 3 deletions

View File

@ -212,7 +212,7 @@ class MusicLibrary implements Initialisable
{ {
this.#logger.info('Starting library scan'); this.#logger.info('Starting library scan');
const start = Date.now(); 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`); this.#logger.debug(`${filePaths.length} files to go through`);
if (!this.#index.size) 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'); this.#logger.info('No index built, performing first time scan. This may take some time depending on the size of your music library');

View File

@ -16,6 +16,7 @@ import { PlainError } from '../../@types/Shared.js';
import { DiscordBaseStruct } from '../../@types/DiscordClient.js'; import { DiscordBaseStruct } from '../../@types/DiscordClient.js';
export type StringIndexable<T = unknown> = { [key: string]: T }; export type StringIndexable<T = unknown> = { [key: string]: T };
type ReaddirOpts = { ignoreDotfiles?: boolean, ignoreSuffixes?: string[] };
const Constants: { const Constants: {
QuotePairs: StringIndexable<string> QuotePairs: StringIndexable<string>
@ -213,11 +214,13 @@ class Util
* Read directory recursively and return all file paths * Read directory recursively and return all file paths
* @static * @static
* @param {string} directory Full path to target directory * @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 * @return {string[]} Array with the paths to the files within the directory
* @memberof Util * @memberof Util
*/ */
static readdirRecursive (dir: string, ignoreDotfiles = true) static readdirRecursive (dir: string, { ignoreDotfiles = true, ignoreSuffixes = [] }: ReaddirOpts = {})
{ {
const result = []; const result = [];
(function read (directory: string) (function read (directory: string)
@ -227,6 +230,8 @@ class Util
{ {
if (file.startsWith('.') && ignoreDotfiles) if (file.startsWith('.') && ignoreDotfiles)
continue; continue;
if (ignoreSuffixes.some(suf => file.endsWith(suf)))
continue;
const filePath = path.join(directory, file); const filePath = path.join(directory, file);
if (fs.statSync(filePath).isDirectory()) if (fs.statSync(filePath).isDirectory())