From 68a2d17239fa8412702e3acbd44def5a43a3d689 Mon Sep 17 00:00:00 2001 From: desu-bot Date: Fri, 9 May 2025 06:46:50 +0000 Subject: [PATCH] chore: update public repo --- scripts/infra/navidrome/find-broken.ts | 42 +++++++++++++++++++ .../find-duplicates.ts} | 4 +- .../remux-m4a.ts} | 8 ++-- .../stats.ts} | 2 +- utils/navidrome.ts | 1 + 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 scripts/infra/navidrome/find-broken.ts rename scripts/infra/{navidrome-find-duplicates.ts => navidrome/find-duplicates.ts} (95%) rename scripts/infra/{navidrome-remux-m4a.ts => navidrome/remux-m4a.ts} (90%) rename scripts/infra/{navidrome-stats.ts => navidrome/stats.ts} (86%) diff --git a/scripts/infra/navidrome/find-broken.ts b/scripts/infra/navidrome/find-broken.ts new file mode 100644 index 0000000..190b406 --- /dev/null +++ b/scripts/infra/navidrome/find-broken.ts @@ -0,0 +1,42 @@ +import { $, ProcessOutput } from 'zx' +import { fetchSongsIter } from '../../../utils/navidrome.ts' +import { asyncPool } from '@fuman/utils' +import { join } from 'path/posix' + +// async function checkIfBroken(path: string) { +// const r = await $`ffprobe -v error -show_entries stream=codec_type,codec_name,index:stream_tags=title,language -of json ${path}`.json() +// } + +// for await (const song of fetchSongsIter()) { + +// } + +const broken: string[] = [] + +await asyncPool(fetchSongsIter({ + onChunkProcessed: (page, items) => { + console.log(`Processed page ${page} with ${items} items`) + }, +}), async (song) => { + const fullPath = join(song.libraryPath, song.path) + const path = fullPath.replace('/music/s3/', '/mnt/tank/enc/media/music/') + try { + const r = await $`ffmpeg -v error -i ${path} -f null -`.quiet() + if (r.exitCode !== 0 || r.stderr.trim() !== '') throw r + } catch (e) { + if (!(e instanceof ProcessOutput)) throw e + + console.log('%s - %s (%s) seems broken:', song.artist, song.title, path) + console.log(e.stderr) + broken.push(path) + } +}, { limit: 8 }) + + +if (broken.length > 0) { + console.log('Found %d broken files:', broken.length) + for (const path of broken) { + console.log(' %s', path) + } + process.exit(1) +} \ No newline at end of file diff --git a/scripts/infra/navidrome-find-duplicates.ts b/scripts/infra/navidrome/find-duplicates.ts similarity index 95% rename from scripts/infra/navidrome-find-duplicates.ts rename to scripts/infra/navidrome/find-duplicates.ts index c5af85b..7732caa 100644 --- a/scripts/infra/navidrome-find-duplicates.ts +++ b/scripts/infra/navidrome/find-duplicates.ts @@ -1,11 +1,11 @@ -import type { NavidromeSong } from '../../utils/navidrome.ts' +import type { NavidromeSong } from '../../../utils/navidrome.ts' import { createRequire } from 'node:module' import { join } from 'node:path' import kuromoji from 'kuromoji' import { isKana, toRomaji } from 'wanakana' -import { fetchSongs, fetchSongsIter } from '../../utils/navidrome.ts' +import { fetchSongsIter } from '../../../utils/navidrome.ts' const WHITELIST_KEYS = new Set([ // actual different tracks with the same title diff --git a/scripts/infra/navidrome-remux-m4a.ts b/scripts/infra/navidrome/remux-m4a.ts similarity index 90% rename from scripts/infra/navidrome-remux-m4a.ts rename to scripts/infra/navidrome/remux-m4a.ts index 92b1e30..df77031 100644 --- a/scripts/infra/navidrome-remux-m4a.ts +++ b/scripts/infra/navidrome/remux-m4a.ts @@ -1,10 +1,10 @@ import { readFile, rm } from 'node:fs/promises' import { join } from 'node:path' import { $ } from 'zx' -import { downloadStream } from '../../utils/fetch.ts' -import { getEnv } from '../../utils/misc.ts' -import { fetchSongs } from '../../utils/navidrome.ts' -import { WebdavClient } from '../../utils/webdav.ts' +import { downloadStream } from '../../../utils/fetch.ts' +import { getEnv } from '../../../utils/misc.ts' +import { fetchSongs } from '../../../utils/navidrome.ts' +import { WebdavClient } from '../../../utils/webdav.ts' const webdav = new WebdavClient({ baseUrl: getEnv('NAVIDROME_WEBDAV_ENDPOINT'), diff --git a/scripts/infra/navidrome-stats.ts b/scripts/infra/navidrome/stats.ts similarity index 86% rename from scripts/infra/navidrome-stats.ts rename to scripts/infra/navidrome/stats.ts index e4bb3fa..906da06 100644 --- a/scripts/infra/navidrome-stats.ts +++ b/scripts/infra/navidrome/stats.ts @@ -1,4 +1,4 @@ -import { fetchSongs, fetchSongsIter } from '../../utils/navidrome.ts' +import { fetchSongs, fetchSongsIter } from '../../../utils/navidrome.ts' let count = 0 let totalSize = 0 diff --git a/utils/navidrome.ts b/utils/navidrome.ts index 5314252..d99477d 100644 --- a/utils/navidrome.ts +++ b/utils/navidrome.ts @@ -30,6 +30,7 @@ export const NavidromeSong = z.object({ albumArtist: z.string(), artist: z.string(), path: z.string(), + libraryPath: z.string(), duration: z.number(), size: z.number(), })