Skip to content

Commit cb2727f

Browse files
committed
✨ feat: 增加音乐文件处理过滤规则
1 parent 9aa4309 commit cb2727f

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

electron/main/services/LocalMusicService.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,7 @@ export class LocalMusicService {
191191
}
192192
this.isRefreshing = true;
193193
// 音乐文件扩展名
194-
const musicExtensions = [
195-
"mp3",
196-
"wav",
197-
"flac",
198-
"aac",
199-
"webm",
200-
"m4a",
201-
"mp4",
202-
"ogg",
203-
"aiff",
204-
"aif",
205-
];
194+
const musicExtensions = ["mp3", "wav", "flac", "aac", "webm", "m4a", "ogg", "aiff", "aif"];
206195
// 构造 Glob 模式数组
207196
const patterns = dirPaths.map((dir) =>
208197
join(dir, `**/*.{${musicExtensions.join(",")}}`).replace(/\\/g, "/"),
@@ -244,6 +233,8 @@ export class LocalMusicService {
244233
const mtime = stats.mtimeMs;
245234
/** 文件大小 */
246235
const size = stats.size;
236+
// 小于 1MB 的文件不处理
237+
if (size < 1024 * 1024) return;
247238
scannedPaths.add(filePath);
248239
/** 缓存 */
249240
const cached = this.db.tracks[filePath];
@@ -275,6 +266,12 @@ export class LocalMusicService {
275266
try {
276267
const id = this.getFileId(filePath);
277268
const metadata = await parseFile(filePath);
269+
// 过滤规则
270+
// 时长 < 30s
271+
if (metadata.format.duration && metadata.format.duration < 30) return;
272+
// 时长 > 2h (7200s)
273+
if (metadata.format.duration && metadata.format.duration > 7200) return;
274+
// 提取封面
278275
const coverPath = await this.extractCover(metadata, id);
279276
// 构建音乐数据
280277
const track: MusicTrack = {

0 commit comments

Comments
 (0)